Ver Fonte

chore: 支持编译多个小程序

zhangyuhan há 1 ano atrás
pai
commit
0218a462a4

+ 19 - 16
config/index.js

@@ -3,6 +3,9 @@ import { defineConfig } from '@tarojs/cli'
 import devConfig from './dev'
 import prodConfig from './prod'
 import path from "path";
+import appConfig from "../project-config/index.common.js";
+
+const distPath = `dist/${appConfig.projectInfo.appCode}`
 
 // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
 export default defineConfig(async (merge, { command, mode }) => {
@@ -21,7 +24,7 @@ export default defineConfig(async (merge, { command, mode }) => {
       "@/vant": path.resolve(__dirname, "../src/components/vant-weapp"),
       '@': path.resolve(__dirname, '../src'),
     },
-    outputRoot: 'dist',
+    outputRoot: distPath,
     plugins: [
       [
         '@tarojs/plugin-html',
@@ -42,63 +45,63 @@ export default defineConfig(async (merge, { command, mode }) => {
       patterns: [
         {
           from: "src/components/vant-weapp/wxs",
-          to: "dist/components/vant-weapp/wxs",
+          to: distPath + "/components/vant-weapp/wxs",
         },
         {
           from: "src/components/vant-weapp/common/",
-          to: "dist/components/vant-weapp/common/",
+          to: distPath + "/components/vant-weapp/common/",
         },
         {
           from: "src/components/vant-weapp/button",
-          to: "dist/components/vant-weapp/button",
+          to: distPath + "/components/vant-weapp/button",
         },
         {
           from: "src/components/vant-weapp/radio",
-          to: "dist/components/vant-weapp/radio",
+          to: distPath + "/components/vant-weapp/radio",
         },
         {
           from: "src/components/vant-weapp/radio-group",
-          to: "dist/components/vant-weapp/radio-group",
+          to: distPath + "/components/vant-weapp/radio-group",
         },
         {
           from: "src/components/vant-weapp/info",
-          to: "dist/components/vant-weapp/info",
+          to: distPath + "/components/vant-weapp/info",
         },
         {
           from: "src/components/vant-weapp/icon",
-          to: "dist/components/vant-weapp/icon",
+          to: distPath + "/components/vant-weapp/icon",
         },
         {
           from: "src/components/vant-weapp/loading",
-          to: "dist/components/vant-weapp/loading",
+          to: distPath + "/components/vant-weapp/loading",
         },
         {
           from: "src/components/vant-weapp/notice-bar",
-          to: "dist/components/vant-weapp/notice-bar",
+          to: distPath + "/components/vant-weapp/notice-bar",
         },
         {
           from: "src/components/vant-weapp/cell",
-          to: "dist/components/vant-weapp/cell",
+          to: distPath + "/components/vant-weapp/cell",
         },
         {
           from: "src/components/vant-weapp/popup",
-          to: "dist/components/vant-weapp/popup",
+          to: distPath + "/components/vant-weapp/popup",
         },
         {
           from: "src/components/vant-weapp/transition",
-          to: "dist/components/vant-weapp/transition",
+          to: distPath + "/components/vant-weapp/transition",
         },
         {
           from: "src/components/vant-weapp/dropdown-menu",
-          to: "dist/components/vant-weapp/dropdown-menu",
+          to: distPath + "/components/vant-weapp/dropdown-menu",
         },
         {
           from: "src/components/vant-weapp/dropdown-item",
-          to: "dist/components/vant-weapp/dropdown-item",
+          to: distPath + "/components/vant-weapp/dropdown-item",
         },
         {
           from: "src/components/vant-weapp/sticky", // 被 tabs 组件调用,所以一并拷贝
-          to: "dist/components/vant-weapp/sticky",
+          to: distPath + "/components/vant-weapp/sticky",
         },
       ],
       options: {},

Diff do ficheiro suprimidas por serem muito extensas
+ 2 - 0
project-config/index.common.js


+ 5 - 5
script/config/id.config.mjs

@@ -105,7 +105,7 @@ const 商机_物业商机 = [
     tip: '您的会员权益是免费用户',
     rightTip: '免费查看项目',
     icon: '/images/logo/cgyx.png',
-    id: 'wx37f06c38292f7d82',
+    id: 'wxb0549c3059dd9b15',
     path: '/pages/tabbar/home/index'
   },
   {
@@ -123,7 +123,7 @@ const 商机_物业商机 = [
     tip: '您的会员权益是免费用户',
     rightTip: '免费查看项目',
     icon: '/images/logo/lqxm.png',
-    id: 'wx37f06c38292f7d82',
+    id: 'wx8e261baf5c1a4e47',
     path: '/pages/tabbar/home/index'
   },
   {
@@ -132,7 +132,7 @@ const 商机_物业商机 = [
     tip: '您的会员权益是免费用户',
     rightTip: '免费查看项目',
     icon: '/images/logo/jfk.png',
-    id: 'wx37f06c38292f7d82',
+    id: 'wx51bec6e5c53dcc0b',
     path: '/pages/tabbar/home/index'
   },
 ]
@@ -266,12 +266,12 @@ const AppInfoMaps = {
   },
   'wy_qzcgf': {
     project: {
-      appId: 'wxd9e11d95ceecf941',
+      appId: 'wx51bec6e5c53dcc0b',
       appName: '物业 | 甲方库',
       appCode: 'wy_qzcgf',
       appType: '甲方库',
       appDesc: '',
-      payAppId: 'wxd9e11d95ceecf941',
+      payAppId: 'wx51bec6e5c53dcc0b',
       appIcon: '/images/logo/jfk.png',
       themeColor: '#296cee',
     },

+ 27 - 2
script/replaceEnv.mjs

@@ -14,17 +14,28 @@ function writeFileSync(filePath, data) {
 
 // 替换文件中的文本
 function replaceTextInFileSync(filePath, matchKey, str, templateFilePath) {
+  return replaceCustomTextInFileSync({
+    filePath,
+    templateFilePath,
+    replaceFn: function (fileContent) {
+      return fileContent.replaceAll(matchKey, str)
+    }
+  })
+}
+
+// 自定义替换文件中的文本
+function replaceCustomTextInFileSync({ filePath, templateFilePath, replaceFn }) {
   try {
     // 读取文件内容
     let fileContent = readFileSync(templateFilePath || filePath);
 
     // 替换文本
-    const newContent = fileContent.replaceAll(matchKey, str);
+    const newContent = replaceFn(fileContent);
 
     // 写入新内容到文件
     writeFileSync(filePath, newContent);
 
-    console.log('环境文本替换:', `${matchKey} ===> ${str}`);
+    console.log('环境文本替换:', filePath);
   } catch (error) {
     console.error('文本替换失败:', error);
   }
@@ -37,12 +48,26 @@ function replaceStyle (color) {
 
 function replaceAppConfig (data) {
   replaceTextInFileSync(path.resolve('./project-config/index.js'), 'const appConfig = {}', `const appConfig = ${JSON.stringify(data)}`, path.resolve('./script/template/project-config.js'))
+  replaceTextInFileSync(path.resolve('./project-config/index.common.js'), 'const appConfig = {}', `const appConfig = ${JSON.stringify(data)}`, path.resolve('./script/template/project-config.common.js'))
+}
+
+function replaceAppID (data) {
+  replaceCustomTextInFileSync({
+    filePath: path.resolve('./project.config.json'),
+    templateFilePath: path.resolve('./script/template/project.config.json'),
+    replaceFn: (content) => {
+      let result = content.replaceAll('APP_ID', data.projectInfo.appId)
+      result = result.replaceAll('APP_CODE', data.projectInfo.appCode)
+      return result
+    }
+  })
 }
 
 
 export function replaceEnvCode (appCode) {
   const appInfo = getAppInfo(appCode)
   // 替换AppId、Tabbar、图标、全部商机列表配置
+  replaceAppID(appInfo)
   replaceAppConfig(appInfo)
   // 替换主题色
   replaceStyle(appInfo.projectInfo.themeColor)

+ 5 - 0
script/template/project-config.common.js

@@ -0,0 +1,5 @@
+// 该配置由 script/config/id.config.mjs 动态生成
+
+const appConfig = {}
+
+module.exports = appConfig

+ 32 - 0
script/template/project.config.json

@@ -0,0 +1,32 @@
+{
+  "miniprogramRoot": "dist/APP_CODE/",
+  "projectname": "jy-wx-mini2",
+  "description": "jy-wx-mini",
+  "appid": "APP_ID",
+  "setting": {
+    "urlCheck": true,
+    "es6": false,
+    "enhance": false,
+    "compileHotReLoad": false,
+    "postcss": false,
+    "minified": false,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    },
+    "ignoreUploadUnusedFiles": true
+  },
+  "compileType": "miniprogram",
+  "libVersion": "3.4.5",
+  "srcMiniprogramRoot": "dist/APP_CODE/",
+  "packOptions": {
+    "ignore": [],
+    "include": []
+  },
+  "condition": {},
+  "editorSetting": {
+    "tabIndent": "insertSpaces",
+    "tabSize": 2
+  }
+}

+ 2 - 1
src/store/modules/config.js

@@ -62,7 +62,8 @@ export default {
     // 搜索、订阅、中标库等切换配置
     searchTypeConf (_, getters) {
       const { appProjectInfo } = getters
-      const type = SEARCH_DIFF_TYPE_MAP[appProjectInfo.appType]
+      const appCodeType = appProjectInfo.appCode.replace(/^(.*)_/, '')
+      const type = SEARCH_DIFF_TYPE_MAP[appCodeType]
       return {
         type
       }

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff