From f16fb69c57fb50d7210f933d25135ca003e7e25e Mon Sep 17 00:00:00 2001 From: aidenlx Date: Sat, 22 Jan 2022 17:40:01 +0800 Subject: [PATCH] build: fix compatability with non-POSIX environment now use node script for version bump instead of shell command --- .eslintrc | 1 + package.json | 3 +-- version-bump.mjs | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 version-bump.mjs diff --git a/.eslintrc b/.eslintrc index 60224a4..0807290 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,7 @@ { "root": true, "parser": "@typescript-eslint/parser", + "env": { "node": true }, "plugins": [ "@typescript-eslint" ], diff --git a/package.json b/package.json index 1271d9c..203d7c0 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "node esbuild.config.mjs", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "json -I -f manifest.json -e \"this.version='$npm_package_version'\" && json -I -f versions.json -e \"this['$npm_package_version']='$(cat manifest.json | json minAppVersion)'\" && git add ." + "version": "node version-bump.mjs" }, "keywords": [], "author": "", @@ -17,7 +17,6 @@ "@typescript-eslint/parser": "^5.2.0", "builtin-modules": "^3.2.0", "esbuild": "0.13.12", - "json": "^11.0.0", "obsidian": "^0.12.17", "tslib": "2.3.1", "typescript": "4.4.4" diff --git a/version-bump.mjs b/version-bump.mjs new file mode 100644 index 0000000..14f8134 --- /dev/null +++ b/version-bump.mjs @@ -0,0 +1,25 @@ +import { readFile as readFile0, writeFile as writeFile0 } from "fs"; +import { exec as exec0 } from "child_process"; +import { promisify } from "util"; + +const exec = promisify(exec0), + readFile = promisify(readFile0), + writeFile = promisify(writeFile0); + +const targetVersion = process.env.npm_package_version; + +(async () => { + // read minAppVersion from manifest.json and bump version to target version + let menifest = JSON.parse((await readFile("manifest.json")).toString()); + const { minAppVersion } = menifest; + menifest.version = targetVersion; + await writeFile("manifest.json", JSON.stringify(menifest, null, 2)); + + // update versions.json with target version and minAppVersion from manifest.json + let versions = JSON.parse((await readFile("versions.json")).toString()); + versions[targetVersion] = minAppVersion; + await writeFile("versions.json", JSON.stringify(versions, null, 2)); + + // save changes in git + await exec("git add manifest.json versions.json"); +})().catch(() => process.exit(1));