Skip to content

Commit

Permalink
feat: Add update manifest.json version script
Browse files Browse the repository at this point in the history
  • Loading branch information
CrawlerCode committed Feb 9, 2024
1 parent 037aa99 commit 98d81b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions scripts/pack.js
Original file line number Diff line number Diff line change
@@ -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.");
Expand Down
17 changes: 17 additions & 0 deletions scripts/updateVersion.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 98d81b4

Please sign in to comment.