From d2908c72d06aa1d54e55dd557d28678ab565c34b Mon Sep 17 00:00:00 2001 From: Nathan Smith Date: Thu, 11 Apr 2024 22:54:19 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20ci:=20Update=20version=20bump=20?= =?UTF-8?q?script=20to=20take=20an=20arg=20and=20update=20everywhere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- version-bump.mjs | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/version-bump.mjs b/version-bump.mjs index d409fa0..e98c621 100644 --- a/version-bump.mjs +++ b/version-bump.mjs @@ -1,14 +1,30 @@ -import { readFileSync, writeFileSync } from "fs"; +import fs from "fs"; +import { execSync } from "child_process"; -const targetVersion = process.env.npm_package_version; +const version = process.argv[2]; -// read minAppVersion from manifest.json and bump version to target version -let manifest = JSON.parse(readFileSync("manifest.json", "utf8")); -const { minAppVersion } = manifest; -manifest.version = targetVersion; -writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); +if (!version) { + console.error("Please provide a version number as a command line argument."); + process.exit(1); +} -// update versions.json with target version and minAppVersion from manifest.json -let versions = JSON.parse(readFileSync("versions.json", "utf8")); -versions[targetVersion] = minAppVersion; -writeFileSync("versions.json", JSON.stringify(versions, null, "\t")); +// Update package.json +const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8")); +packageJson.version = version; +fs.writeFileSync("package.json", JSON.stringify(packageJson, null, "\t")); + +// Update manifest.json +const manifestJson = JSON.parse(fs.readFileSync("manifest.json", "utf8")); +manifestJson.version = version; +fs.writeFileSync("manifest.json", JSON.stringify(manifestJson, null, "\t")); + +// Update versions.json +const versionsJson = JSON.parse(fs.readFileSync("versions.json", "utf8")); +const hostSoftwareVersion = Object.values(versionsJson)[0]; // Assuming the first entry is the previous version +const newVersionsJson = { [version]: hostSoftwareVersion, ...versionsJson }; +fs.writeFileSync("versions.json", JSON.stringify(newVersionsJson, null, "\t")); + +// Update package-lock.json by running npm install +execSync("npm install", { stdio: "inherit" }); + +console.log("Version updated successfully.");