Repository navigation
Expand file tree
/
Copy pathpublish-version.mjs
More file actions
97 lines (76 loc) · 3.81 KB
/
Copy pathpublish-version.mjs
File metadata and controls
97 lines (76 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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();
const packages = ['extensions/*', 'platform/*', 'modes/*'];
// Track only the release's version files (the ones this script writes, plus
// version.txt), 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 = [];
// 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'));
// Bump only the package's own version. Internal @ohif/* references stay
// as workspace:* in the committed manifests (and therefore the lockfile,
// which records them as links), so pnpm-lock.yaml never drifts on a
// version bump and frozen installs keep working. pnpm publish rewrites
// workspace:* to the exact version in the published tarball only.
packageJson.version = nextVersion;
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
updatedFiles.push(packageJsonPath);
console.log(`Updated ${packageJsonPath}`);
} catch (err) {
console.log("ERROR: Couldn't find package.json in", packageDirectory);
continue;
}
}
}
// 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');
// version.txt holds the version version.mjs computed for this release. The
// viewer build reads it as its version (process.env.VERSION_NUMBER, shown in
// the About dialog), so commit it with the package.json files: a build from
// the release tag, or from a checkout, then reports the version it was
// tagged with.
updatedFiles.push('version.txt');
// 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 version files tracked above, 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
const tagName = `v${nextVersion}`;
await execa('git', ['tag', '-f', tagName]);
console.log('Pushing changes...');
await execa('git', ['push', 'origin', branchName]);
console.log('Pushing tag...');
await execa('git', ['push', 'origin', tagName]);
console.log('Version set successfully');
}
run().catch(err => {
console.error('Error encountered during version bump:', err);
process.exit(1);
});