From 22227be408a6be84d98d745c12b38c08b03408f1 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Wed, 6 Oct 2021 02:06:59 +0800 Subject: [PATCH] update version in wiki too --- extra/update-version.js | 47 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/extra/update-version.js b/extra/update-version.js index ca810a40a..2e3b42da8 100644 --- a/extra/update-version.js +++ b/extra/update-version.js @@ -19,6 +19,7 @@ if (! newVersion) { const exists = tagExists(newVersion); if (! exists) { + // Process package.json pkg.version = newVersion; pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion); @@ -29,8 +30,11 @@ if (! exists) { commit(newVersion); tag(newVersion); + + updateWiki(oldVersion, newVersion); + } else { - console.log("version exists") + console.log("version exists"); } function commit(version) { @@ -38,16 +42,16 @@ function commit(version) { let res = child_process.spawnSync("git", ["commit", "-m", msg, "-a"]); let stdout = res.stdout.toString().trim(); - console.log(stdout) + console.log(stdout); if (stdout.includes("no changes added to commit")) { - throw new Error("commit error") + throw new Error("commit error"); } } function tag(version) { let res = child_process.spawnSync("git", ["tag", version]); - console.log(res.stdout.toString().trim()) + console.log(res.stdout.toString().trim()); } function tagExists(version) { @@ -59,3 +63,38 @@ function tagExists(version) { return res.stdout.toString().trim() === version; } + +function updateWiki(oldVersion, 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(); + content = content.replaceAll(`git checkout ${oldVersion}`, `git checkout ${newVersion}`); + fs.writeFileSync(howToUpdateFilename, content); + + child_process.spawnSync("git", ["add", "-A"], { + cwd: wikiDir, + }); + + child_process.spawnSync("git", ["commit", "-m", `Update to ${newVersion} from ${oldVersion}`], { + 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, + }); + } +}