check-style-langs.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const path = require('path');
  4. function walk(dir, out = []) {
  5. for (const name of fs.readdirSync(dir)) {
  6. if (['node_modules', 'dist', 'unpackage', '.git', 'docs'].includes(name)) continue;
  7. const p = path.join(dir, name);
  8. const st = fs.statSync(p);
  9. if (st.isDirectory()) walk(p, out);
  10. else if (name.endsWith('.vue')) out.push(p);
  11. }
  12. return out;
  13. }
  14. const files = walk('.');
  15. let scss = 0, cssAttr = 0, noLang = 0;
  16. const noLangSamples = [];
  17. for (const f of files) {
  18. const src = fs.readFileSync(f, 'utf8');
  19. const re = /<style([^>]*)>/gi;
  20. let m;
  21. while ((m = re.exec(src))) {
  22. const attrs = m[1];
  23. if (/lang=["']scss["']/i.test(attrs)) scss++;
  24. else if (/lang=["']/i.test(attrs)) cssAttr++;
  25. else {
  26. noLang++;
  27. if (noLangSamples.length < 20) noLangSamples.push(path.relative('.', f));
  28. }
  29. }
  30. }
  31. console.log('scss blocks:', scss, '| lang=css blocks:', cssAttr, '| no-lang blocks:', noLang);
  32. if (noLangSamples.length) {
  33. console.log('--- no-lang sample ---');
  34. console.log(noLangSamples.join('\n'));
  35. }