Files
ohif-viewer/publish-version.mjs
T

103 lines
3.6 KiB
JavaScript
Raw Normal View History

import { execa } from 'execa';
import fs from 'fs/promises';
import glob from 'glob';
import path from 'path';
async function run() {
const { stdout: branchName } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
console.log('Current branch:', branchName);
// read the current version from ./version.txt
const nextVersion = (await fs.readFile('./version.txt', 'utf-8')).trim();
2026-06-12 16:04:56 -04:00
const packages = ['extensions/*', 'platform/*', 'modes/*'];
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 = [];
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
for (const packagePathPattern of packages) {
const matchingDirectories = glob.sync(packagePathPattern);
for (const packageDirectory of matchingDirectories) {
const packageJsonPath = path.join(packageDirectory, 'package.json');
try {
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
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;
}
}
}
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
2026-06-12 16:04:56 -04:00
updatedFiles.push(packageJsonPath);
console.log(`Updated ${packageJsonPath}`);
} catch (err) {
console.log("ERROR: Couldn't find package.json in", packageDirectory);
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]);
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');
}
run().catch(err => {
console.error('Error encountered during version bump:', err);
process.exit(1);
});