fix-merged-style-tag.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env node
  2. /**
  3. * 紧急修复:A 批 replace-hex-to-token.js 的 attrs.trim() 吞掉 <style 与 scoped 之间空格
  4. * <stylescoped lang="scss"> 不是合法标签名,全量恢复为 <style scoped lang="scss">
  5. * 用法: node scripts/fix-merged-style-tag.js
  6. */
  7. const fs = require('fs');
  8. const path = require('path');
  9. const ROOT = path.resolve(__dirname, '..');
  10. const EXCLUDE = new Set(['node_modules', 'dist', 'unpackage', '.git', 'docs']);
  11. function walk(dir, out = []) {
  12. for (const n of fs.readdirSync(dir)) {
  13. if (EXCLUDE.has(n)) continue;
  14. const p = path.join(dir, n);
  15. const s = fs.statSync(p);
  16. if (s.isDirectory()) walk(p, out);
  17. else if (n.endsWith('.vue')) out.push(p);
  18. }
  19. return out;
  20. }
  21. const FIXES = [
  22. [/<stylescoped\s/g, '<style scoped '], // 无 scoped 前空格:<style scoped ...
  23. [/<stylescoped>/g, '<style scoped>'], // 兜底:<stylescoped> -> <style scoped>
  24. [/<stylelang=/g, '<style lang='], // 兜底:任何 <stylelang= 拼写
  25. ];
  26. let fixed = 0;
  27. for (const f of walk(ROOT)) {
  28. const src = fs.readFileSync(f, 'utf8');
  29. let ns = src;
  30. for (const [re, rep] of FIXES) ns = ns.replace(re, rep);
  31. if (ns !== src) {
  32. fs.writeFileSync(f, ns);
  33. console.log('FIX:', path.relative(ROOT, f));
  34. fixed++;
  35. }
  36. }
  37. console.log('fixed files:', fixed);