2023-06-06 14:15:36 -04:00
|
|
|
import { execa } from 'execa';
|
|
|
|
|
import fs from 'fs/promises';
|
|
|
|
|
import glob from 'glob';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
|
|
async function run() {
|
2023-09-01 16:19:39 -04:00
|
|
|
const { stdout: branchName } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
|
2023-06-06 14:15:36 -04:00
|
|
|
console.log('Current branch:', branchName);
|
|
|
|
|
|
|
|
|
|
// read the current version from ./version.txt
|
2026-02-10 11:56:52 -05:00
|
|
|
const nextVersion = (await fs.readFile('./version.txt', 'utf-8')).trim();
|
2026-06-12 16:04:56 -04:00
|
|
|
const packages = ['extensions/*', 'platform/*', 'modes/*'];
|
2023-06-06 14:15:36 -04:00
|
|
|
|
2026-06-12 16:04:56 -04:00
|
|
|
// Track only the files this script writes, so the release commit stages
|
|
|
|
|
// exactly the version bump and never sweeps in unrelated local edits or
|
|
|
|
|
// generated artifacts via `git add -A`.
|
|
|
|
|
const updatedFiles = [];
|
2023-06-06 14:15:36 -04:00
|
|
|
|
2026-06-12 16:04:56 -04:00
|
|
|
// For each package's package.json file, update:
|
|
|
|
|
// 1. The package version
|
|
|
|
|
// 2. Any @ohif/* peerDependencies to the next version
|
|
|
|
|
// 3. Any @ohif/* dependencies to the next version
|
2023-06-06 14:15:36 -04:00
|
|
|
|
|
|
|
|
for (const packagePathPattern of packages) {
|
|
|
|
|
const matchingDirectories = glob.sync(packagePathPattern);
|
|
|
|
|
|
|
|
|
|
for (const packageDirectory of matchingDirectories) {
|
|
|
|
|
const packageJsonPath = path.join(packageDirectory, 'package.json');
|
|
|
|
|
|
|
|
|
|
try {
|
2023-09-01 16:19:39 -04:00
|
|
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
|
2023-06-06 14:15:36 -04:00
|
|
|
|
2026-06-12 16:04:56 -04:00
|
|
|
// Update the package version
|
|
|
|
|
packageJson.version = nextVersion;
|
|
|
|
|
|
|
|
|
|
// Update peerDependencies
|
|
|
|
|
if (packageJson.peerDependencies) {
|
|
|
|
|
for (const dep of Object.keys(packageJson.peerDependencies)) {
|
|
|
|
|
if (dep.startsWith('@ohif/')) {
|
|
|
|
|
packageJson.peerDependencies[dep] = nextVersion;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update dependencies
|
|
|
|
|
if (packageJson.dependencies) {
|
|
|
|
|
for (const dep of Object.keys(packageJson.dependencies)) {
|
|
|
|
|
if (dep.startsWith('@ohif/')) {
|
|
|
|
|
packageJson.dependencies[dep] = nextVersion;
|
|
|
|
|
}
|
2023-06-06 14:15:36 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-01 16:19:39 -04:00
|
|
|
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
2026-06-12 16:04:56 -04:00
|
|
|
updatedFiles.push(packageJsonPath);
|
2023-06-06 14:15:36 -04:00
|
|
|
|
|
|
|
|
console.log(`Updated ${packageJsonPath}`);
|
|
|
|
|
} catch (err) {
|
2023-09-29 10:35:30 -04:00
|
|
|
console.log("ERROR: Couldn't find package.json in", packageDirectory);
|
2023-06-06 14:15:36 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-12 16:04:56 -04:00
|
|
|
// Update root package.json version
|
|
|
|
|
const rootPackageJson = JSON.parse(await fs.readFile('package.json', 'utf-8'));
|
|
|
|
|
rootPackageJson.version = nextVersion;
|
|
|
|
|
await fs.writeFile('package.json', JSON.stringify(rootPackageJson, null, 2) + '\n');
|
|
|
|
|
updatedFiles.push('package.json');
|
|
|
|
|
console.log('Updated root package.json');
|
|
|
|
|
|
|
|
|
|
// NOTE: Do not delete .npmrc here. It is tracked and holds pnpm workspace
|
|
|
|
|
// config (node-linker, workspace linking) with no npm credentials, so
|
|
|
|
|
// removing it would commit the loss of needed install config. This script
|
|
|
|
|
// does not publish, so there is no accidental-publish risk to guard against.
|
|
|
|
|
|
|
|
|
|
console.log('Setting the version...');
|
|
|
|
|
|
|
|
|
|
// Stage only the package.json files this script updated, so the release
|
|
|
|
|
// commit is deterministic and doesn't pick up unrelated worktree changes.
|
|
|
|
|
await execa('git', ['add', '--', ...updatedFiles]);
|
|
|
|
|
|
|
|
|
|
// Create the version commit
|
|
|
|
|
const commitMessage = `chore(version): Update package versions to ${nextVersion} [skip ci]`;
|
|
|
|
|
await execa('git', ['commit', '-m', commitMessage]);
|
|
|
|
|
|
|
|
|
|
// Create the version tag
|
2026-02-11 09:20:14 -05:00
|
|
|
const tagName = `v${nextVersion}`;
|
|
|
|
|
await execa('git', ['tag', '-f', tagName]);
|
|
|
|
|
|
2026-02-10 11:56:52 -05:00
|
|
|
console.log('Pushing changes...');
|
|
|
|
|
await execa('git', ['push', 'origin', branchName]);
|
|
|
|
|
|
2026-02-11 09:20:14 -05:00
|
|
|
console.log('Pushing tag...');
|
|
|
|
|
await execa('git', ['push', 'origin', tagName]);
|
|
|
|
|
|
2026-06-12 16:04:56 -04:00
|
|
|
console.log('Version set successfully');
|
2023-06-06 14:15:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run().catch(err => {
|
|
|
|
|
console.error('Error encountered during version bump:', err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|