66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
const fs = require("fs");
|
||
const obj = require("../config/app_config");
|
||
// 获取当前工作目录路径
|
||
const currentDirPath = process.cwd();
|
||
// 定义需要更改的 package.json 文件路径
|
||
const packageJsonFilePath = `${currentDirPath}/package.json`;
|
||
const installerFilePath = `${currentDirPath}/installer.nsh`;
|
||
const installText = `${currentDirPath}/install.txt`;
|
||
|
||
/*function setEnvior() {}*/
|
||
|
||
let Factory = (function() {
|
||
return {
|
||
mains: function() {
|
||
// 读取原始的 package.json 内容
|
||
let packageData;
|
||
let y;
|
||
try {
|
||
const str = String(fs.readFileSync(installText));
|
||
y = str.replace(/installurl/g, obj.installUrl);
|
||
const rawData = fs.readFileSync(packageJsonFilePath);
|
||
packageData = JSON.parse(rawData);
|
||
} catch (error) {
|
||
console.log(error);
|
||
console.log(`无法读取 ${packageJsonFilePath}`);
|
||
return;
|
||
}
|
||
|
||
// 根据自定义逻辑修改 package.json 中的 name 字段(这里示意性地将其设置为 "new_app")
|
||
for (const objKey in obj) {
|
||
if (objKey.indexOf("_") > -1) {
|
||
let keyArr = [];
|
||
keyArr = objKey.split("_");
|
||
//[win,icon]=>["win"]["icon"]
|
||
let str = '["' + keyArr.join('"]["') + '"]';
|
||
console.log(str);
|
||
try {
|
||
eval(`packageData${str} = obj[objKey]`);
|
||
} catch (e) {}
|
||
} else {
|
||
if (packageData.hasOwnProperty(objKey)) {
|
||
packageData[objKey] = obj[objKey];
|
||
}
|
||
if(objKey=="isSetDefaultLayer"){
|
||
localStorage.setItem("isSetDefaultLayer",obj[objKey])
|
||
}
|
||
|
||
}
|
||
}
|
||
console.log(packageData);
|
||
// 写入修改后的 package.json 数据
|
||
fs.writeFileSync(packageJsonFilePath, JSON.stringify(packageData));
|
||
fs.writeFileSync(installerFilePath, y);
|
||
},
|
||
setEnvior: function() {
|
||
// console.log("*********************", obj.head);
|
||
if(obj.hasOwnProperty('isSetDefaultLayer')){
|
||
// localStorage.setItem("isSetDefaultLayer",obj[objKey])
|
||
}
|
||
// process.env.Head = obj.head;
|
||
return obj.head;
|
||
}
|
||
};
|
||
})();
|
||
module.exports = Factory;
|