| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/usr/bin/env node
- /**
- * 紧急修复:A 批 replace-hex-to-token.js 的 attrs.trim() 吞掉 <style 与 scoped 之间空格
- * <stylescoped lang="scss"> 不是合法标签名,全量恢复为 <style scoped lang="scss">
- * 用法: node scripts/fix-merged-style-tag.js
- */
- const fs = require('fs');
- const path = require('path');
- const ROOT = path.resolve(__dirname, '..');
- const EXCLUDE = new Set(['node_modules', 'dist', 'unpackage', '.git', 'docs']);
- function walk(dir, out = []) {
- for (const n of fs.readdirSync(dir)) {
- if (EXCLUDE.has(n)) continue;
- const p = path.join(dir, n);
- const s = fs.statSync(p);
- if (s.isDirectory()) walk(p, out);
- else if (n.endsWith('.vue')) out.push(p);
- }
- return out;
- }
- const FIXES = [
- [/<stylescoped\s/g, '<style scoped '], // 无 scoped 前空格:<style scoped ...
- [/<stylescoped>/g, '<style scoped>'], // 兜底:<stylescoped> -> <style scoped>
- [/<stylelang=/g, '<style lang='], // 兜底:任何 <stylelang= 拼写
- ];
- let fixed = 0;
- for (const f of walk(ROOT)) {
- const src = fs.readFileSync(f, 'utf8');
- let ns = src;
- for (const [re, rep] of FIXES) ns = ns.replace(re, rep);
- if (ns !== src) {
- fs.writeFileSync(f, ns);
- console.log('FIX:', path.relative(ROOT, f));
- fixed++;
- }
- }
- console.log('fixed files:', fixed);
|