* 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>
211 lines
5.3 KiB
JavaScript
Executable File
211 lines
5.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
import program from 'commander';
|
|
import inquirer from 'inquirer';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import { getPathQuestions, getRepoQuestions } from './questions.js';
|
|
import {
|
|
createPackage,
|
|
addExtension,
|
|
removeExtension,
|
|
addMode,
|
|
removeMode,
|
|
listPlugins,
|
|
searchPlugins,
|
|
linkExtension,
|
|
linkMode,
|
|
unlinkExtension,
|
|
unlinkMode,
|
|
} from './commands/index.js';
|
|
import chalk from 'chalk';
|
|
|
|
const runningDirectory = process.cwd();
|
|
const viewerDirectory = path.resolve(runningDirectory, 'platform/viewer');
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
const packageJsonPath = path.join(runningDirectory, 'package.json');
|
|
|
|
try {
|
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
if (packageJson.name !== 'ohif-monorepo-root') {
|
|
console.log(packageJson);
|
|
console.log(
|
|
chalk.red('ohif-cli must run from the root of the OHIF platform')
|
|
);
|
|
process.exit(1);
|
|
}
|
|
} catch (error) {
|
|
console.log(
|
|
chalk.red('ohif-cli must run from the root of the OHIF platform')
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
function _createPackage(packageType) {
|
|
const pathQuestions = getPathQuestions(packageType);
|
|
const repoQuestions = getRepoQuestions(packageType);
|
|
|
|
let pathAnswers;
|
|
|
|
const askPathQuestions = () => {
|
|
inquirer.prompt(pathQuestions).then((answers) => {
|
|
pathAnswers = answers;
|
|
if (pathAnswers.confirm) {
|
|
askRepoQuestions(answers.baseDir, answers.name);
|
|
} else {
|
|
askPathQuestions();
|
|
}
|
|
});
|
|
};
|
|
|
|
const askRepoQuestions = () => {
|
|
inquirer.prompt(repoQuestions).then((repoAnswers) => {
|
|
const answers = {
|
|
...pathAnswers,
|
|
...repoAnswers,
|
|
};
|
|
|
|
const templateDir = path.join(__dirname, `../templates/${packageType}`);
|
|
answers.templateDir = templateDir;
|
|
answers.targetDir = path.join(answers.baseDir);
|
|
answers.packageType = packageType;
|
|
|
|
createPackage(answers);
|
|
});
|
|
};
|
|
|
|
askPathQuestions();
|
|
}
|
|
|
|
// Todo: inject with webpack
|
|
program.version('2.0.7').description('OHIF CLI');
|
|
|
|
program
|
|
.command('create-extension')
|
|
.description('Create a new template extension')
|
|
.action(() => {
|
|
_createPackage('extension');
|
|
});
|
|
|
|
program
|
|
.command('create-mode')
|
|
.description('Create a new template Mode')
|
|
.action(() => {
|
|
_createPackage('mode');
|
|
});
|
|
|
|
program
|
|
.command('add-extension <packageName> [version]')
|
|
.description('Adds an ohif extension')
|
|
.action((packageName, version) => {
|
|
// change directory to viewer
|
|
process.chdir(viewerDirectory);
|
|
addExtension(packageName, version);
|
|
});
|
|
|
|
program
|
|
.command('remove-extension <packageName>')
|
|
.description('removes an ohif extension')
|
|
.action((packageName) => {
|
|
// change directory to viewer
|
|
process.chdir(viewerDirectory);
|
|
removeExtension(packageName);
|
|
});
|
|
|
|
program
|
|
.command('add-mode <packageName> [version]')
|
|
.description('Removes an ohif mode')
|
|
.action((packageName, version) => {
|
|
// change directory to viewer
|
|
process.chdir(viewerDirectory);
|
|
addMode(packageName, version);
|
|
});
|
|
|
|
program
|
|
.command('remove-mode <packageName>')
|
|
.description('Removes an ohif mode')
|
|
.action((packageName) => {
|
|
// change directory to viewer
|
|
process.chdir(viewerDirectory);
|
|
removeMode(packageName);
|
|
});
|
|
|
|
program
|
|
.command('link-extension <packageDir>')
|
|
.description(
|
|
'Links a local OHIF extension to the Viewer to be used for development'
|
|
)
|
|
.action((packageDir) => {
|
|
if (!fs.existsSync(packageDir)) {
|
|
console.log(
|
|
chalk.red(
|
|
'The extension directory does not exist, please provide a valid directory'
|
|
)
|
|
);
|
|
process.exit(1);
|
|
}
|
|
linkExtension(packageDir, { viewerDirectory });
|
|
});
|
|
|
|
program
|
|
.command('unlink-extension <extensionName>')
|
|
.description('Unlinks a local OHIF extension from the Viewer')
|
|
.action((extensionName) => {
|
|
unlinkExtension(extensionName, { viewerDirectory });
|
|
console.log(
|
|
chalk.green(
|
|
`Successfully unlinked extension ${extensionName} from the Viewer, don't forget to run yarn install --force`
|
|
)
|
|
);
|
|
});
|
|
|
|
program
|
|
.command('link-mode <packageDir>')
|
|
.description(
|
|
'Links a local OHIF mode to the Viewer to be used for development'
|
|
)
|
|
.action((packageDir) => {
|
|
if (!fs.existsSync(packageDir)) {
|
|
console.log(
|
|
chalk.red(
|
|
'The mode directory does not exist, please provide a valid directory'
|
|
)
|
|
);
|
|
process.exit(1);
|
|
}
|
|
linkMode(packageDir, { viewerDirectory });
|
|
});
|
|
|
|
program
|
|
.command('unlink-mode <modeName>')
|
|
.description('Unlinks a local OHIF mode from the Viewer')
|
|
.action((modeName) => {
|
|
unlinkMode(modeName, { viewerDirectory });
|
|
console.log(
|
|
chalk.green(
|
|
`Successfully unlinked mode ${modeName} from the Viewer, don't forget to run yarn install --force`
|
|
)
|
|
);
|
|
});
|
|
|
|
program
|
|
.command('list')
|
|
.description('List Added Extensions and Modes')
|
|
.action(() => {
|
|
const configPath = path.resolve(viewerDirectory, './pluginConfig.json');
|
|
listPlugins(configPath);
|
|
});
|
|
|
|
program
|
|
.command('search')
|
|
.option('-v, --verbose', 'Verbose output')
|
|
.description('Search NPM for the list of Modes and Extensions')
|
|
.action((options) => {
|
|
searchPlugins(options);
|
|
});
|
|
|
|
program.parse(process.argv);
|