d26-child-index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env node
  2. /**
  3. * D26: child-index.vue 孩子首页清理 (debt 54 -> 0)
  4. * 全局令牌 3 色 + Tailwind pastel 描边族 5 色;页面专属 5 色收编局部 $c-ci-*
  5. */
  6. const fs = require('fs');
  7. const F = 'pages/home-pages/child-index.vue';
  8. let src = fs.readFileSync(F, 'utf8');
  9. let replaced = 0;
  10. const styleIdx = src.indexOf('<style');
  11. const before = src.slice(0, styleIdx);
  12. let styleBody = src.slice(styleIdx);
  13. const GLOBAL = [
  14. ['#2563EB', '$status-info-deep'],
  15. ['#EDF2F7', '$uni-bg-color-grey'],
  16. ['#FDE68A', '$status-warning-light'],
  17. ['#BAE6FD', '$tint-sky-line'],
  18. ['#BBF7D0', '$tint-green-line'],
  19. ['#BFDBFE', '$tint-blue-line'],
  20. ['#FBCFE8', '$tint-pink-line'],
  21. ['#C7D2FE', '$tint-indigo-line'],
  22. ];
  23. for (const [from, to] of GLOBAL) {
  24. const re = new RegExp(from + '(?![0-9a-fA-F])', 'gi');
  25. replaced += (styleBody.match(re) || []).length;
  26. styleBody = styleBody.replace(re, to);
  27. }
  28. const LOCAL = [
  29. ['#E0ECF8', '$c-ci-sky'],
  30. ['#1E4A7A', '$c-ci-navy'],
  31. ['#FFB800', '$c-ci-gold'],
  32. ['#DCE8F5', '$c-ci-blue-1'],
  33. ['#C8DDF0', '$c-ci-blue-2'],
  34. ];
  35. for (const [from, to] of LOCAL) {
  36. const re = new RegExp(from + '(?![0-9a-fA-F])', 'gi');
  37. replaced += (styleBody.match(re) || []).length;
  38. styleBody = styleBody.replace(re, to);
  39. }
  40. const palette = [
  41. '// ===== 孩子首页专属色阶(天空蓝渐变族 + 徽章金;单页专用,约定见 uni.scss §14)=====',
  42. '$c-ci-sky: #E0ECF8; // 顶部渐变终(浅天蓝)',
  43. '$c-ci-navy: #1E4A7A; // 深海军蓝文字',
  44. '$c-ci-gold: #FFB800; // 徽章金渐变终',
  45. '$c-ci-blue-1: #DCE8F5; // 空态卡渐变起',
  46. '$c-ci-blue-2: #C8DDF0; // 空态卡渐变终',
  47. ''
  48. ].join('\n');
  49. styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
  50. fs.writeFileSync(F, before + styleBody);
  51. console.log('total replaced:', replaced);
  52. const out = fs.readFileSync(F, 'utf8');
  53. const lines = out.split('\n');
  54. let n = 0;
  55. for (let i = 0; i < lines.length; i++) {
  56. const L = lines[i].trim();
  57. if (/#[0-9a-fA-F]{3,8}\b/.test(L) && L.charAt(0) !== '$') { console.log('HEX ' + (i + 1) + ': ' + L.slice(0, 110)); n++; }
  58. }
  59. console.log('remaining non-palette hex:', n);