feat: 由脚本自动更新主题颜色
This commit is contained in:
@@ -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("💡 提示: 请检查文件内容确认更新正确");
|
||||
|
||||
Reference in New Issue
Block a user