* tests: add various e2e tests for MPR and measurements wip add cypress config feat: add mode and extension for testing add hp applied through search params add MPR tests apply review comments add more e2e tests update yarn lock * fix unit tests failing
236 lines
5.8 KiB
JavaScript
236 lines
5.8 KiB
JavaScript
const pluginConfig = require('../pluginConfig.json');
|
|
const fs = require('fs');
|
|
const glob = require('glob');
|
|
|
|
const autogenerationDisclaimer = `
|
|
// THIS FILE IS AUTOGENERATED AS PART OF THE EXTENSION AND MODE PLUGIN PROCESS.
|
|
// IT SHOULD NOT BE MODIFIED MANUALLY \n`;
|
|
|
|
function constructLines(input, categoryName) {
|
|
let pluginCount = 0;
|
|
|
|
const lines = {
|
|
importLines: [],
|
|
addToWindowLines: [],
|
|
};
|
|
|
|
if (!input) return lines;
|
|
|
|
input.forEach(entry => {
|
|
if (entry.default === false) return;
|
|
|
|
const packageName = entry.packageName;
|
|
const defaultImportName = `${categoryName}${pluginCount}`;
|
|
|
|
lines.importLines.push(
|
|
`import ${defaultImportName} from '${packageName}';\n`
|
|
);
|
|
lines.addToWindowLines.push(
|
|
`${categoryName}.push(${defaultImportName});\n`
|
|
);
|
|
|
|
pluginCount++;
|
|
});
|
|
|
|
return lines;
|
|
}
|
|
|
|
function getFormattedImportBlock(importLines) {
|
|
let content = '';
|
|
// Imports
|
|
importLines.forEach(importLine => {
|
|
content += importLine;
|
|
});
|
|
|
|
return content;
|
|
}
|
|
|
|
function getFormattedWindowBlock(addToWindowLines) {
|
|
let content =
|
|
'const extensions = [];\n' +
|
|
'const modes = [];\n' +
|
|
'const modesFactory = [];\n' +
|
|
'window.extensions = extensions;\n' +
|
|
'window.modes = modes;\n\n';
|
|
|
|
addToWindowLines.forEach(addToWindowLine => {
|
|
content += addToWindowLine;
|
|
});
|
|
|
|
return content;
|
|
}
|
|
|
|
function getRuntimeLoadModesExtensions() {
|
|
return (
|
|
'\n\n// Add a dynamic runtime loader\n' +
|
|
'export default async () => {\n' +
|
|
' for(const modeFactory of modesFactory) {\n' +
|
|
' const newModes = await modeFactory(modes,extensions);\n' +
|
|
' newModes.forEach(newMode => modes.push(newMode));\n' +
|
|
'}\n}\n\n\n' +
|
|
'async function loadRuntimeImports(config) {\n' +
|
|
' if (config && config.modes && config.modes.length) {\n' +
|
|
' for (const modeName of config.modes) {\n' +
|
|
' const existingMode = modes.find(mode => mode.id === modeName);\n' +
|
|
' if (!existingMode) {\n' +
|
|
' if (modeName === `@ohif/mode-test`) {\n' +
|
|
' const mode = await import(`@ohif/mode-test`);\n' +
|
|
' window.modes.push(mode.default);\n' +
|
|
' const extension = await import(`@ohif/extension-test`);\n' +
|
|
' window.extensions.push(extension.default);\n' +
|
|
' }\n' +
|
|
' }\n' +
|
|
' };\n' +
|
|
' }\n' +
|
|
'}\n' +
|
|
'export { loadRuntimeImports };\n\n'
|
|
);
|
|
}
|
|
|
|
const createCopyPluginToDistForLink = (
|
|
SRC_DIR,
|
|
DIST_DIR,
|
|
plugins,
|
|
folderName
|
|
) => {
|
|
return plugins
|
|
.map(plugin => {
|
|
const from = `${SRC_DIR}/../node_modules/${plugin.packageName}/${folderName}/`;
|
|
const exists = fs.existsSync(from);
|
|
return exists
|
|
? {
|
|
from,
|
|
to: DIST_DIR,
|
|
toType: 'dir',
|
|
}
|
|
: undefined;
|
|
})
|
|
.filter(x => !!x);
|
|
};
|
|
|
|
const createCopyPluginToDistForBuild = (
|
|
SRC_DIR,
|
|
DIST_DIR,
|
|
plugins,
|
|
folderName
|
|
) => {
|
|
return plugins
|
|
.map(plugin => {
|
|
const from = `${SRC_DIR}/../../../node_modules/${plugin.packageName}/${folderName}/`;
|
|
const exists = fs.existsSync(from);
|
|
return exists
|
|
? {
|
|
from,
|
|
to: DIST_DIR,
|
|
toType: 'dir',
|
|
}
|
|
: undefined;
|
|
})
|
|
.filter(x => !!x);
|
|
};
|
|
|
|
function writePluginImportsFile(SRC_DIR, DIST_DIR) {
|
|
let pluginImportsJsContent = autogenerationDisclaimer;
|
|
|
|
const extensionLines = constructLines(pluginConfig.extensions, 'extensions');
|
|
const modeLines = constructLines(pluginConfig.modes, 'modes');
|
|
const modesFactoryLines = constructLines(
|
|
pluginConfig.modesFactory,
|
|
'modesFactory'
|
|
);
|
|
|
|
pluginImportsJsContent += getFormattedImportBlock([
|
|
...extensionLines.importLines,
|
|
...modeLines.importLines,
|
|
...modesFactoryLines.importLines,
|
|
]);
|
|
pluginImportsJsContent += getFormattedWindowBlock([
|
|
...extensionLines.addToWindowLines,
|
|
...modeLines.addToWindowLines,
|
|
...modesFactoryLines.addToWindowLines,
|
|
]);
|
|
|
|
pluginImportsJsContent += getRuntimeLoadModesExtensions();
|
|
|
|
fs.writeFileSync(
|
|
`${SRC_DIR}/pluginImports.js`,
|
|
pluginImportsJsContent,
|
|
{ flag: 'w+' },
|
|
err => {
|
|
if (err) {
|
|
console.error(err);
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
|
|
// Build packages using cli add-mode and add-extension
|
|
// will get added to the root node_modules, but the linked packages
|
|
// will be hosted at the viewer node_modules.
|
|
|
|
const copyPluginPublicToDistBuild = createCopyPluginToDistForBuild(
|
|
SRC_DIR,
|
|
DIST_DIR,
|
|
[
|
|
...pluginConfig.modesFactory,
|
|
...pluginConfig.modes,
|
|
...pluginConfig.extensions,
|
|
...pluginConfig.umd,
|
|
],
|
|
'public'
|
|
);
|
|
|
|
const copyPluginPublicToDistLink = createCopyPluginToDistForLink(
|
|
SRC_DIR,
|
|
DIST_DIR,
|
|
[
|
|
...pluginConfig.modesFactory,
|
|
...pluginConfig.modes,
|
|
...pluginConfig.extensions,
|
|
...pluginConfig.umd,
|
|
],
|
|
'public'
|
|
);
|
|
|
|
// Temporary way to copy chunks from the dist folder so that the become
|
|
// available
|
|
const copyPluginDistToDistBuild = createCopyPluginToDistForBuild(
|
|
SRC_DIR,
|
|
DIST_DIR,
|
|
[
|
|
...pluginConfig.modesFactory,
|
|
...pluginConfig.modes,
|
|
...pluginConfig.extensions,
|
|
...pluginConfig.umd,
|
|
],
|
|
'dist'
|
|
);
|
|
|
|
const copyPluginDistToDistLink = createCopyPluginToDistForLink(
|
|
SRC_DIR,
|
|
DIST_DIR,
|
|
[
|
|
...pluginConfig.modesFactory,
|
|
...pluginConfig.modes,
|
|
...pluginConfig.extensions,
|
|
...pluginConfig.umd,
|
|
],
|
|
'dist'
|
|
);
|
|
|
|
console.log('copy plugins', [
|
|
...copyPluginPublicToDistBuild,
|
|
...copyPluginPublicToDistLink,
|
|
...copyPluginDistToDistBuild,
|
|
...copyPluginDistToDistLink,
|
|
]);
|
|
return [
|
|
...copyPluginPublicToDistBuild,
|
|
...copyPluginPublicToDistLink,
|
|
...copyPluginDistToDistBuild,
|
|
...copyPluginDistToDistLink,
|
|
];
|
|
}
|
|
|
|
module.exports = writePluginImportsFile;
|