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

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-03-19 20:08:33 -07:00
const pkg = require("../../package.json");
const fs = require("fs");
2022-04-13 09:30:32 -07:00
const childProcess = require("child_process");
2022-03-19 20:08:33 -07:00
const util = require("../../src/util");
util.polyfill();
const version = process.env.VERSION;
console.log("Beta Version: " + version);
if (!version || !version.includes("-beta.")) {
console.error("invalid version, beta version only");
process.exit(1);
}
const exists = tagExists(version);
if (! exists) {
// Process package.json
pkg.version = version;
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n");
// Also update package-lock.json
2023-02-14 11:20:40 -08:00
const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm";
childProcess.spawnSync(npm, [ "install" ]);
2022-03-21 20:30:45 -07:00
commit(version);
2022-03-19 20:08:33 -07:00
tag(version);
} else {
console.log("version tag exists, please delete the tag or use another tag");
process.exit(1);
}
/**
* Commit updated files
* @param {string} version Version to update to
* @returns {void}
* @throws Error committing files
*/
2022-03-21 20:30:45 -07:00
function commit(version) {
let msg = "Update to " + version;
2022-04-17 00:27:35 -07:00
let res = childProcess.spawnSync("git", [ "commit", "-m", msg, "-a" ]);
2022-03-21 20:30:45 -07:00
let stdout = res.stdout.toString().trim();
console.log(stdout);
if (stdout.includes("no changes added to commit")) {
throw new Error("commit error");
}
2022-03-22 01:45:07 -07:00
2022-04-17 00:27:35 -07:00
res = childProcess.spawnSync("git", [ "push", "origin", "master" ]);
2022-03-22 01:45:07 -07:00
console.log(res.stdout.toString().trim());
2022-03-21 20:30:45 -07:00
}
/**
* Create a tag with the specified version
* @param {string} version Tag to create
* @returns {void}
*/
2022-03-19 20:08:33 -07:00
function tag(version) {
2022-04-17 00:27:35 -07:00
let res = childProcess.spawnSync("git", [ "tag", version ]);
2022-03-19 20:08:33 -07:00
console.log(res.stdout.toString().trim());
2022-03-20 23:31:29 -07:00
2022-04-17 00:27:35 -07:00
res = childProcess.spawnSync("git", [ "push", "origin", version ]);
2022-03-20 23:31:29 -07:00
console.log(res.stdout.toString().trim());
2022-03-19 20:08:33 -07:00
}
/**
* Check if a tag exists for the specified version
* @param {string} version Version to check
* @returns {boolean} Does the tag already exist
* @throws Version is not valid
*/
2022-03-19 20:08:33 -07:00
function tagExists(version) {
if (! version) {
throw new Error("invalid version");
}
2022-04-17 00:27:35 -07:00
let res = childProcess.spawnSync("git", [ "tag", "-l", version ]);
2022-03-19 20:08:33 -07:00
return res.stdout.toString().trim() === version;
}