Skip to content

Commit dc73b18

Browse files
jboccesedghi
andauthored
fix(cli): various fixes for adding custom modes and extensions (OHIF#3683)
Co-authored-by: Alireza <[email protected]>
1 parent 52da92f commit dc73b18

File tree

11 files changed

+60
-245
lines changed

11 files changed

+60
-245
lines changed

extensions/_example/src/index.js

-134
This file was deleted.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868
"@babel/plugin-proposal-class-properties": "^7.16.7",
6969
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
7070
"@babel/plugin-proposal-private-methods": "^7.18.6",
71+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
7172
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
7273
"@babel/plugin-transform-arrow-functions": "^7.16.7",
7374
"@babel/plugin-transform-regenerator": "^7.16.7",
7475
"@babel/plugin-transform-runtime": "^7.17.0",
7576
"@babel/plugin-transform-typescript": "^7.13.0",
7677
"@babel/preset-env": "^7.16.11",
77-
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
7878
"@babel/preset-react": "^7.16.7",
7979
"@babel/preset-typescript": "^7.13.0",
8080
"@types/jest": "^27.5.0",
@@ -88,13 +88,13 @@
8888
"clean-webpack-plugin": "^3.0.0",
8989
"copy-webpack-plugin": "^9.0.1",
9090
"cross-env": "^5.2.0",
91-
"css-loader": "^3.2.0",
91+
"css-loader": "^6.8.1",
9292
"dotenv": "^8.1.0",
9393
"eslint": "^7.32.0",
9494
"eslint-config-prettier": "^7.2.0",
9595
"eslint-config-react-app": "^6.0.0",
96-
"eslint-plugin-flowtype": "^7.0.0",
9796
"eslint-plugin-cypress": "^2.12.1",
97+
"eslint-plugin-flowtype": "^7.0.0",
9898
"eslint-plugin-import": "^2.26.0",
9999
"eslint-plugin-jsx-a11y": "^6.5.1",
100100
"eslint-plugin-node": "^11.1.0",
@@ -109,8 +109,8 @@
109109
"html-webpack-plugin": "^5.3.2",
110110
"husky": "^3.0.0",
111111
"jest": "^29.5.0",
112-
"jest-environment-jsdom": "^29.5.0",
113112
"jest-canvas-mock": "^2.1.0",
113+
"jest-environment-jsdom": "^29.5.0",
114114
"jest-junit": "^6.4.0",
115115
"lerna": "^7.2.0",
116116
"lint-staged": "^9.0.2",

platform/cli/src/commands/linkPackage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function linkPackage(packageDir, options, addToConfig, keyword) {
4848
const newLine = `path.resolve(__dirname, '${packageNodeModules}'),`;
4949
const modifiedFileContent = fileContent.replace(
5050
/(modules:\s*\[)([\s\S]*?)(\])/,
51-
`$1$2 ${newLine}$3`
51+
`$1$2 ${newLine.replace(/\\/g, '/')}$3`
5252
);
5353

5454
await fs.promises.writeFile(webpackConfigPath, modifiedFileContent);

platform/cli/src/commands/utils/editPackageJson.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import path from 'path';
44
async function editPackageJson(options) {
55
const { name, version, description, author, license, targetDir } = options;
66

7+
const ohifVersion = fs.readFileSync('./version.txt', 'utf8');
8+
79
// read package.json from targetDir
810
const dependenciesPath = path.join(targetDir, 'dependencies.json');
911
const rawData = fs.readFileSync(dependenciesPath, 'utf8');
10-
const packageJson = JSON.parse(rawData);
12+
13+
const dataWithOHIFVersion = rawData.replace(/\{LATEST_OHIF_VERSION\}/g, ohifVersion);
14+
const packageJson = JSON.parse(dataWithOHIFVersion);
1115

1216
// edit package.json
1317
const mergedObj = Object.assign(

platform/cli/templates/extension/dependencies.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@babel/preset-env": "^7.16.11",
4545
"@babel/preset-react": "^7.16.7",
4646
"@babel/preset-typescript": "^7.13.0",
47+
"@babel/plugin-proposal-private-property-in-object":"7.21.11",
4748
"babel-eslint": "9.x",
4849
"babel-loader": "^8.2.4",
4950
"babel-plugin-inline-react-svg": "^2.0.2",

platform/cli/templates/mode/dependencies.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
"test:unit:ci": "jest --ci --runInBand --collectCoverage --passWithNoTests"
1818
},
1919
"peerDependencies": {
20-
"@ohif/core": "^3.0.0"
20+
"@ohif/core": "^{LATEST_OHIF_VERSION}"
2121
},
2222
"dependencies": {
23-
"@babel/runtime": "^7.20.13"
23+
"@babel/runtime": "^7.20.13",
24+
"@ohif/mode-longitudinal": "^{LATEST_OHIF_VERSION}"
2425
},
2526
"devDependencies": {
2627
"@babel/core": "^7.21.4",

platform/docs/docs/development/architecture.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ you'll see the following:
2424
```bash
2525
2626
├── extensions
27-
│ ├── _example # Skeleton of example extension
2827
│ ├── default # default functionalities
2928
│ ├── cornerstone # 2D/3D images w/ Cornerstonejs
3029
│ ├── cornerstone-dicom-sr # Structured reports
3130
│ ├── measurement-tracking # measurement tracking
3231
│ └── dicom-pdf # View DICOM wrapped PDFs in viewport
32+
| # and many more ...
3333
3434
├── modes
3535
│ └── longitudinal # longitudinal measurement tracking mode
3636
| └── basic-dev-mode # basic viewer with Cornerstone (a developer focused mode)
37+
| # and many more
3738
3839
├── platform
3940
│ ├── core # Business Logic

publish-package.mjs

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,29 @@ async function run() {
1616
const rootDir = process.cwd();
1717

1818
for (const packagePathPattern of packages) {
19-
const matchingDirectories = glob.sync(packagePathPattern);
19+
const matchingDirectories = glob.sync(packagePathPattern, { cwd: rootDir });
2020

2121
for (const packageDirectory of matchingDirectories) {
22-
// change back to the root directory
23-
process.chdir(rootDir);
22+
try {
23+
// change back to the root directory
24+
process.chdir(rootDir);
2425

25-
const packageJsonPath = path.join(packageDirectory, 'package.json');
26+
const packageJsonPath = path.join(packageDirectory, 'package.json');
2627

27-
try {
2828
const packageJsonContent = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
2929

3030
if (packageJsonContent.private) {
3131
console.log(`Skipping private package at ${packageDirectory}`);
3232
continue;
3333
}
3434

35+
// move to package directory
3536
process.chdir(packageDirectory);
3637

3738
let retries = 0;
3839
while (retries < MAX_RETRIES) {
3940
try {
41+
console.log(`Tying to publishing package at ${packageDirectory}`);
4042
const publishArgs = ['publish'];
4143

4244
if (branchName === 'master') {
@@ -56,6 +58,8 @@ async function run() {
5658
}
5759
} catch (error) {
5860
console.error(`An error occurred while processing ${packageDirectory}: ${error}`);
61+
} finally {
62+
process.chdir(rootDir); // Ensure we always move back to the root directory
5963
}
6064
}
6165
}

publish-version.mjs

+3-10
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,19 @@ async function run() {
3232
try {
3333
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
3434

35-
if (!packageJson.peerDependencies) {
36-
continue;
37-
}
38-
35+
// lerna will take care of updating the dependencies, but it does not
36+
// update the peerDependencies, so we need to do that manually
3937
for (const peerDependency of Object.keys(packageJson.peerDependencies)) {
4038
if (peerDependency.startsWith('@ohif/')) {
4139
packageJson.peerDependencies[peerDependency] = nextVersion;
42-
43-
console.log(
44-
'updating peerdependency to ',
45-
packageJson.peerDependencies[peerDependency]
46-
);
4740
}
4841
}
4942

5043
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
5144

5245
console.log(`Updated ${packageJsonPath}`);
5346
} catch (err) {
54-
// This could be a directory without a package.json file. Ignore and continue.
47+
console.log("ERROR: Couldn't find package.json in", packageDirectory);
5548
continue;
5649
}
5750
}

version.mjs

+26-9
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,37 @@ async function run() {
2323
console.log('Branch: release');
2424
nextVersion = semver.inc(currentVersion, 'minor');
2525
} else {
26-
console.log('Branch: master/main');
26+
console.log('Branch: master');
2727
const prereleaseComponents = semver.prerelease(currentVersion);
2828
const isBumpBeta = lastCommitMessage.trim().endsWith('[BUMP BETA]');
2929
console.log('isBumpBeta', isBumpBeta);
3030

31-
if (prereleaseComponents && prereleaseComponents.includes('beta') && !isBumpBeta) {
32-
nextVersion = semver.inc(currentVersion, 'prerelease', 'beta');
33-
} else if (isBumpBeta && prereleaseComponents.includes('beta')) {
34-
console.log('Bumping beta version to be fresh beta');
35-
nextVersion = `${semver.major(currentVersion)}.${semver.minor(currentVersion) + 1}.0-beta.0`;
31+
if (prereleaseComponents?.includes('beta')) {
32+
// if the version includes beta
33+
if (isBumpBeta) {
34+
// if the commit message includes [BUMP BETA]
35+
// which means that we should reset to beta 0 for next major version
36+
// e.g., from 2.11.0-beta.11 to 2.12.0-beta.0
37+
console.log(
38+
'Bumping beta version to be fresh beta, e.g., from 2.11.0-beta.11 to 2.12.0-beta.0'
39+
);
40+
nextVersion = `${semver.major(currentVersion)}.${
41+
semver.minor(currentVersion) + 1
42+
}.0-beta.0`;
43+
} else {
44+
// this means that the current version is already a beta version
45+
// and we should bump the beta version to the next beta version
46+
// e.g., from 2.11.0-beta.11 to 2.11.0-beta.12
47+
console.log(
48+
'Bumping beta version to be next beta, e.g., from 2.11.0-beta.11 to 2.11.0-beta.12'
49+
);
50+
nextVersion = semver.inc(currentVersion, 'prerelease', 'beta');
51+
}
3652
} else {
37-
console.log('Bumping minor version for beta release');
38-
const nextMinorVersion = semver.inc(currentVersion, 'minor');
39-
nextVersion = `${semver.major(nextMinorVersion)}.${semver.minor(nextMinorVersion)}.0-beta.0`;
53+
// if the version does not include the beta, might be that a recent merge into the release branch
54+
// that later has been pulled into this PR
55+
console.log('Bumping beta version to be fresh beta e.g., from 2.11.0 to 2.12.0-beta.0');
56+
nextVersion = `${semver.major(currentVersion)}.${semver.minor(currentVersion) + 1}.0-beta.0`;
4057
}
4158
}
4259

0 commit comments

Comments
 (0)