两个app只有一些图片,请求接口地址,manifest.json不一致,其他主要业务代码基本一样。如何去做呢,不想拉两套代码。

l***@qq.com
- 发布:2025-04-11 16:41
- 更新:2025-04-14 17:39
- 阅读:1844

l***@qq.com (作者)
解决了,就是上面说的替换的方法
1.新建node.js文件,放在项目根目录下
//替换app种不同的部分打包
const fs = require('fs');
const path = require('path');
// 获取命令行参数
const args = process.argv.slice(2);
console.log(args);
if (args.length !== 1) {
console.error('Usage: node node.js <source-file-path>');
process.exit(1);
}
const sourceFilePath = './manifest_' + args + '.json';
const sourceFilePath2 = './androidPrivacy_' + args + '.json';
const targetFilePath = './manifest.json';
const targetFilePath2 = './androidPrivacy.json';
// 检查源文件是否存在
if (!fs.existsSync(sourceFilePath)) {
console.error(`Source file not found: ${sourceFilePath}`);
process.exit(1);
}
// 读取源文件内容
const sourceFileContent = fs.readFileSync(sourceFilePath, 'utf8');
// 读取源文件内容
const sourceFileContent2 = fs.readFileSync(sourceFilePath2, 'utf8');
// 写入源文件内容到目标文件,覆盖原有内容
fs.writeFileSync(targetFilePath, sourceFileContent, 'utf8');
fs.writeFileSync(targetFilePath2, sourceFileContent2, 'utf8');
console.log(`Replaced content in ${targetFilePath} with content from ${sourceFilePath}.`);
console.log(`Replaced content in ${targetFilePath2} with content from ${sourceFilePath2}.`);
2.新建多个环境的manifest_xxx.json 和 /androidPrivacy_xxx.json
3.使用node命令切换环境
#test 与上面xxx对应
node node.js test
l***@qq.com (作者)
没有额,图标,名称那些都不一样的,苹果应用商店两个app都已经通过了
2025-04-11 16:56
l***@qq.com (作者)
现在就是拉了两套代码来做的,维护太累了,说不定以后还有其他环境的
2025-04-11 16:57
恭喜n发财
回复 l***@qq.com:
脚本文件node.js
const fs = require('fs');
const a = JSON.parse(fs.readFileSync('./a.json', 'utf8'));
const manifest = JSON.parse(fs.readFileSync('./manifestbf.json', 'utf8'));
manifest.name = a.appName;
manifest.description = a.desc;
manifest.versionName = String(a.banben);
fs.writeFileSync('./manifest.json', JSON.stringify(manifest, null, 2), 'utf8');
console.log('manifest.json 生成完毕');
1、manifestbf.json复制原来那个文件删除所有备份
2、a json就是你需要替换的一些内容,标题图片啥的
3、需要安装一下fs 然后执行 node node.js
2025-04-11 17:32
恭喜n发财
回复 恭喜n发财: 删除所有注释 打错了
2025-04-11 17:32
恭喜n发财
回复 恭喜n发财: {
"appName": "应用名称",
"desc": "描述",
"banben": 101
} ajson
2025-04-11 17:33
l***@qq.com (作者)
回复 恭喜n发财: 感觉这样可以,我试试。谢谢!
2025-04-14 08:38