uptime-kuma/extra/update-wiki-version.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

const childProcess = require("child_process");
2022-03-24 07:44:22 -07:00
const fs = require("fs");
2022-03-22 01:45:07 -07:00
const newVersion = process.env.VERSION;
2022-03-24 07:44:22 -07:00
if (!newVersion) {
console.log("Missing version");
process.exit(1);
}
2022-03-22 01:45:07 -07:00
updateWiki(newVersion);
function updateWiki(newVersion) {
const wikiDir = "./tmp/wiki";
const howToUpdateFilename = "./tmp/wiki/🆙-How-to-Update.md";
safeDelete(wikiDir);
childProcess.spawnSync("git", ["clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir]);
2022-03-22 01:45:07 -07:00
let content = fs.readFileSync(howToUpdateFilename).toString();
// Replace the version: https://regex101.com/r/hmj2Bc/1
content = content.replace(/(git checkout )([^\s]+)/, `$1${newVersion}`);
fs.writeFileSync(howToUpdateFilename, content);
childProcess.spawnSync("git", ["add", "-A"], {
2022-03-22 01:45:07 -07:00
cwd: wikiDir,
});
childProcess.spawnSync("git", ["commit", "-m", `Update to ${newVersion}`], {
2022-03-22 01:45:07 -07:00
cwd: wikiDir,
});
console.log("Pushing to Github");
childProcess.spawnSync("git", ["push"], {
2022-03-22 01:45:07 -07:00
cwd: wikiDir,
});
safeDelete(wikiDir);
}
function safeDelete(dir) {
if (fs.existsSync(dir)) {
fs.rmdirSync(dir, {
recursive: true,
});
}
}