UNPKG

@o3r/core

Version:
67 lines 3.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ngAddModules = void 0; const prompt_1 = require("@angular/cli/src/utilities/prompt"); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@o3r/schematics"); const presets_1 = require("../shared/presets"); /** * Select the available modules to add to the project * @param options */ function ngAddModulesFn(options) { return async (tree, context) => { if (!context.interactive && !options.preset && !options.externalPresets) { context.logger.error('This command is available only for interactive shell, only the "preset" option can be used without interaction'); return () => tree; } const { preset, externalPresets, ...forwardOptions } = options; const presetRunner = preset ? await presets_1.presets[preset]({ forwardOptions }) : undefined; const externalPresetRunner = externalPresets ? await (0, presets_1.getExternalPreset)(externalPresets, tree, context)?.({ projectName: forwardOptions.projectName, forwardOptions }) : undefined; const mods = [...new Set([...(presetRunner?.modules || []), ...(externalPresetRunner?.modules || [])])]; if (mods.length > 0) { context.logger.info(`The following modules will be installed: ${mods.join(', ')}`); if (context.interactive && !await (0, prompt_1.askConfirmation)('Would you like to process to the setup of these modules?', true)) { return; } } if (presetRunner || externalPresetRunner) { return () => (0, schematics_1.chain)([ presetRunner?.rule || (0, schematics_1.noop)(), externalPresetRunner?.rule || (0, schematics_1.noop)() ])(tree, context); } try { const modules = await (0, schematics_2.getAvailableModulesWithLatestPackage)(schematics_2.OTTER_MODULE_KEYWORD, { scopeWhitelist: schematics_2.OTTER_MODULE_SUPPORTED_SCOPES, onlyNotInstalled: true, logger: context.logger, workspaceConfig: (0, schematics_2.getWorkspaceConfig)(tree) }); if (modules.length === 0) { context.logger.warn('There is no additional available module'); return () => tree; } const res = await (0, prompt_1.askQuestion)('Choose the modules to install:', modules.map((mod) => ({ type: 'choice', name: mod.name, value: mod.name, short: mod.description })), 0, null); if (res) { return (0, schematics_1.externalSchematic)(res, 'ng-add', forwardOptions); } } catch (e) { context.logger.debug('Error during the module discovery', e); context.logger.error('List of Otter modules unavailable'); } return () => tree; }; } /** * Select the available modules to add to the project * @param options */ exports.ngAddModules = (0, schematics_2.createOtterSchematic)(ngAddModulesFn); //# sourceMappingURL=index.js.map