From dd40c1c262a5814e304cc6596fcd912ff79b7065 Mon Sep 17 00:00:00 2001 From: Markus Rudolph Date: Wed, 13 Nov 2024 14:57:52 +0100 Subject: [PATCH] Add "Update versions" script --- examples/lox/package.json | 5 +++-- examples/ox/package.json | 7 ++++--- package.json | 4 +--- packages/typir-langium/package.json | 4 +++- packages/typir/package.json | 4 +++- scripts/update-versions.js | 29 +++++++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 scripts/update-versions.js diff --git a/examples/lox/package.json b/examples/lox/package.json index e377add..5951b6b 100644 --- a/examples/lox/package.json +++ b/examples/lox/package.json @@ -1,8 +1,9 @@ { - "name": "lox", + "name": "typir-example-lox", "displayName": "lox", "version": "0.0.1", - "description": "Please enter a brief description here", + "private": true, + "description": "", "author": { "name": "TypeFox", "url": "https://www.typefox.io" diff --git a/examples/ox/package.json b/examples/ox/package.json index 9470ba6..401af24 100644 --- a/examples/ox/package.json +++ b/examples/ox/package.json @@ -1,8 +1,9 @@ { - "name": "ox", - "displayName": "Ox", + "name": "typir-example-ox", + "displayName": "ox", "version": "0.0.1", - "description": "Please enter a brief description here", + "private": true, + "description": "", "author": { "name": "TypeFox", "url": "https://www.typefox.io" diff --git a/package.json b/package.json index a21eab1..49380a2 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,7 @@ "langium:generate": "npm run langium:generate --workspace=examples/ox --workspace=examples/lox", "langium:watch": "npm run langium:watch --workspace=examples/ox --workspace=examples/lox", "vscode:prepublish": "npm run build && npm run lint", - "reset:repo": "git clean -f -X -d", - "publish:next": "npm --no-git-tag-version version \"$(semver $npm_package_version -i minor)-next.$(git rev-parse --short HEAD)\" && npm publish --tag next", - "publish:latest": "npm publish --tag latest --access public" + "reset:repo": "git clean -f -X -d" }, "devDependencies": { "@types/node": "~18.19.55", diff --git a/packages/typir-langium/package.json b/packages/typir-langium/package.json index 0e0c5f8..c9a81fd 100644 --- a/packages/typir-langium/package.json +++ b/packages/typir-langium/package.json @@ -41,7 +41,9 @@ "clean": "shx rm -rf lib out coverage", "build": "tsc", "watch": "tsc --watch", - "lint": "eslint src test --ext .ts" + "lint": "eslint src test --ext .ts", + "publish:next": "npm --no-git-tag-version version \"$(semver $npm_package_version -i minor)-next.$(git rev-parse --short HEAD)\" && npm publish --tag next", + "publish:latest": "npm publish --tag latest --access public" }, "repository": { "type": "git", diff --git a/packages/typir/package.json b/packages/typir/package.json index 18d10e4..cb5fcf4 100644 --- a/packages/typir/package.json +++ b/packages/typir/package.json @@ -41,7 +41,9 @@ "clean": "shx rm -rf lib out coverage", "build": "tsc", "watch": "tsc --watch", - "lint": "eslint src test --ext .ts" + "lint": "eslint src test --ext .ts", + "publish:next": "npm --no-git-tag-version version \"$(semver $npm_package_version -i minor)-next.$(git rev-parse --short HEAD)\" && npm publish --tag next", + "publish:latest": "npm publish --tag latest --access public" }, "repository": { "type": "git", diff --git a/scripts/update-versions.js b/scripts/update-versions.js new file mode 100644 index 0000000..6955740 --- /dev/null +++ b/scripts/update-versions.js @@ -0,0 +1,29 @@ +const fs = require('fs-extra'); +const path = require('path'); + +async function runUpdate() { + const langiumPath = getPath('typir', true); + const langiumPackage = await fs.readJson(langiumPath); + const version = langiumPackage.version; + await Promise.all([ + replaceAll('typir', true, version), + replaceAll('typir-langium', true, version), + replaceAll('ox', false, version), + replaceAll('lox', false, version), + ]); +} + +async function replaceAll(project, package, version) { + const path = getPath(project, package); + let content = await fs.readFile(path, 'utf-8'); + content = content + .replace(/(?<="typir": "[~\^]?)\d+\.\d+\.\d+/g, version) + .replace(/(?<="typir-langium": "[~\^]?)\d+\.\d+\.\d+/g, version) + await fs.writeFile(path, content); +} + +function getPath(project, package) { + return path.join(package ? 'packages' : 'examples', project, 'package.json'); +} + +runUpdate();