UNPKG

@o3r/components

Version:

This module contains component-related features (Component replacement, CMS compatibility, helpers, pipes, debugging developer tools...) It comes with an integrated ng builder to help you generate components compatible with Otter features (CMS integration

70 lines 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ngAdd = void 0; const tslib_1 = require("tslib"); const fs = tslib_1.__importStar(require("node:fs")); const path = tslib_1.__importStar(require("node:path")); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@o3r/schematics"); const cms_adapter_1 = require("../cms-adapter"); const devtools_registration_1 = require("./helpers/devtools-registration"); /** * Add Otter components to an Angular Project * @param options */ function ngAddFn(options) { /* ng add rules */ return async (tree, context) => { const { NodeDependencyType } = await Promise.resolve().then(() => tslib_1.__importStar(require('@schematics/angular/utility/dependencies'))).catch(() => ({ NodeDependencyType: { Dev: 'devDependencies' } })); options = { ...(0, schematics_2.getDefaultOptionsForSchematic)((0, schematics_2.getWorkspaceConfig)(tree), '@o3r/components', 'ng-add', options), ...options }; const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })); const depsInfo = (0, schematics_2.getO3rPeerDeps)(packageJsonPath); if (options.enableMetadataExtract) { depsInfo.o3rPeerDeps = [...depsInfo.o3rPeerDeps, '@o3r/extractors']; } const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined; const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => { acc[dep] = { inManifest: [{ range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`, types: (0, schematics_2.getProjectNewDependenciesTypes)(workspaceProject) }], ngAddOptions: { exactO3rVersion: options.exactO3rVersion } }; return acc; }, (0, schematics_2.getPackageInstallConfig)(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion)); const devDependencies = { chokidar: { inManifest: [{ range: packageJson.peerDependencies.chokidar, types: [NodeDependencyType.Dev] }] } }; const rule = (0, schematics_1.chain)([ (0, schematics_2.removePackages)(['@otter/components']), (0, schematics_2.setupDependencies)({ projectName: options.projectName, dependencies: { ...dependencies, ...devDependencies }, ngAddToRun: depsInfo.o3rPeerDeps }), (0, schematics_2.registerPackageCollectionSchematics)(packageJson), ...(options.enableMetadataExtract ? [(0, cms_adapter_1.updateCmsAdapter)(options)] : []), (0, devtools_registration_1.registerDevtools)(options) ]); context.logger.info(`The package ${depsInfo.packageName} comes with a debug mechanism`); context.logger.info('Get more information on the following page: https://github.com/AmadeusITGroup/otter/tree/main/docs/components/INTRODUCTION.md#Runtime-debugging'); return () => rule(tree, context); }; } /** * Add Otter components to an Angular Project * @param options */ const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options); exports.ngAdd = ngAdd; //# sourceMappingURL=index.js.map