replaceEnv.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as fs from 'fs'
  2. import path from 'path'
  3. // 同步读取文件内容
  4. function readFileSync(filePath) {
  5. return fs.readFileSync(filePath, 'utf8');
  6. }
  7. // 同步写入文件内容
  8. function writeFileSync(filePath, data) {
  9. fs.writeFileSync(filePath, data, 'utf8');
  10. }
  11. // 替换文件中的文本
  12. function replaceTextInFileSync(filePath, matchKey, str, templateFilePath) {
  13. try {
  14. // 读取文件内容
  15. let fileContent = readFileSync(templateFilePath || filePath);
  16. // 替换文本
  17. const newContent = fileContent.replaceAll(matchKey, str);
  18. // 写入新内容到文件
  19. writeFileSync(filePath, newContent);
  20. console.log('环境文本替换:', `${matchKey} ===> ${str}`);
  21. } catch (error) {
  22. console.error('文本替换失败:', error);
  23. }
  24. }
  25. function replaceStyle (color) {
  26. replaceTextInFileSync(path.resolve('./src/assets/env_style/scss.scss'), '#2ABED1', color, path.resolve('./script/template/env_style/scss.scss'))
  27. replaceTextInFileSync(path.resolve('./src/assets/env_style/less.less'), '#2ABED1', color, path.resolve('./script/template/env_style/less.less'))
  28. }
  29. function replaceEnvCode () {
  30. // 替换AppId
  31. // 替换主题色、图标、全部商机列表配置
  32. replaceStyle('#0ec684')
  33. // 替换 Tabbar 配置
  34. // 替换请求域名、资源域名
  35. }
  36. replaceEnvCode()