From 98d81b491d274fb1d2497ca89a61d242d4f1a8cb Mon Sep 17 00:00:00 2001 From: CrawlerCode <41094392+CrawlerCode@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:05:56 +0100 Subject: [PATCH] feat: Add update manifest.json version script --- package.json | 2 +- scripts/pack.js | 20 ++++++++++---------- scripts/updateVersion.js | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 scripts/updateVersion.js diff --git a/package.json b/package.json index 339851d..9f28acb 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "type": "module", "scripts": { "dev": "tsc && vite build --watch", - "build": "tsc && vite build", + "build": "node scripts/updateVersion.js && tsc && vite build", "pack": "node scripts/pack.js", "release": "gh release create v%npm_package_version% release/redmine-time-tracking-v%npm_package_version%.zip --notes-file release_notes.md --generate-notes", "publish": "pnpm run build && pnpm run pack && pnpm run release", diff --git a/scripts/pack.js b/scripts/pack.js index eadf3b0..6371c40 100644 --- a/scripts/pack.js +++ b/scripts/pack.js @@ -1,22 +1,22 @@ import AdmZip from "adm-zip"; import { existsSync, mkdirSync, readFileSync } from "fs"; -import { dirname, parse, resolve } from "path"; +import { resolve } from "path"; try { - const __dirname = resolve(dirname("")); - const { base } = parse(__dirname); - const { version, version_name } = JSON.parse(readFileSync(resolve(__dirname, "dist", "manifest.json"), "utf8")); + const { version, version_name } = JSON.parse(readFileSync(resolve("dist", "manifest.json"), "utf8")); + + const name = "redmine-time-tracking"; + const outDir = "release"; + const filename = `${name}-v${version_name || version}.zip`; - const outdir = "release"; - const filename = `${base}-v${version_name || version}.zip`; const zip = new AdmZip(); zip.addLocalFolder("dist"); - if (!existsSync(outdir)) { - mkdirSync(outdir); + if (!existsSync(outDir)) { + mkdirSync(outDir); } - zip.writeZip(`${outdir}/${filename}`); + zip.writeZip(`${outDir}/${filename}`); - console.log(`Success! Created a ${filename} file under ${outdir} directory. You can upload this file to web store.`); + console.log(`Success! Created a ${filename} file under ${outDir} directory. You can upload this file to web store.`); } catch (e) { console.log(e); console.error("Error! Failed to generate a zip file."); diff --git a/scripts/updateVersion.js b/scripts/updateVersion.js new file mode 100644 index 0000000..8013bf0 --- /dev/null +++ b/scripts/updateVersion.js @@ -0,0 +1,17 @@ +import { readFileSync, writeFileSync } from "fs"; +import { resolve } from "path"; + +try { + const packageJsonContent = JSON.parse(readFileSync(resolve("package.json"), "utf8")); + + const manifestPath = resolve("public", "manifest.json"); + const manifestContent = JSON.parse(readFileSync(manifestPath, "utf8")); + + manifestContent.version = packageJsonContent.version; + + writeFileSync(manifestPath, JSON.stringify(manifestContent, null, 4)); + + console.log("Success! Version in manifest.json updated."); +} catch (error) { + console.error("Error! Failed to update manifest.json:", error); +}