chore(build): try to build demo and docs (#3434)
This commit is contained in:
1 parent
869b8ced05
commit
828690cd3b
329 files changed
+1896
-1010
No files matched your search
@@ -0,0 +1,138 @@
|
||||
import {
|
||||
CommandsManager,
|
||||
ExtensionManager,
|
||||
ServicesManager,
|
||||
HotkeysManager,
|
||||
UINotificationService,
|
||||
UIModalService,
|
||||
UIDialogService,
|
||||
UIViewportDialogService,
|
||||
MeasurementService,
|
||||
StateSyncService,
|
||||
DisplaySetService,
|
||||
ToolbarService,
|
||||
ViewportGridService,
|
||||
HangingProtocolService,
|
||||
CineService,
|
||||
UserAuthenticationService,
|
||||
errorHandler,
|
||||
CustomizationService,
|
||||
PanelService,
|
||||
// utils,
|
||||
} from '@ohif/core';
|
||||
|
||||
import loadModules from './pluginImports';
|
||||
|
||||
/**
|
||||
* @param {object|func} appConfigOrFunc - application configuration, or a function that returns application configuration
|
||||
* @param {object[]} defaultExtensions - array of extension objects
|
||||
*/
|
||||
async function appInit(appConfigOrFunc, defaultExtensions, defaultModes) {
|
||||
const commandsManagerConfig = {
|
||||
getAppState: () => {},
|
||||
};
|
||||
|
||||
const commandsManager = new CommandsManager(commandsManagerConfig);
|
||||
const servicesManager = new ServicesManager(commandsManager);
|
||||
const hotkeysManager = new HotkeysManager(commandsManager, servicesManager);
|
||||
|
||||
const appConfig = {
|
||||
...(typeof appConfigOrFunc === 'function'
|
||||
? await appConfigOrFunc({ servicesManager })
|
||||
: appConfigOrFunc),
|
||||
};
|
||||
|
||||
const extensionManager = new ExtensionManager({
|
||||
commandsManager,
|
||||
servicesManager,
|
||||
hotkeysManager,
|
||||
appConfig,
|
||||
});
|
||||
|
||||
servicesManager.registerServices([
|
||||
UINotificationService.REGISTRATION,
|
||||
UIModalService.REGISTRATION,
|
||||
UIDialogService.REGISTRATION,
|
||||
UIViewportDialogService.REGISTRATION,
|
||||
MeasurementService.REGISTRATION,
|
||||
DisplaySetService.REGISTRATION,
|
||||
[CustomizationService.REGISTRATION, appConfig.customizationService],
|
||||
ToolbarService.REGISTRATION,
|
||||
ViewportGridService.REGISTRATION,
|
||||
HangingProtocolService.REGISTRATION,
|
||||
CineService.REGISTRATION,
|
||||
UserAuthenticationService.REGISTRATION,
|
||||
PanelService.REGISTRATION,
|
||||
StateSyncService.REGISTRATION,
|
||||
]);
|
||||
|
||||
errorHandler.getHTTPErrorHandler = () => {
|
||||
if (typeof appConfig.httpErrorHandler === 'function') {
|
||||
return appConfig.httpErrorHandler;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Example: [ext1, ext2, ext3]
|
||||
* Example2: [[ext1, config], ext2, [ext3, config]]
|
||||
*/
|
||||
const loadedExtensions = await loadModules([
|
||||
...defaultExtensions,
|
||||
...appConfig.extensions,
|
||||
]);
|
||||
await extensionManager.registerExtensions(
|
||||
loadedExtensions,
|
||||
appConfig.dataSources
|
||||
);
|
||||
|
||||
// TODO: We no longer use `utils.addServer`
|
||||
// TODO: We no longer init webWorkers at app level
|
||||
// TODO: We no longer init the user Manager
|
||||
|
||||
if (!appConfig.modes) {
|
||||
throw new Error('No modes are defined! Check your app-config.js');
|
||||
}
|
||||
|
||||
const loadedModes = await loadModules([
|
||||
...(appConfig.modes || []),
|
||||
...defaultModes,
|
||||
]);
|
||||
|
||||
// This is the name for the loaded istance object
|
||||
appConfig.loadedModes = [];
|
||||
const modesById = new Set();
|
||||
for (let i = 0; i < loadedModes.length; i++) {
|
||||
let mode = loadedModes[i];
|
||||
if (!mode) continue;
|
||||
const { id } = mode;
|
||||
|
||||
if (mode.modeFactory) {
|
||||
// If the appConfig contains configuration for this mode, use it.
|
||||
const modeConfig =
|
||||
appConfig.modeConfig && appConfig.modeConfig[i]
|
||||
? appConfig.modeConfig[id]
|
||||
: {};
|
||||
|
||||
mode = mode.modeFactory(modeConfig);
|
||||
}
|
||||
|
||||
if (modesById.has(id)) continue;
|
||||
// Prevent duplication
|
||||
modesById.add(id);
|
||||
if (!mode || typeof mode !== 'object') continue;
|
||||
appConfig.loadedModes.push(mode);
|
||||
}
|
||||
// Hack alert - don't touch the original modes definition,
|
||||
// but there are still dependencies on having the appConfig modes defined
|
||||
appConfig.modes = appConfig.loadedModes;
|
||||
|
||||
return {
|
||||
appConfig,
|
||||
commandsManager,
|
||||
extensionManager,
|
||||
servicesManager,
|
||||
hotkeysManager,
|
||||
};
|
||||
}
|
||||
|
||||
export default appInit;
|
||||
Reference in new issue
Block a user