2022-04-16 13:39:49 -04:00
|
|
|
const childProcess = require("child_process");
|
2022-03-24 10:44:22 -04:00
|
|
|
const fs = require("fs");
|
2022-03-22 04:45:07 -04:00
|
|
|
|
|
|
|
const newVersion = process.env.VERSION;
|
|
|
|
|
2022-03-24 10:44:22 -04:00
|
|
|
if (!newVersion) {
|
|
|
|
console.log("Missing version");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2022-03-22 04:45:07 -04:00
|
|
|
updateWiki(newVersion);
|
|
|
|
|
2023-01-05 14:57:28 -05:00
|
|
|
/**
|
|
|
|
* Update the wiki with new version number
|
|
|
|
* @param {string} newVersion Version to update to
|
2023-08-11 03:46:41 -04:00
|
|
|
* @returns {void}
|
2023-01-05 14:57:28 -05:00
|
|
|
*/
|
2022-03-22 04:45:07 -04:00
|
|
|
function updateWiki(newVersion) {
|
|
|
|
const wikiDir = "./tmp/wiki";
|
|
|
|
const howToUpdateFilename = "./tmp/wiki/🆙-How-to-Update.md";
|
|
|
|
|
|
|
|
safeDelete(wikiDir);
|
|
|
|
|
2022-04-17 03:27:35 -04:00
|
|
|
childProcess.spawnSync("git", [ "clone", "https://github.com/louislam/uptime-kuma.wiki.git", wikiDir ]);
|
2022-03-22 04:45:07 -04: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);
|
|
|
|
|
2022-04-17 03:27:35 -04:00
|
|
|
childProcess.spawnSync("git", [ "add", "-A" ], {
|
2022-03-22 04:45:07 -04:00
|
|
|
cwd: wikiDir,
|
|
|
|
});
|
|
|
|
|
2022-04-17 03:27:35 -04:00
|
|
|
childProcess.spawnSync("git", [ "commit", "-m", `Update to ${newVersion}` ], {
|
2022-03-22 04:45:07 -04:00
|
|
|
cwd: wikiDir,
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Pushing to Github");
|
2022-04-17 03:27:35 -04:00
|
|
|
childProcess.spawnSync("git", [ "push" ], {
|
2022-03-22 04:45:07 -04:00
|
|
|
cwd: wikiDir,
|
|
|
|
});
|
|
|
|
|
|
|
|
safeDelete(wikiDir);
|
|
|
|
}
|
|
|
|
|
2023-01-05 14:57:28 -05:00
|
|
|
/**
|
2023-01-06 12:17:37 -05:00
|
|
|
* Check if a directory exists and then delete it
|
2023-01-05 14:57:28 -05:00
|
|
|
* @param {string} dir Directory to delete
|
2023-08-11 03:46:41 -04:00
|
|
|
* @returns {void}
|
2023-01-05 14:57:28 -05:00
|
|
|
*/
|
2022-03-22 04:45:07 -04:00
|
|
|
function safeDelete(dir) {
|
|
|
|
if (fs.existsSync(dir)) {
|
2022-06-23 07:18:28 -04:00
|
|
|
fs.rm(dir, {
|
2022-03-22 04:45:07 -04:00
|
|
|
recursive: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|