Skip to content

Commit 0f8f756

Browse files
authored
chore: add script for bumping version (#42)
* chore: add script for bumping version * update lock file * update packages
1 parent ca3f902 commit 0f8f756

File tree

6 files changed

+81
-29
lines changed

6 files changed

+81
-29
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "turbo run lint",
1010
"test": "turbo run test",
1111
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
12+
"bump-version": "npx tsx scripts/bump-version.ts",
1213
"publish-all": "pnpm --filter \"./packages/**\" -r publish --tag next",
1314
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --tag next --force --registry https://preview.registry.zenstack.dev/",
1415
"unpublish-preview": "pnpm --filter \"./packages/**\" -r --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ \"\\$PNPM_PACKAGE_NAME\""
@@ -20,13 +21,15 @@
2021
"@eslint/js": "^9.29.0",
2122
"@types/node": "^20.17.24",
2223
"eslint": "~9.29.0",
24+
"glob": "^11.0.2",
2325
"prettier": "^3.5.3",
2426
"tsup": "^8.5.0",
2527
"tsx": "^4.20.3",
2628
"turbo": "^2.5.4",
2729
"typescript": "catalog:",
2830
"typescript-eslint": "^8.34.1",
29-
"vitest": "^3.2.4"
31+
"vitest": "^3.2.4",
32+
"yaml": "^2.8.0"
3033
},
3134
"pnpm": {
3235
"onlyBuiltDependencies": [

packages/language/src/generated/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
* This file was generated by langium-cli 3.3.0.
2+
* This file was generated by langium-cli 3.3.1.
33
* DO NOT EDIT MANUALLY!
44
******************************************************************************/
55

packages/language/src/generated/grammar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
* This file was generated by langium-cli 3.3.0.
2+
* This file was generated by langium-cli 3.3.1.
33
* DO NOT EDIT MANUALLY!
44
******************************************************************************/
55

packages/language/src/generated/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/******************************************************************************
2-
* This file was generated by langium-cli 3.3.0.
2+
* This file was generated by langium-cli 3.3.1.
33
* DO NOT EDIT MANUALLY!
44
******************************************************************************/
55

pnpm-lock.yaml

Lines changed: 31 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/bump-version.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as fs from 'node:fs';
2+
import { glob } from 'glob';
3+
import * as path from 'node:path';
4+
import * as yaml from 'yaml';
5+
6+
function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
7+
const workspaceYaml = fs.readFileSync(workspaceFile, 'utf8');
8+
const workspace = yaml.parse(workspaceYaml) as { packages?: string[] };
9+
if (!workspace.packages) throw new Error('No "packages" key found in pnpm-workspace.yaml');
10+
const rootDir = path.dirname(workspaceFile);
11+
const files = new Set<string>();
12+
for (const pattern of workspace.packages) {
13+
const matches = glob.sync(path.join(pattern, 'package.json'), {
14+
cwd: rootDir,
15+
absolute: true,
16+
});
17+
matches.forEach((f) => files.add(f));
18+
}
19+
return Array.from(files);
20+
}
21+
22+
function incrementVersion(version: string): string {
23+
const parts = version.split('.');
24+
const last = parts.length - 1;
25+
const lastNum = parseInt(parts[last], 10);
26+
if (isNaN(lastNum)) throw new Error(`Invalid version: ${version}`);
27+
parts[last] = (lastNum + 1).toString();
28+
return parts.join('.');
29+
}
30+
31+
const workspaceFile = path.resolve(__dirname, '../pnpm-workspace.yaml');
32+
const packageFiles = getWorkspacePackageJsonFiles(workspaceFile);
33+
34+
for (const file of packageFiles) {
35+
const content = fs.readFileSync(file, 'utf8');
36+
const pkg = JSON.parse(content) as { version?: string };
37+
if (pkg.version) {
38+
const oldVersion = pkg.version;
39+
pkg.version = incrementVersion(pkg.version);
40+
fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
41+
console.log(`Updated ${file}: ${oldVersion} -> ${pkg.version}`);
42+
}
43+
}

0 commit comments

Comments
 (0)