You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
44 lines
1.1 KiB
import child_process from "child_process";
|
|
import fs from "fs";
|
|
|
|
const newVersion = process.env.VERSION;
|
|
|
|
updateWiki(newVersion);
|
|
|
|
function updateWiki(newVersion) {
|
|
const wikiDir = "./tmp/wiki";
|
|
const howToUpdateFilename = "./tmp/wiki/🆙-How-to-Update.md";
|
|
|
|
safeDelete(wikiDir);
|
|
|
|
child_process.spawnSync("git", ["clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir]);
|
|
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);
|
|
|
|
child_process.spawnSync("git", ["add", "-A"], {
|
|
cwd: wikiDir,
|
|
});
|
|
|
|
child_process.spawnSync("git", ["commit", "-m", `Update to ${newVersion}`], {
|
|
cwd: wikiDir,
|
|
});
|
|
|
|
console.log("Pushing to Github");
|
|
child_process.spawnSync("git", ["push"], {
|
|
cwd: wikiDir,
|
|
});
|
|
|
|
safeDelete(wikiDir);
|
|
}
|
|
|
|
function safeDelete(dir) {
|
|
if (fs.existsSync(dir)) {
|
|
fs.rmdirSync(dir, {
|
|
recursive: true,
|
|
});
|
|
}
|
|
}
|