Skip to content

Commit

Permalink
fix(cli): various fixes for adding custom modes and extensions (#3683)
Browse files Browse the repository at this point in the history
Co-authored-by: Alireza <ar.sedghi@gmail.com>
  • Loading branch information
jbocce and sedghi authored Sep 29, 2023
1 parent 52da92f commit dc73b18
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 245 deletions.
134 changes: 0 additions & 134 deletions extensions/_example/src/index.js

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-arrow-functions": "^7.16.7",
"@babel/plugin-transform-regenerator": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/plugin-transform-typescript": "^7.13.0",
"@babel/preset-env": "^7.16.11",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.13.0",
"@types/jest": "^27.5.0",
Expand All @@ -88,13 +88,13 @@
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^5.2.0",
"css-loader": "^3.2.0",
"css-loader": "^6.8.1",
"dotenv": "^8.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^7.0.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-flowtype": "^7.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-node": "^11.1.0",
Expand All @@ -109,8 +109,8 @@
"html-webpack-plugin": "^5.3.2",
"husky": "^3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-canvas-mock": "^2.1.0",
"jest-environment-jsdom": "^29.5.0",
"jest-junit": "^6.4.0",
"lerna": "^7.2.0",
"lint-staged": "^9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion platform/cli/src/commands/linkPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function linkPackage(packageDir, options, addToConfig, keyword) {
const newLine = `path.resolve(__dirname, '${packageNodeModules}'),`;
const modifiedFileContent = fileContent.replace(
/(modules:\s*\[)([\s\S]*?)(\])/,
`$1$2 ${newLine}$3`
`$1$2 ${newLine.replace(/\\/g, '/')}$3`
);

await fs.promises.writeFile(webpackConfigPath, modifiedFileContent);
Expand Down
6 changes: 5 additions & 1 deletion platform/cli/src/commands/utils/editPackageJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import path from 'path';
async function editPackageJson(options) {
const { name, version, description, author, license, targetDir } = options;

const ohifVersion = fs.readFileSync('./version.txt', 'utf8');

// read package.json from targetDir
const dependenciesPath = path.join(targetDir, 'dependencies.json');
const rawData = fs.readFileSync(dependenciesPath, 'utf8');
const packageJson = JSON.parse(rawData);

const dataWithOHIFVersion = rawData.replace(/\{LATEST_OHIF_VERSION\}/g, ohifVersion);
const packageJson = JSON.parse(dataWithOHIFVersion);

// edit package.json
const mergedObj = Object.assign(
Expand Down
1 change: 1 addition & 0 deletions platform/cli/templates/extension/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.13.0",
"@babel/plugin-proposal-private-property-in-object":"7.21.11",
"babel-eslint": "9.x",
"babel-loader": "^8.2.4",
"babel-plugin-inline-react-svg": "^2.0.2",
Expand Down
5 changes: 3 additions & 2 deletions platform/cli/templates/mode/dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"test:unit:ci": "jest --ci --runInBand --collectCoverage --passWithNoTests"
},
"peerDependencies": {
"@ohif/core": "^3.0.0"
"@ohif/core": "^{LATEST_OHIF_VERSION}"
},
"dependencies": {
"@babel/runtime": "^7.20.13"
"@babel/runtime": "^7.20.13",
"@ohif/mode-longitudinal": "^{LATEST_OHIF_VERSION}"
},
"devDependencies": {
"@babel/core": "^7.21.4",
Expand Down
3 changes: 2 additions & 1 deletion platform/docs/docs/development/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ you'll see the following:
```bash
├── extensions
│ ├── _example # Skeleton of example extension
│ ├── default # default functionalities
│ ├── cornerstone # 2D/3D images w/ Cornerstonejs
│ ├── cornerstone-dicom-sr # Structured reports
│ ├── measurement-tracking # measurement tracking
│ └── dicom-pdf # View DICOM wrapped PDFs in viewport
| # and many more ...
├── modes
│ └── longitudinal # longitudinal measurement tracking mode
| └── basic-dev-mode # basic viewer with Cornerstone (a developer focused mode)
| # and many more
├── platform
│ ├── core # Business Logic
Expand Down
14 changes: 9 additions & 5 deletions publish-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,29 @@ async function run() {
const rootDir = process.cwd();

for (const packagePathPattern of packages) {
const matchingDirectories = glob.sync(packagePathPattern);
const matchingDirectories = glob.sync(packagePathPattern, { cwd: rootDir });

for (const packageDirectory of matchingDirectories) {
// change back to the root directory
process.chdir(rootDir);
try {
// change back to the root directory
process.chdir(rootDir);

const packageJsonPath = path.join(packageDirectory, 'package.json');
const packageJsonPath = path.join(packageDirectory, 'package.json');

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

if (packageJsonContent.private) {
console.log(`Skipping private package at ${packageDirectory}`);
continue;
}

// move to package directory
process.chdir(packageDirectory);

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

if (branchName === 'master') {
Expand All @@ -56,6 +58,8 @@ async function run() {
}
} catch (error) {
console.error(`An error occurred while processing ${packageDirectory}: ${error}`);
} finally {
process.chdir(rootDir); // Ensure we always move back to the root directory
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions publish-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,19 @@ async function run() {
try {
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));

if (!packageJson.peerDependencies) {
continue;
}

// lerna will take care of updating the dependencies, but it does not
// update the peerDependencies, so we need to do that manually
for (const peerDependency of Object.keys(packageJson.peerDependencies)) {
if (peerDependency.startsWith('@ohif/')) {
packageJson.peerDependencies[peerDependency] = nextVersion;

console.log(
'updating peerdependency to ',
packageJson.peerDependencies[peerDependency]
);
}
}

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

console.log(`Updated ${packageJsonPath}`);
} catch (err) {
// This could be a directory without a package.json file. Ignore and continue.
console.log("ERROR: Couldn't find package.json in", packageDirectory);
continue;
}
}
Expand Down
35 changes: 26 additions & 9 deletions version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,37 @@ async function run() {
console.log('Branch: release');
nextVersion = semver.inc(currentVersion, 'minor');
} else {
console.log('Branch: master/main');
console.log('Branch: master');
const prereleaseComponents = semver.prerelease(currentVersion);
const isBumpBeta = lastCommitMessage.trim().endsWith('[BUMP BETA]');
console.log('isBumpBeta', isBumpBeta);

if (prereleaseComponents && prereleaseComponents.includes('beta') && !isBumpBeta) {
nextVersion = semver.inc(currentVersion, 'prerelease', 'beta');
} else if (isBumpBeta && prereleaseComponents.includes('beta')) {
console.log('Bumping beta version to be fresh beta');
nextVersion = `${semver.major(currentVersion)}.${semver.minor(currentVersion) + 1}.0-beta.0`;
if (prereleaseComponents?.includes('beta')) {
// if the version includes beta
if (isBumpBeta) {
// if the commit message includes [BUMP BETA]
// which means that we should reset to beta 0 for next major version
// e.g., from 2.11.0-beta.11 to 2.12.0-beta.0
console.log(
'Bumping beta version to be fresh beta, e.g., from 2.11.0-beta.11 to 2.12.0-beta.0'
);
nextVersion = `${semver.major(currentVersion)}.${
semver.minor(currentVersion) + 1
}.0-beta.0`;
} else {
// this means that the current version is already a beta version
// and we should bump the beta version to the next beta version
// e.g., from 2.11.0-beta.11 to 2.11.0-beta.12
console.log(
'Bumping beta version to be next beta, e.g., from 2.11.0-beta.11 to 2.11.0-beta.12'
);
nextVersion = semver.inc(currentVersion, 'prerelease', 'beta');
}
} else {
console.log('Bumping minor version for beta release');
const nextMinorVersion = semver.inc(currentVersion, 'minor');
nextVersion = `${semver.major(nextMinorVersion)}.${semver.minor(nextMinorVersion)}.0-beta.0`;
// if the version does not include the beta, might be that a recent merge into the release branch
// that later has been pulled into this PR
console.log('Bumping beta version to be fresh beta e.g., from 2.11.0 to 2.12.0-beta.0');
nextVersion = `${semver.major(currentVersion)}.${semver.minor(currentVersion) + 1}.0-beta.0`;
}
}

Expand Down
Loading

0 comments on commit dc73b18

Please sign in to comment.