2024-08-11 07:45:49 +00:00
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const process = require("process");
|
|
|
|
|
|
|
|
|
|
console.log("[NapCat] [CheckVersion] 开始检测当前仓库版本...");
|
|
|
|
|
try {
|
|
|
|
|
const packageJson = require("../package.json");
|
2024-10-27 14:30:01 +00:00
|
|
|
|
const manifsetJson = require("../manifest.json");
|
|
|
|
|
|
2024-08-11 07:45:49 +00:00
|
|
|
|
const currentVersion = packageJson.version;
|
|
|
|
|
const targetVersion = process.env.VERSION;
|
|
|
|
|
|
2024-10-27 14:30:01 +00:00
|
|
|
|
const manifestCurrentVersion = manifsetJson.version;
|
|
|
|
|
const manifestTargetVersion = process.env.VERSION;
|
|
|
|
|
|
2024-08-11 07:45:49 +00:00
|
|
|
|
console.log("[NapCat] [CheckVersion] currentVersion:", currentVersion, "targetVersion:", targetVersion);
|
2024-10-27 14:30:01 +00:00
|
|
|
|
console.log("[NapCat] [CheckVersion] manifestCurrentVersion:", manifestCurrentVersion, "manifestTargetVersion:", manifestTargetVersion);
|
2024-08-11 07:45:49 +00:00
|
|
|
|
|
|
|
|
|
// 验证 targetVersion 格式
|
|
|
|
|
if (!targetVersion || typeof targetVersion !== 'string') {
|
2024-08-11 09:53:15 +00:00
|
|
|
|
console.log("[NapCat] [CheckVersion] 目标版本格式不正确或未设置!");
|
2024-08-11 07:45:49 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-27 14:30:01 +00:00
|
|
|
|
// 验证 manifestTargetVersion 格式
|
|
|
|
|
if (!manifestTargetVersion || typeof manifestTargetVersion !== 'string') {
|
|
|
|
|
console.log("[NapCat] [CheckVersion] manifest目标版本格式不正确或未设置!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-11 07:45:49 +00:00
|
|
|
|
|
|
|
|
|
// 写入脚本文件的统一函数
|
|
|
|
|
const writeScriptToFile = (content) => {
|
|
|
|
|
fs.writeFileSync("./checkVersion.sh", content, { flag: 'w' });
|
|
|
|
|
console.log("[NapCat] [CheckVersion] checkVersion.sh 文件已更新。");
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-27 14:30:01 +00:00
|
|
|
|
if (currentVersion === targetVersion && manifestCurrentVersion === manifestTargetVersion) {
|
2024-08-11 07:45:49 +00:00
|
|
|
|
// 不需要更新版本,写入一个简单的脚本
|
|
|
|
|
const simpleScript = "#!/bin/bash\necho \"CheckVersion Is Done\"";
|
|
|
|
|
writeScriptToFile(simpleScript);
|
|
|
|
|
} else {
|
|
|
|
|
// 更新版本,构建安全的sed命令
|
|
|
|
|
const safeScriptContent = `
|
|
|
|
|
#!/bin/bash
|
2024-10-27 14:45:51 +00:00
|
|
|
|
git config --global user.email "nanaeonn@outlook.com"
|
|
|
|
|
git config --global user.name "Mlikiowa"
|
2024-10-27 14:36:48 +00:00
|
|
|
|
sed -i "s/\\"version\\": \\"${currentVersion}\\"/\\"version\\": \\"${targetVersion}\\"/g" package.json
|
|
|
|
|
sed -i "s/\\"version\\": \\"${manifestCurrentVersion}\\"/\\"version\\": \\"${targetVersion}\\"/g" manifest.json
|
2024-10-27 14:41:46 +00:00
|
|
|
|
sed -i "s/napCatVersion = '.*'/napCatVersion = '${targetVersion}'/g" ./src/common/version.ts
|
|
|
|
|
sed -i "s/SettingButton(\\"V.*\\", \\"napcat-update-button\\", \\"secondary\\")/SettingButton(\\"V${targetVersion}\\", \\"napcat-update-button\\", \\"secondary\\")/g" ./static/assets/renderer.js
|
2024-08-11 07:45:49 +00:00
|
|
|
|
git add .
|
2024-10-27 14:45:51 +00:00
|
|
|
|
git commit -m "release: v${targetVersion}"
|
2024-08-11 07:45:49 +00:00
|
|
|
|
git push -u origin main`;
|
|
|
|
|
writeScriptToFile(safeScriptContent);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2024-08-11 09:53:15 +00:00
|
|
|
|
console.log("[NapCat] [CheckVersion] 检测过程中发生错误:", error);
|
2024-08-11 07:45:49 +00:00
|
|
|
|
}
|