#!/usr/bin/env node /** * D37: 模板区组件属性色值(switch color / slider activeColor / 图表 fillColor 等) * 绑定到 BrandColors,消除模板里编译期不可达的硬编码 hex。 * * 做法: * 1) 模板属性 `attr=#HEX` → `:attr="Color"` * 2) script 内补 `import { BrandColors } from '@/utils/brand-colors.js'`(已存在则跳过) * 3) 在 data() 的 return 对象首部(无 data 则 computed,再否则新建 computed)注入 * `Color: BrandColors.,` * * 用法: node scripts/d37-template-color-bind.js [--dry] */ const fs = require('fs'); const HEXT_TO_KEY = { '#FF8C42': 'body', '#F97316': 'primary', '#10B981': 'success', '#6366F1': 'wisdom', '#F59E0B': 'wealth', '#FF6B9D': 'mind', }; const FILES = [ 'pages/action-detail/index.vue', 'pages/body-detail/index.vue', 'pages/child/rewards.vue', 'pages/discover/create-circle.vue', 'pages/discover-detail/product-detail/product-detail.vue', 'pages/family/add-member.vue', 'pages/health/components/ComprehensiveSurvey.vue', 'pages/health/daily-checkin.vue', 'pages/health/sleep-index.vue', 'pages/health-main/index.vue', 'pages/member-detail/components/member-detail-sections/body-section.vue', 'pages/mind-detail/index.vue', 'pages/profile/components/ProfileMenu.vue', 'pages/promotion/index.vue', 'pages/rewards/rewards.vue', 'pages/wealth/components/WealthEnergyRing.vue', 'pages/wealth/index.vue', 'pages/wisdom-detail/index.vue', ]; const DRY = process.argv.includes('--dry'); const IMPORT_LINE = "import { BrandColors } from '@/utils/brand-colors.js'"; let totalBind = 0; for (const f of FILES) { let src = fs.readFileSync(f, 'utf8'); const eol = src.includes('\r\n') ? '\r\n' : '\n'; // 只在模板区(第一个行首