Skip to content

Commit

Permalink
Add "Update versions" script
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotes committed Nov 13, 2024
1 parent 5fe1232 commit dd40c1c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
5 changes: 3 additions & 2 deletions examples/lox/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 4 additions & 3 deletions examples/ox/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/typir-langium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/typir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions scripts/update-versions.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit dd40c1c

Please sign in to comment.