build: fix compatability with non-POSIX environment

now use node script for version bump instead of shell command
This commit is contained in:
aidenlx 2022-01-22 17:40:01 +08:00
parent 750e319a92
commit f16fb69c57
3 changed files with 27 additions and 2 deletions

View File

@ -1,6 +1,7 @@
{ {
"root": true, "root": true,
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": [ "plugins": [
"@typescript-eslint" "@typescript-eslint"
], ],

View File

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "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": [], "keywords": [],
"author": "", "author": "",
@ -17,7 +17,6 @@
"@typescript-eslint/parser": "^5.2.0", "@typescript-eslint/parser": "^5.2.0",
"builtin-modules": "^3.2.0", "builtin-modules": "^3.2.0",
"esbuild": "0.13.12", "esbuild": "0.13.12",
"json": "^11.0.0",
"obsidian": "^0.12.17", "obsidian": "^0.12.17",
"tslib": "2.3.1", "tslib": "2.3.1",
"typescript": "4.4.4" "typescript": "4.4.4"

25
version-bump.mjs Normal file
View File

@ -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));