修改小程序切换脚本
parent
7660cc28cd
commit
d2f1c13640
|
|
@ -39,5 +39,18 @@
|
||||||
- [[智慧农业认养系统]](https://gitee.com/tony2y/smart-breed):基于Java + SpringBoot + Mybatis Plus + Redis + Vue + antdv,支持认养、商城、营销、会员、进销存、多租户等功能,包含小程序,系统管理后台。
|
- [[智慧农业认养系统]](https://gitee.com/tony2y/smart-breed):基于Java + SpringBoot + Mybatis Plus + Redis + Vue + antdv,支持认养、商城、营销、会员、进销存、多租户等功能,包含小程序,系统管理后台。
|
||||||
- [[智慧景区管理系统]](https://gitee.com/tony2y/scenic-spot):基于Java + SpringBoot + Mybatis Plus + Redis + Vue + antdv,支持景区管理、售票、地块管理、认养、商城、农资管理、积分兑换等功能,包含小程序,系统管理后台。
|
- [[智慧景区管理系统]](https://gitee.com/tony2y/scenic-spot):基于Java + SpringBoot + Mybatis Plus + Redis + Vue + antdv,支持景区管理、售票、地块管理、认养、商城、农资管理、积分兑换等功能,包含小程序,系统管理后台。
|
||||||
|
|
||||||
数字项管:wx46466c7828eede2b
|
写一个切换环境的 js,根据不同的环境修改 config.js,config.wxs 和 project.config.json 文件中的配置项
|
||||||
筑安施工:wx007a8fd50dc185b2
|
|
||||||
|
数字项管(A):
|
||||||
|
appid:wx46466c7828eede2b
|
||||||
|
baseUrl:https://xiangguan.sxyanzhu.com/wechat
|
||||||
|
baseImgUrl:https://xiangguan.sxyanzhu.com
|
||||||
|
|
||||||
|
筑安施工(B):
|
||||||
|
appid:wx007a8fd50dc185b2
|
||||||
|
baseUrl:https://jaszpt.crfeb.com.cn/wechat
|
||||||
|
baseImgUrl:https://jaszpt.crfeb.com.cn
|
||||||
|
|
||||||
|
注意修改图片路径要修改两个文件
|
||||||
|
config.js
|
||||||
|
config.wxs
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
// 应用全局配置
|
// 应用全局配置
|
||||||
module.exports = {
|
module.exports = {
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
appId: "wx007a8fd50dc185b2",
|
appId: "wx46466c7828eede2b",
|
||||||
//baseUrl: "https://xiangguan.sxyanzhu.com/wechat",
|
baseUrl: "https://xiangguan.sxyanzhu.com/wechat",
|
||||||
baseUrl: "https://jaszpt.crfeb.com.cn/wechat",
|
////baseUrl: "https://jaszpt.crfeb.com.cn/wechat",
|
||||||
//baseUrl: "http://127.0.0.1:8080",
|
//baseUrl: "http://127.0.0.1:8080",
|
||||||
//baseImgUrl: "https://xiangguan.sxyanzhu.com",
|
baseImgUrl: "https://xiangguan.sxyanzhu.com",
|
||||||
baseImgUrl: "https://jaszpt.crfeb.com.cn",
|
////baseImgUrl: "https://jaszpt.crfeb.com.cn",
|
||||||
//baseImgUrl: 'http://127.0.0.1:9300',
|
//baseImgUrl: 'http://127.0.0.1:9300',
|
||||||
noSecuritys: [
|
noSecuritys: [
|
||||||
"/code",
|
"/code",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"appid": "wx007a8fd50dc185b2",
|
"appid": "wx46466c7828eede2b",
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"libVersion": "3.8.9",
|
"libVersion": "3.8.9",
|
||||||
"packOptions": {
|
"packOptions": {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// WXS 配置文件
|
// WXS 配置文件
|
||||||
var config = {
|
var config = {
|
||||||
// 与 config.js 中的 baseImgUrl 保持同步
|
// 与 config.js 中的 baseImgUrl 保持同步
|
||||||
baseImgUrl: "https://jaszpt.crfeb.com.cn",
|
baseImgUrl: "https://xiangguan.sxyanzhu.com",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"name": "yanzhu-ui-app",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "研筑-临时工程项目管理App",
|
||||||
|
"scripts": {
|
||||||
|
"switch": "node switchEnv.js"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"微信小程序",
|
||||||
|
"工程项目管理",
|
||||||
|
"Flowable",
|
||||||
|
"RuoYi"
|
||||||
|
],
|
||||||
|
"author": "研筑团队",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
// 环境配置
|
||||||
|
const envConfigs = {
|
||||||
|
A: {
|
||||||
|
name: "数字项管",
|
||||||
|
displayName: "A (数字项管)",
|
||||||
|
appId: "wx46466c7828eede2b",
|
||||||
|
baseUrl: "https://xiangguan.sxyanzhu.com/wechat",
|
||||||
|
baseImgUrl: "https://xiangguan.sxyanzhu.com",
|
||||||
|
},
|
||||||
|
B: {
|
||||||
|
name: "筑安施工",
|
||||||
|
displayName: "B (筑安施工)",
|
||||||
|
appId: "wx007a8fd50dc185b2",
|
||||||
|
baseUrl: "https://jaszpt.crfeb.com.cn/wechat",
|
||||||
|
baseImgUrl: "https://jaszpt.crfeb.com.cn",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 文件路径
|
||||||
|
const configJsPath = path.join(__dirname, "miniprogram", "config.js");
|
||||||
|
const configWxsPath = path.join(
|
||||||
|
__dirname,
|
||||||
|
"miniprogram",
|
||||||
|
"utils",
|
||||||
|
"config.wxs"
|
||||||
|
);
|
||||||
|
const projectConfigPath = path.join(
|
||||||
|
__dirname,
|
||||||
|
"miniprogram",
|
||||||
|
"project.config.json"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 更新 config.js
|
||||||
|
function updateConfigJs(env) {
|
||||||
|
let content = fs.readFileSync(configJsPath, "utf8");
|
||||||
|
|
||||||
|
// 更新 appId
|
||||||
|
content = content.replace(/appId:\s*"[^"]*"/, `appId: "${env.appId}"`);
|
||||||
|
|
||||||
|
// 更新 baseUrl (取消注释目标环境,注释其他环境)
|
||||||
|
if (env.name === "数字项管") {
|
||||||
|
// 启用数字项管,注释其他
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com\/wechat"/,
|
||||||
|
`baseUrl: "${env.baseUrl}"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/baseUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn\/wechat"/,
|
||||||
|
`//baseUrl: "https://jaszpt.crfeb.com.cn/wechat"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseUrl:\s*"http:\/\/127\.0\.0\.1:8080"/,
|
||||||
|
`//baseUrl: "http://127.0.0.1:8080"`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 启用筑安施工,注释其他
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn\/wechat"/,
|
||||||
|
`baseUrl: "${env.baseUrl}"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/baseUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com\/wechat"/,
|
||||||
|
`//baseUrl: "https://xiangguan.sxyanzhu.com/wechat"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseUrl:\s*"http:\/\/127\.0\.0\.1:8080"/,
|
||||||
|
`//baseUrl: "http://127.0.0.1:8080"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新 baseImgUrl (取消注释目标环境,注释其他)
|
||||||
|
if (env.name === "数字项管") {
|
||||||
|
// 启用数字项管,注释其他
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseImgUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com"/,
|
||||||
|
`baseImgUrl: "${env.baseImgUrl}"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/baseImgUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn"/,
|
||||||
|
`//baseImgUrl: "https://jaszpt.crfeb.com.cn"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseImgUrl:\s*'http:\/\/127\.0\.0\.1:9300'/,
|
||||||
|
`//baseImgUrl: 'http://127.0.0.1:9300'`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 启用筑安施工,注释其他
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseImgUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn"/,
|
||||||
|
`baseImgUrl: "${env.baseImgUrl}"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/baseImgUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com"/,
|
||||||
|
`//baseImgUrl: "https://xiangguan.sxyanzhu.com"`
|
||||||
|
);
|
||||||
|
content = content.replace(
|
||||||
|
/\/\/baseImgUrl:\s*'http:\/\/127\.0\.0\.1:9300'/,
|
||||||
|
`//baseImgUrl: 'http://127.0.0.1:9300'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(configJsPath, content, "utf8");
|
||||||
|
console.log(`✅ 已更新 config.js 为 ${env.name} 环境`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新 config.wxs
|
||||||
|
function updateConfigWxs(env) {
|
||||||
|
let content = fs.readFileSync(configWxsPath, "utf8");
|
||||||
|
|
||||||
|
// 更新 baseImgUrl
|
||||||
|
content = content.replace(
|
||||||
|
/baseImgUrl:\s*"[^"]*"/,
|
||||||
|
`baseImgUrl: "${env.baseImgUrl}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFileSync(configWxsPath, content, "utf8");
|
||||||
|
console.log(`✅ 已更新 config.wxs 为 ${env.name} 环境`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新 project.config.json
|
||||||
|
function updateProjectConfig(env) {
|
||||||
|
const content = fs.readFileSync(projectConfigPath, "utf8");
|
||||||
|
const config = JSON.parse(content);
|
||||||
|
|
||||||
|
// 更新 appId
|
||||||
|
config.appid = env.appId;
|
||||||
|
|
||||||
|
fs.writeFileSync(projectConfigPath, JSON.stringify(config, null, 4), "utf8");
|
||||||
|
console.log(`✅ 已更新 project.config.json 为 ${env.name} 环境`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主函数
|
||||||
|
function main() {
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
let envName = args[0];
|
||||||
|
|
||||||
|
// 如果没有传参数,提示用户选择
|
||||||
|
if (!envName) {
|
||||||
|
console.log("🔧 当前支持的环境:");
|
||||||
|
console.log(" A - 数字项管");
|
||||||
|
console.log(" B - 筑安施工");
|
||||||
|
console.log("\n💡 使用方法: node switchEnv.js <环境标识>");
|
||||||
|
console.log(" 例如: node switchEnv.js A");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 匹配环境
|
||||||
|
let selectedEnv = null;
|
||||||
|
for (const [key, env] of Object.entries(envConfigs)) {
|
||||||
|
if (key.includes(envName) || env.name.includes(envName)) {
|
||||||
|
selectedEnv = env;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!selectedEnv) {
|
||||||
|
console.error(`❌ 未找到环境: ${envName}`);
|
||||||
|
console.log("🔧 支持的环境:");
|
||||||
|
Object.entries(envConfigs).forEach(([key, env]) => {
|
||||||
|
console.log(` ${key} - ${env.name}`);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`🔄 正在切换到 ${selectedEnv.displayName} 环境...`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateConfigJs(selectedEnv);
|
||||||
|
updateConfigWxs(selectedEnv);
|
||||||
|
updateProjectConfig(selectedEnv);
|
||||||
|
console.log(`\n🎉 环境切换成功!当前环境: ${selectedEnv.displayName}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`❌ 环境切换失败: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
Loading…
Reference in New Issue