0
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-11-22 11:47:30 +01:00
uptime-kuma/extra/update-wiki-version.js

59 lines
1.4 KiB
JavaScript
Raw Normal View History

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