import * as fs from 'fs' import path from 'path' // 同步读取文件内容 function readFileSync(filePath) { return fs.readFileSync(filePath, 'utf8'); } // 同步写入文件内容 function writeFileSync(filePath, data) { fs.writeFileSync(filePath, data, 'utf8'); } // 替换文件中的文本 function replaceTextInFileSync(filePath, matchKey, str, templateFilePath) { try { // 读取文件内容 let fileContent = readFileSync(templateFilePath || filePath); // 替换文本 const newContent = fileContent.replaceAll(matchKey, str); // 写入新内容到文件 writeFileSync(filePath, newContent); console.log('环境文本替换:', `${matchKey} ===> ${str}`); } catch (error) { console.error('文本替换失败:', error); } } function replaceStyle (color) { replaceTextInFileSync(path.resolve('./src/assets/env_style/scss.scss'), '#2ABED1', color, path.resolve('./script/template/env_style/scss.scss')) replaceTextInFileSync(path.resolve('./src/assets/env_style/less.less'), '#2ABED1', color, path.resolve('./script/template/env_style/less.less')) } function replaceEnvCode () { // 替换AppId // 替换主题色、图标、全部商机列表配置 replaceStyle('#0ec684') // 替换 Tabbar 配置 // 替换请求域名、资源域名 } replaceEnvCode()