life-sciences-portal-cli
Version:
A CLI to generate and manage life sciences portals.
66 lines (65 loc) • 3.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.lifeSciencesPortalNew = void 0;
const JSON5 = require("json5");
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
function updateAngularJson(_options) {
return (tree, _context) => {
const angularJsonFileName = (0, core_1.normalize)(`/${_options.path}/angular.json`);
const angularJsonBuffer = tree.read(angularJsonFileName);
if (angularJsonBuffer !== null) {
const angularJson = JSON.parse(angularJsonBuffer.toString());
const projectName = Object.keys(angularJson.projects)[0];
const build = angularJson.projects[projectName].architect.build;
build.options.stylePreprocessorOptions = Object.assign(Object.assign({}, build.options.stylePreprocessorOptions), { includePaths: [
...build.options.stylePreprocessorOptions.includePaths,
'node_modules/ngx-smart-modal/styles'
] });
tree.overwrite(angularJsonFileName, JSON.stringify(angularJson, null, 2));
}
return tree;
};
}
function updateTsConfig(_options) {
return (tree, _context) => {
const tsconfigFileName = (0, core_1.normalize)(`/${_options.path}/tsconfig.json`);
const tsconfigBuffer = tree.read(tsconfigFileName);
if (tsconfigBuffer !== null) {
const tsconfig = JSON5.parse(tsconfigBuffer.toString());
if (tsconfig) {
tsconfig.compilerOptions = Object.assign(Object.assign({}, tsconfig.compilerOptions), { resolveJsonModule: true, allowSyntheticDefaultImports: true });
}
tree.overwrite(tsconfigFileName, JSON.stringify(tsconfig, null, 2));
}
return tree;
};
}
// TODO: check project existence
function lifeSciencesPortalNew(_options) {
return async (_tree, _context) => {
const _path = (0, core_1.normalize)(`/${_options.name || ''}`);
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(`./files/${_options.portalType}`), [
(0, schematics_1.move)(_path)
]);
return (0, schematics_1.chain)([
(0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.empty)(), [
(0, schematics_1.externalSchematic)('@schematics/angular', 'ng-new', {
name: _options.name,
skipInstall: true,
style: 'scss',
routing: false,
strict: false,
version: '16.2.1'
})
])),
(0, schematics_1.mergeWith)(templateSource, schematics_1.MergeStrategy.Overwrite),
(0, schematics_1.schematic)('lsp-visual-framework', { path: _options.name }),
updateAngularJson({ path: _options.name }),
updateTsConfig({ path: _options.name }),
_options.sitemap ? (0, schematics_1.schematic)('lsp-sitemap', { path: _options.name, portalType: _options.portalType }) : (0, schematics_1.noop)(),
_options.internalCms ? (0, schematics_1.schematic)('lsp-internal-cms', { path: _options.name }) : (0, schematics_1.noop)(),
]);
};
}
exports.lifeSciencesPortalNew = lifeSciencesPortalNew;