| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- #!/usr/bin/env node
- /**
- * D31 修正:撤销模板区(<script> 之前)被误替换的 BrandColors.* —— 模板无法访问模块级变量,
- * 统一还原为原 hex 字面量;script/style 区的收编保留。
- */
- const fs = require('fs');
- const { execSync } = require('child_process');
- const files = execSync('git -C .. diff --name-only -- cfc-frontend', { encoding: 'utf8' })
- .split('\n').map(s => s.trim()).filter(s => s.endsWith('.vue')).map(s => s.replace('cfc-frontend/', ''));
- const KEY_TO_HEX = {
- success: '#10B981', wealth: '#F59E0B', mind: '#FF6B9D', body: '#FF8C42',
- primary: '#F97316', wisdom: '#6366F1', white: '#FFFFFF', infoBlue: '#3B82F6',
- danger: '#EF4444', appTextSubtle: '#94A3B8', violet: '#8B5CF6', orangeDeep: '#EA580C',
- infoSky: '#0EA5E9', pink: '#EC4899', textSlate: '#6B7280', matGreen: '#4CAF50',
- mindAccent: '#FF6B35', brownWarm: '#8D6E63',
- };
- let touched = 0;
- let reverted = 0;
- for (const f of files) {
- const s = fs.readFileSync(f, 'utf8');
- const scriptIdx = s.search(/<script/);
- if (scriptIdx === -1) continue;
- let tpl = s.slice(0, scriptIdx);
- const rest = s.slice(scriptIdx);
- if (!/BrandColors\.\w+/.test(tpl)) continue;
- tpl = tpl.replace(/BrandColors\.(\w+)/g, (m, key) => {
- if (!KEY_TO_HEX[key]) {
- console.warn('UNKNOWN KEY ' + key + ' in ' + f);
- return m;
- }
- reverted++;
- return KEY_TO_HEX[key];
- });
- fs.writeFileSync(f, tpl + rest, 'utf8');
- touched++;
- }
- console.log('修正文件:', touched, '还原引用:', reverted);
|