UNPKG

@o3r/core

Version:
114 lines 5.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ngAdd = void 0; const fs = require("node:fs"); const path = require("node:path"); const prompt_1 = require("@angular/cli/src/utilities/prompt"); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@o3r/schematics"); const schematics_3 = require("@o3r/schematics"); const dependencies_1 = require("@schematics/angular/utility/dependencies"); const index_1 = require("../rule-factories/index"); const presets_1 = require("../shared/presets"); const index_2 = require("./project-setup/index"); const workspacePackageName = '@o3r/workspace'; const o3rDevDependencies = [ '@o3r/schematics' ]; /** * Add Otter library to an Angular Project * @param options */ function ngAddFn(options) { const corePackageJsonContent = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', 'package.json'), { encoding: 'utf8' })); const o3rCoreVersion = corePackageJsonContent.version; const o3rVersionRange = options.exactO3rVersion ? o3rCoreVersion : `~${o3rCoreVersion}`; return () => { const dependenciesSetupConfig = { projectName: options.projectName, dependencies: o3rDevDependencies.reduce((acc, dep) => { acc[dep] = { inManifest: [{ range: o3rVersionRange, types: [dependencies_1.NodeDependencyType.Dev] }], ngAddOptions: { exactO3rVersion: options.exactO3rVersion } }; return acc; }, {}), ngAddToRun: [...o3rDevDependencies] }; if (!options.projectName) { dependenciesSetupConfig.dependencies[workspacePackageName] = { toWorkspaceOnly: true, inManifest: [{ range: o3rVersionRange, types: [dependencies_1.NodeDependencyType.Default] }], ngAddOptions: { exactO3rVersion: options.exactO3rVersion } }; (dependenciesSetupConfig.ngAddToRun ||= []).push(workspacePackageName); } return (0, schematics_1.chain)([ (0, schematics_2.setupSchematicsParamsForProject)({ '*:ng-add': { registerDevtool: options.withDevtool } }, options.projectName), options.exactO3rVersion ? (0, schematics_2.setupSchematicsParamsForProject)({ '*:*': { exactO3rVersion: true } }, options.projectName) : (0, schematics_1.noop)(), // Warning: this should always be executed before the setup dependencies as it modifies the options.dependencies options.projectName ? (0, index_2.prepareProject)(options, dependenciesSetupConfig) : (0, schematics_1.noop)(), (0, schematics_2.registerPackageCollectionSchematics)(corePackageJsonContent), (0, index_1.updatePackageJson)(dependenciesSetupConfig, ['@angular/animations', '@angular/platform-browser-dynamic'], [], options.projectName), (0, schematics_3.setupDependencies)(dependenciesSetupConfig), async (t, c) => { const { preset, externalPresets, ...forwardOptions } = options; const presetOptions = { projectName: forwardOptions.projectName, exactO3rVersion: forwardOptions.exactO3rVersion, forwardOptions }; const presetRunner = await presets_1.presets[preset](presetOptions); const externalPresetRunner = externalPresets ? await (0, presets_1.getExternalPreset)(externalPresets, t, c)(presetOptions) : undefined; const modules = [...new Set([...(presetRunner.modules || []), ...(externalPresetRunner?.modules || [])])]; if (modules.length > 0) { c.logger.info(`The following modules will be installed: ${modules.join(', ')}`); if (c.interactive && !await (0, prompt_1.askConfirmation)('Would you like to process to the setup of these modules?', true)) { return; } } return () => (0, schematics_1.chain)([ presetRunner.rule, externalPresetRunner?.rule || (0, schematics_1.noop)() ])(t, c); }, options.projectName ? (0, schematics_2.displayModuleListRule)({ packageName: options.projectName }) : (0, schematics_1.noop)(), (t) => { const mcpConfigToAdd = { servers: { angular: { command: 'npx', args: ['@angular/cli', 'mcp'] }, o3r: { type: 'stdio', command: 'npx', args: ['-y', '-p', '@o3r/mcp', 'o3r-mcp-start'] } } }; const mcpConfigPath = '/.vscode/mcp.json'; if (t.exists(mcpConfigPath)) { const mcpConfig = t.readJson(mcpConfigPath); t.overwrite(mcpConfigPath, JSON.stringify({ ...mcpConfig, servers: { ...mcpConfigToAdd.servers, ...mcpConfig.servers } }, null, 2)); return t; } t.create(mcpConfigPath, JSON.stringify(mcpConfigToAdd, null, 2)); } ]); }; } /** * Add Otter library to an Angular Project * @param options */ exports.ngAdd = (0, schematics_2.createOtterSchematic)(ngAddFn); //# sourceMappingURL=index.js.map