فهرست منبع

chore: 新增配置项主题色替换模板

zhangyuhan 1 سال پیش
والد
کامیت
7abbae75fb
5فایلهای تغییر یافته به همراه53 افزوده شده و 38 حذف شده
  1. 1 1
      package.json
  2. 0 37
      script/replaceEnv.js
  3. 46 0
      script/replaceEnv.mjs
  4. 1 0
      script/template/env_style/less.less
  5. 5 0
      script/template/env_style/scss.scss

+ 1 - 1
package.json

@@ -10,7 +10,7 @@
     "framework": "Vue"
   },
   "scripts": {
-    "pre:env": "node script/replaceEnv.js",
+    "pre:env": "node script/replaceEnv.mjs",
     "build:weapp": "npm run pre:env && taro build --type weapp",
     "build:h5": "taro build --type h5",
     "dev:pord-weapp": "NODE_ENV=production npm run build:weapp -- --watch",

+ 0 - 37
script/replaceEnv.js

@@ -1,37 +0,0 @@
-const fs = require('fs');
-const path = require('path');
-
-// 同步读取文件内容
-function readFileSync(filePath) {
-  return fs.readFileSync(filePath, 'utf8');
-}
-
-// 同步写入文件内容
-function writeFileSync(filePath, data) {
-  fs.writeFileSync(filePath, data, 'utf8');
-}
-
-// 替换文件中的文本
-function replaceTextInFileSync(filePath, matchKey, str) {
-  try {
-    // 读取文件内容
-    let fileContent = readFileSync(filePath);
-
-    // 替换文本
-    const newContent = fileContent.replace(matchKey, str);
-
-    // 写入新内容到文件
-    writeFileSync(filePath, newContent);
-
-    console.log('文本替换完成。');
-  } catch (error) {
-    console.error('文本替换失败:', error);
-  }
-}
-
-// 使用示例
-const filePath = path.resolve('./src/assets/style/_variables.scss'); // 替换为你的文件路径
-const matchKey = '$main: #2ABED1;'; // 替换为需要查找并替换的文本
-const str = '$main: #111;'; // 替换为新的文本
-
-// replaceTextInFileSync(filePath, matchKey, str);

+ 46 - 0
script/replaceEnv.mjs

@@ -0,0 +1,46 @@
+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()

+ 1 - 0
script/template/env_style/less.less

@@ -0,0 +1 @@
+@themeColor: #2ABED1;

+ 5 - 0
script/template/env_style/scss.scss

@@ -0,0 +1,5 @@
+$themeColor: #2ABED1;
+
+page {
+  --themeColor: #2ABED1;
+}