Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "turbo run lint",
"test": "turbo run test",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"bump-version": "npx tsx scripts/bump-version.ts",
"publish-all": "pnpm --filter \"./packages/**\" -r publish --tag next",
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --tag next --force --registry https://preview.registry.zenstack.dev/",
"unpublish-preview": "pnpm --filter \"./packages/**\" -r --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ \"\\$PNPM_PACKAGE_NAME\""
Expand Down
56 changes: 31 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions scripts/bump-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as fs from 'node:fs';
import { glob } from 'glob';
import * as path from 'node:path';
import * as yaml from 'yaml';

function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
const workspaceYaml = fs.readFileSync(workspaceFile, 'utf8');
const workspace = yaml.parse(workspaceYaml) as { packages?: string[] };
if (!workspace.packages) throw new Error('No "packages" key found in pnpm-workspace.yaml');
const rootDir = path.dirname(workspaceFile);
const files = new Set<string>();
for (const pattern of workspace.packages) {
const matches = glob.sync(path.join(pattern, 'package.json'), {
cwd: rootDir,
absolute: true,
});
matches.forEach((f) => files.add(f));
}
return Array.from(files);
}

function incrementVersion(version: string): string {
const parts = version.split('.');
const last = parts.length - 1;
const lastNum = parseInt(parts[last], 10);
if (isNaN(lastNum)) throw new Error(`Invalid version: ${version}`);
parts[last] = (lastNum + 1).toString();
return parts.join('.');
}

const workspaceFile = path.resolve(__dirname, '../pnpm-workspace.yaml');
const packageFiles = getWorkspacePackageJsonFiles(workspaceFile);

for (const file of packageFiles) {
const content = fs.readFileSync(file, 'utf8');
const pkg = JSON.parse(content) as { version?: string };
if (pkg.version) {
const oldVersion = pkg.version;
pkg.version = incrementVersion(pkg.version);
fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
console.log(`Updated ${file}: ${oldVersion} -> ${pkg.version}`);
}
}
Loading