feat: 由脚本自动更新主题颜色

This commit is contained in:
2026-03-10 16:36:13 +08:00
parent df8a7f4de7
commit 5031a710db
3 changed files with 59 additions and 12 deletions

View File

@@ -15,7 +15,14 @@
"ipSmallImageWidth": 128,
"ipSmallImageHeight": 128,
"ipSmallTotalFrames": 117,
"ipSmallColumns": 1
"ipSmallColumns": 1,
"theme": {
"theme-color-800": "#0B7034",
"theme-color-700": "#0B5C2D",
"theme-color-500": "#0CCD58",
"theme-color-100": "#E8FFF1",
"theme-color-50": "#F0F8F3"
}
},
"duohua": {
"clientId": "2",
@@ -33,7 +40,14 @@
"ipSmallImageWidth": 128,
"ipSmallImageHeight": 128,
"ipSmallTotalFrames": 117,
"ipSmallColumns": 1
"ipSmallColumns": 1,
"theme": {
"theme-color-800": "#0B7034",
"theme-color-700": "#0B5C2D",
"theme-color-500": "#0CCD58",
"theme-color-100": "#E8FFF1",
"theme-color-50": "#F0F8F3"
}
},
"tianmu": {
"clientId": "4",
@@ -51,6 +65,13 @@
"ipSmallImageWidth": 128,
"ipSmallImageHeight": 128,
"ipSmallTotalFrames": 148,
"ipSmallColumns": 1
"ipSmallColumns": 1,
"theme": {
"theme-color-800": "#8B5CF6",
"theme-color-700": "#7C3AED",
"theme-color-500": "#A78BFA",
"theme-color-100": "#EDE9FE",
"theme-color-50": "#F5F3FF"
}
}
}

View File

@@ -50,6 +50,38 @@ if (!input) {
// 文件路径
const manifestPath = path.join(__dirname, "../src/manifest.json");
const projectConfigPath = path.join(__dirname, "../project.config.json");
const uniScssPath = path.join(__dirname, "../src/uni.scss");
/**
* 更新 uni.scss 中的主题色变量
*/
function updateUniScss(clientName) {
try {
const theme = CLIENT_CONFIGS[clientName].theme;
if (!theme) {
console.log("⚠️ 未找到主题色配置,跳过更新 uni.scss");
return true;
}
console.log("📝 正在更新 uni.scss 主题色...");
let content = fs.readFileSync(uniScssPath, "utf8");
// 更新主题色变量
const themeKeys = Object.keys(theme);
themeKeys.forEach((key) => {
// 匹配形如 $theme-color-800: #174BB6; 的正则
const regex = new RegExp(`(\\\$${key}):\\s*#[0-9a-fA-F]+;`);
content = content.replace(regex, `$1: ${theme[key]};`);
});
fs.writeFileSync(uniScssPath, content, "utf8");
console.log("✅ uni.scss 主题色更新成功");
return true;
} catch (error) {
console.error("❌ 更新 uni.scss 失败:", error.message);
return false;
}
}
/**
* 更新base.js中的getCurrentConfig函数
@@ -195,8 +227,9 @@ function main() {
const baseSuccess = updateBaseJs(clientName);
const manifestSuccess = updateManifestJson(newAppId);
const projectConfigSuccess = updateProjectConfigJson(newAppId);
const scssSuccess = updateUniScss(clientName);
if (baseSuccess && manifestSuccess && projectConfigSuccess) {
if (baseSuccess && manifestSuccess && projectConfigSuccess && scssSuccess) {
console.log("\n🎉 所有文件更新完成!");
console.log(`💡 已切换到 ${CLIENT_CONFIGS[clientName].name} 客户端配置`);
console.log("💡 提示: 请检查文件内容确认更新正确");

View File

@@ -12,14 +12,7 @@
* 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* 主题颜色:蓝色 */
// $theme-color-800: #174BB6;
// $theme-color-700: #19428F;
// $theme-color-500: #2D91FF;
// $theme-color-100: #D9EEFF;
// $theme-color-50: #EEF8FF;
/* 主题颜色:绿色 */
/* 主题颜色(由 switch-client 命令自动更新) */
$theme-color-800: #0B7034;
$theme-color-700: #0B5C2D;
$theme-color-500: #0CCD58;