feat(cli): Ohif cli for modes and extensions modification (#2696)
* feat: Add initial cli tool structure * feat: add copying template files * feat: Add mode template and command * feat: Add readme template generation * feat: Add documentation to extension template * feat: Enhance documentation of the template mode * fix: cli module type * feat: Add config-based mode and extension registration (#2660) * feat: Add ohif cli add/remove extension/mode (#2661) * Basic working CLI for add-extension and remove-extension * Basic cli for add/remove extension/mode, lots more to do. * Cleanup and harden] * feat: Add list of tasks to add-mode Co-authored-by: Alireza <ar.sedghi@gmail.com> * feat: Add git initialization for the mode or extension template (#2662) * fix: package json file to include templates * feat: Add git initialization for the mode or extension template * feat: Add more checks of git and target dir * feat: refactore library utilities * feat: Add the list command to print extensions and modes (#2664) * feat: Add the list command to print extensions and modes * Add todo * Feat/ohif cli validation + auto install (#2671) * WIP * Working mode keyword verification * Validation * auto install extensions based on modes * WIP remove unused extensions on removeMove * Working add-mode, remove-mode automatic extension management. * If extension is in used by a mode, don't allow the CLI to uninstall it * Cleanup addExtension * cleanup removeExtension and addMode * Cleanup removeMode * Update existing extensions with the needed keywords/peer deps * Fix broken config * Feat/cli search (#2677) * feat: refactor pretty print for console * feat: add search for modes and extensions * fix: ugly colors * Feat/ohif cli error handling publishing (#2679) * WIP * fix: webpack imports * wip * fix: react router dom private routes * from last commit * wip * fix: webpack prod builds * WIP * Working regsitration with new IDs * Stable Co-authored-by: Alireza <ar.sedghi@gmail.com> * verify extensions when constructing modes. (#2681) * verify extensions when constructing modes. * Add version to unit tests so it conforms to schema * Update ohif utils exposed via @ohif/core * Fix import * fix tests * feat: ohif-cli link local modes/extensions for development (#2682) * feat: enable cli to work with project root * feat: add initial link package * feat: add link and unlink extension * feat: add link and unlink mode * erro handling for link-package * feat: add comment on ohif-cli linking for development (#2686) * Docs/ohif cli (#2687) * feat: Add documentation for templates * feat: Add more documentation * Fix/core publish (#2685) * versions * wip * remove webpack clean output * fix publish * use next as dist tag for v3 for now * fix webpack pro recipe for output * fix: lerna publish next * fix(cli): fix issues when trying to link an extension or a mode (#2725) The generated package.json doesn't contain keywords property which is required by the linkPackage function. The module apth wasn't correclty handled too, and when there is no pluginOptions, it fails while reading the file or while generating a default configuration. * make dicom pdf and video work after cli merge * add axios dependency * comment out the chdir for now * create id and version based on user inputs * customizable path for extension and modes * fix template to make the template mode load * fix the questions to loop if path is not desirable * fix templates * correct package json order * unify the package creation for extension and mode * bump versions for each package * bump extension versions to 3.0 * add gitignore to templates * fix version requirements when ^ * update docs * update docs and fix tests * try to fix the tests * bump node version * remove the version from extensions * remove the version from modes * remove version from extensionManager * fix eslint * revert husky version * fix eslint * fix node version for new eslint * fix documentatoin removing version * fix cicle ci image version * fix circle ci node image * fix circle ci node image * add back the video and pdf Co-authored-by: Matthis Duclos <matthis.duclos@gmail.com> Co-authored-by: James A. Petts <jamesapetts@gmail.com>
This commit is contained in:
181 files changed
+5985
-3689
No files matched your search
+17
-18
@@ -24,13 +24,10 @@ import createRoutes from './routes';
|
||||
import appInit from './appInit.js';
|
||||
import OpenIdConnectRoutes from './utils/OpenIdConnectRoutes.jsx';
|
||||
|
||||
// TODO: Temporarily for testing
|
||||
import '@ohif/mode-longitudinal';
|
||||
|
||||
let commandsManager, extensionManager, servicesManager, hotkeysManager;
|
||||
|
||||
function App({ config, defaultExtensions }) {
|
||||
const init = appInit(config, defaultExtensions);
|
||||
function App({ config, defaultExtensions, defaultModes }) {
|
||||
const init = appInit(config, defaultExtensions, defaultModes);
|
||||
|
||||
// Set above for named export
|
||||
commandsManager = init.commandsManager;
|
||||
@@ -63,27 +60,29 @@ function App({ config, defaultExtensions }) {
|
||||
|
||||
const providers = [
|
||||
[AppConfigProvider, { value: appConfigState }],
|
||||
[UserAuthenticationProvider, { service: UserAuthenticationService}],
|
||||
[UserAuthenticationProvider, { service: UserAuthenticationService }],
|
||||
[I18nextProvider, { i18n }],
|
||||
[ThemeWrapper],
|
||||
[ViewportGridProvider, {service: ViewportGridService}],
|
||||
[ViewportDialogProvider, {service: UIViewportDialogService}],
|
||||
[CineProvider, {service: CineService}],
|
||||
[SnackbarProvider, {service: UINotificationService}],
|
||||
[DialogProvider, {service: UIDialogService}],
|
||||
[ModalProvider, {service: UIModalService, modal: Modal}],
|
||||
]
|
||||
[ViewportGridProvider, { service: ViewportGridService }],
|
||||
[ViewportDialogProvider, { service: UIViewportDialogService }],
|
||||
[CineProvider, { service: CineService }],
|
||||
[SnackbarProvider, { service: UINotificationService }],
|
||||
[DialogProvider, { service: UIDialogService }],
|
||||
[ModalProvider, { service: UIModalService, modal: Modal }],
|
||||
];
|
||||
const CombinedProviders = ({ children }) =>
|
||||
Compose({ components: providers, children });
|
||||
|
||||
let authRoutes = null;
|
||||
|
||||
if (oidc) {
|
||||
authRoutes = (<OpenIdConnectRoutes
|
||||
oidc={oidc}
|
||||
routerBasename={routerBasename}
|
||||
UserAuthenticationService={UserAuthenticationService}
|
||||
/>)
|
||||
authRoutes = (
|
||||
<OpenIdConnectRoutes
|
||||
oidc={oidc}
|
||||
routerBasename={routerBasename}
|
||||
UserAuthenticationService={UserAuthenticationService}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
HangingProtocolService,
|
||||
CineService,
|
||||
UserAuthenticationService,
|
||||
errorHandler
|
||||
errorHandler,
|
||||
// utils,
|
||||
} from '@ohif/core';
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
* @param {object|func} appConfigOrFunc - application configuration, or a function that returns application configuration
|
||||
* @param {object[]} defaultExtensions - array of extension objects
|
||||
*/
|
||||
function appInit(appConfigOrFunc, defaultExtensions) {
|
||||
function appInit(appConfigOrFunc, defaultExtensions, defaultModes) {
|
||||
const appConfig = {
|
||||
...(typeof appConfigOrFunc === 'function'
|
||||
? appConfigOrFunc({ servicesManager })
|
||||
@@ -86,10 +86,18 @@ function appInit(appConfigOrFunc, defaultExtensions) {
|
||||
throw new Error('No modes are defined! Check your app-config.js');
|
||||
}
|
||||
|
||||
// TODO: Remove this
|
||||
if (!appConfig.modes.length) {
|
||||
appConfig.modes.push(window.longitudinalMode);
|
||||
// appConfig.modes.push(window.segmentationMode);
|
||||
for (let i = 0; i < defaultModes.length; i++) {
|
||||
const { modeFactory, id } = defaultModes[i];
|
||||
|
||||
// If the appConfig contains configuration for this mode, use it.
|
||||
const modeConfig =
|
||||
appConfig.modeConfig && appConfig.modeConfig[i]
|
||||
? appConfig.modeConfig[id]
|
||||
: {};
|
||||
|
||||
const mode = modeFactory(modeConfig);
|
||||
|
||||
appConfig.modes.push(mode);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -7,36 +7,24 @@ import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
/**
|
||||
* EXTENSIONS
|
||||
* EXTENSIONS AND MODES
|
||||
* =================
|
||||
* pluginImports.js is dynamically generated from extension and mode
|
||||
* configuration at build time.
|
||||
*
|
||||
* Importing and modifying the extensions our app uses HERE allows us to leverage
|
||||
* tree shaking and a few other niceties. However, by including them here they become
|
||||
* "baked in" to the published application.
|
||||
*
|
||||
* Depending on your use case/needs, you may want to consider not adding any extensions
|
||||
* by default HERE, and instead provide them via the extensions configuration key or
|
||||
* by using the exported `App` component, and passing in your extensions as props using
|
||||
* the defaultExtensions property.
|
||||
* pluginImports.js imports all of the modes and extensions and adds them
|
||||
* to the window for processing.
|
||||
*/
|
||||
import OHIFDefaultExtension from '@ohif/extension-default';
|
||||
import OHIFCornerstoneExtension from '@ohif/extension-cornerstone';
|
||||
import OHIFMeasurementTrackingExtension from '@ohif/extension-measurement-tracking';
|
||||
import OHIFDICOMSRExtension from '@ohif/extension-dicom-sr';
|
||||
import OHIFDICOMVIDEOExtension from '@ohif/extension-dicom-video';
|
||||
import OHIFDICOMPDFExtension from '@ohif/extension-dicom-pdf';
|
||||
import './pluginImports.js';
|
||||
|
||||
/** Combine our appConfiguration and "baked-in" extensions */
|
||||
/**
|
||||
* Combine our appConfiguration with installed extensions and modes.
|
||||
* In the future appConfiguration may contain modes added at runtime.
|
||||
* */
|
||||
const appProps = {
|
||||
config: window ? window.config : {},
|
||||
defaultExtensions: [
|
||||
OHIFDefaultExtension,
|
||||
OHIFCornerstoneExtension,
|
||||
OHIFMeasurementTrackingExtension,
|
||||
OHIFDICOMSRExtension,
|
||||
OHIFDICOMVIDEOExtension,
|
||||
OHIFDICOMPDFExtension,
|
||||
],
|
||||
defaultExtensions: window.extensions,
|
||||
defaultModes: window.modes,
|
||||
};
|
||||
|
||||
/** Create App */
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { useParams, useLocation } from 'react-router';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
// TODO: DicomMetadataStore should be injected?
|
||||
import { DicomMetadataStore } from '@ohif/core';
|
||||
@@ -82,7 +83,6 @@ export default function ModeRoute({
|
||||
const {
|
||||
DisplaySetService,
|
||||
HangingProtocolService,
|
||||
UserAuthenticationService,
|
||||
} = servicesManager.services;
|
||||
|
||||
const { extensions, sopClassHandlers, hotkeys, hangingProtocols } = mode;
|
||||
@@ -100,16 +100,11 @@ export default function ModeRoute({
|
||||
// Only handling one route per mode for now
|
||||
const route = mode.routes[0];
|
||||
|
||||
const layoutTemplateRouteData = route.layoutTemplate({ location });
|
||||
const layoutTemplateModuleEntry = extensionManager.getModuleEntry(
|
||||
layoutTemplateRouteData.id
|
||||
);
|
||||
const LayoutComponent = layoutTemplateModuleEntry.component;
|
||||
|
||||
// For each extension, look up their context modules
|
||||
// TODO: move to extension manager.
|
||||
let contextModules = [];
|
||||
extensions.forEach(extensionId => {
|
||||
|
||||
Object.keys(extensions).forEach(extensionId => {
|
||||
const allRegisteredModuleIds = Object.keys(extensionManager.modulesMap);
|
||||
const moduleIds = allRegisteredModuleIds.filter(id =>
|
||||
id.includes(`${extensionId}.contextModule.`)
|
||||
@@ -215,9 +210,9 @@ export default function ModeRoute({
|
||||
|
||||
// Adding hanging protocols of extensions after onModeEnter since
|
||||
// it will reset the protocols
|
||||
hangingProtocols.forEach(extentionProtocols => {
|
||||
hangingProtocols.forEach(extensionProtocols => {
|
||||
const hangingProtocolModule = extensionManager.getModuleEntry(
|
||||
extentionProtocols
|
||||
extensionProtocols
|
||||
);
|
||||
if (hangingProtocolModule?.protocols) {
|
||||
HangingProtocolService.addProtocols(hangingProtocolModule.protocols);
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import React from "react";
|
||||
import { Route } from "react-router-dom";
|
||||
import { useUserAuthentication } from "@ohif/ui";
|
||||
import React from 'react';
|
||||
import { useUserAuthentication } from '@ohif/ui';
|
||||
|
||||
export const PrivateRoute = ({ ...rest }) => {
|
||||
const [{ user, enabled }, userAuthenticationService] = useUserAuthentication();
|
||||
export const PrivateRoute = ({ children, handleUnauthenticated }) => {
|
||||
const [{ user, enabled }] = useUserAuthentication();
|
||||
|
||||
if (enabled && !user) {
|
||||
return userAuthenticationService.handleUnauthenticated();
|
||||
}
|
||||
if (enabled && !user) {
|
||||
return handleUnauthenticated();
|
||||
}
|
||||
|
||||
return <Route {...rest}/>;
|
||||
}
|
||||
return children;
|
||||
};
|
||||
|
||||
export default PrivateRoute;
|
||||
@@ -194,10 +194,7 @@ function WorkList({
|
||||
const fetchSeries = async studyInstanceUid => {
|
||||
try {
|
||||
const series = await dataSource.query.series.search(studyInstanceUid);
|
||||
seriesInStudiesMap.set(
|
||||
studyInstanceUid,
|
||||
sortBySeriesDate(series)
|
||||
);
|
||||
seriesInStudiesMap.set(studyInstanceUid, sortBySeriesDate(series));
|
||||
setStudiesWithSeriesData([...studiesWithSeriesData, studyInstanceUid]);
|
||||
} catch (ex) {
|
||||
// TODO: UI Notification Service
|
||||
@@ -336,22 +333,23 @@ function WorkList({
|
||||
{appConfig.modes.map((mode, i) => {
|
||||
const isFirst = i === 0;
|
||||
|
||||
const isValidMode = mode.isValidMode({ modalities })
|
||||
const isValidMode = mode.isValidMode({ modalities });
|
||||
|
||||
// TODO: Modes need a default/target route? We mostly support a single one for now.
|
||||
// We should also be using the route path, but currently are not
|
||||
// mode.id
|
||||
// mode.routeName
|
||||
// mode.routes[x].path
|
||||
// Don't specify default data source, and it should just be picked up... (this may not currently be the case)
|
||||
// How do we know which params to pass? Today, it's just StudyInstanceUIDs
|
||||
return (
|
||||
<Link
|
||||
key={i}
|
||||
to={`${mode.id}?StudyInstanceUIDs=${studyInstanceUid}`}
|
||||
// to={`${mode.id}/dicomweb?StudyInstanceUIDs=${studyInstanceUid}`}
|
||||
to={`${mode.routeName}?StudyInstanceUIDs=${studyInstanceUid}`}
|
||||
// to={`${mode.routeName}/dicomweb?StudyInstanceUIDs=${studyInstanceUid}`}
|
||||
>
|
||||
<Button
|
||||
rounded="full"
|
||||
variant={isValidMode ? "contained" : "disabled"}
|
||||
variant={isValidMode ? 'contained' : 'disabled'}
|
||||
disabled={!isValidMode}
|
||||
endIcon={<Icon name="launch-arrow" />} // launch-arrow | launch-info
|
||||
className={classnames('font-bold', { 'ml-2': !isFirst })}
|
||||
@@ -380,7 +378,12 @@ function WorkList({
|
||||
{
|
||||
title: t('Header:About'),
|
||||
icon: 'info',
|
||||
onClick: () => show({ content: AboutModal, title: 'About OHIF Viewer', contentProps: { versionNumber, buildNumber } }),
|
||||
onClick: () =>
|
||||
show({
|
||||
content: AboutModal,
|
||||
title: 'About OHIF Viewer',
|
||||
contentProps: { versionNumber, buildNumber },
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: t('Header:Preferences'),
|
||||
@@ -398,13 +401,13 @@ function WorkList({
|
||||
currentLanguage: currentLanguage(),
|
||||
availableLanguages,
|
||||
defaultLanguage,
|
||||
onSubmit: (state) => {
|
||||
onSubmit: state => {
|
||||
i18n.changeLanguage(state.language.value);
|
||||
hotkeysManager.setHotkeys(state.hotkeyDefinitions);
|
||||
hide();
|
||||
},
|
||||
onReset: () => hotkeysManager.restoreDefaultBindings(),
|
||||
hotkeysModule: hotkeys
|
||||
hotkeysModule: hotkeys,
|
||||
},
|
||||
}),
|
||||
},
|
||||
@@ -416,7 +419,12 @@ function WorkList({
|
||||
'h-screen': !hasStudies,
|
||||
})}
|
||||
>
|
||||
<Header isSticky menuOptions={menuOptions} isReturnEnabled={false} WhiteLabeling={appConfig.whiteLabeling} />
|
||||
<Header
|
||||
isSticky
|
||||
menuOptions={menuOptions}
|
||||
isReturnEnabled={false}
|
||||
WhiteLabeling={appConfig.whiteLabeling}
|
||||
/>
|
||||
<StudyListFilter
|
||||
numOfStudies={pageNumber * resultsPerPage > 100 ? 101 : numOfStudies}
|
||||
filtersMeta={filtersMeta}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import ModeRoute from '@routes/Mode';
|
||||
import checkExtensionDependencies from './checkExtensionDependencies';
|
||||
|
||||
/*
|
||||
Routes uniquely define an entry point to:
|
||||
@@ -44,10 +45,11 @@ export default function buildModeRoutes({
|
||||
});
|
||||
|
||||
modes.forEach(mode => {
|
||||
checkExtensionDependencies(mode, extensionManager);
|
||||
|
||||
// todo: for each route. add route to path.
|
||||
dataSourceNames.forEach(dataSourceName => {
|
||||
// TODO: name vs id
|
||||
const path = `/${mode.id}/${dataSourceName}`;
|
||||
const path = `/${mode.routeName}/${dataSourceName}`;
|
||||
|
||||
// TODO move up.
|
||||
const children = () => (
|
||||
@@ -69,7 +71,7 @@ export default function buildModeRoutes({
|
||||
const defaultDataSourceName = extensionManager.defaultDataSourceName;
|
||||
|
||||
// Add default DataSource route.
|
||||
const path = `/${mode.id}`;
|
||||
const path = `/${mode.routeName}`;
|
||||
|
||||
// TODO move up.
|
||||
const children = () => (
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
export default function checkExtensionDependencies(mode, extensionManager) {
|
||||
const extensionDependencies = mode.extensions;
|
||||
|
||||
const dependencyString = `Unmet extension dependency in mode: ${mode.id}`;
|
||||
|
||||
Object.keys(extensionDependencies).forEach(extensionId => {
|
||||
const extensionInstalled = extensionManager.registeredExtensionIds.includes(
|
||||
extensionId
|
||||
);
|
||||
|
||||
if (!extensionInstalled) {
|
||||
throw new Error(
|
||||
`${dependencyString}: extension ${extensionId} not found`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function areVersionsCompatible(semanticVersion, installedVersion) {
|
||||
if (semanticVersion.includes('^')) {
|
||||
// Major must match
|
||||
const versionLessCaret = semanticVersion.split('^')[1];
|
||||
|
||||
// Index 0 is the major version.
|
||||
return versionLessCaret[0] === installedVersion[0];
|
||||
} else if (semanticVersion.includes('~')) {
|
||||
// Major and minor must match
|
||||
const versionLessTilde = semanticVersion.split('~')[1];
|
||||
|
||||
// Index 0 is the major version.
|
||||
// Index 2 is the minor version.
|
||||
return (
|
||||
versionLessTilde[0] === installedVersion[0] &&
|
||||
versionLessTilde[2] === installedVersion[2]
|
||||
);
|
||||
} else {
|
||||
return semanticVersion === installedVersion;
|
||||
}
|
||||
}
|
||||
@@ -64,18 +64,26 @@ const createRoutes = ({
|
||||
|
||||
const { UserAuthenticationService } = servicesManager.services;
|
||||
|
||||
// Note: PrivateRoutes in react-router-dom 6.x should be defined within
|
||||
// a Route element
|
||||
return (
|
||||
<Routes basename={routerBasename}>
|
||||
{allRoutes.map((route, i) => {
|
||||
return route.private === true ? (
|
||||
<PrivateRoute
|
||||
<Route
|
||||
key={i}
|
||||
exact
|
||||
path={route.path}
|
||||
handleUnauthenticated={
|
||||
UserAuthenticationService.handleUnauthenticated
|
||||
element={
|
||||
<PrivateRoute
|
||||
handleUnauthenticated={
|
||||
UserAuthenticationService.handleUnauthenticated
|
||||
}
|
||||
>
|
||||
<RouteWithErrorBoundary route={route} />
|
||||
</PrivateRoute>
|
||||
}
|
||||
element={<RouteWithErrorBoundary route={route} />}
|
||||
/>
|
||||
></Route>
|
||||
) : (
|
||||
<Route
|
||||
key={i}
|
||||
|
||||
Reference in new issue
Block a user