UNPKG

@o3r/schematics

Version:

Schematics module of the Otter framework

69 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerPackageCollectionSchematics = registerPackageCollectionSchematics; exports.setupSchematicsParamsForProject = setupSchematicsParamsForProject; const utility_1 = require("../../utility"); /** * Register the given package in the Angular CLI schematics * @param packageJson PackageJson of the project containing the collection to add to the project * @param angularJsonFile Path to the Angular.json file. Will use the workspace root's angular.json if not specified */ function registerPackageCollectionSchematics(packageJson, angularJsonFile) { return (tree, context) => { if (!packageJson.name) { return tree; } const workspace = (0, utility_1.getWorkspaceConfig)(tree, angularJsonFile); if (!workspace) { context.logger.error('No workspace found'); return tree; } return (0, utility_1.writeAngularJson)(tree, (0, utility_1.registerCollectionSchematics)(workspace, packageJson.name), angularJsonFile); }; } /** * Setup schematics default params in angular.json and per project * @param schematicsDefaultParams default params to setup by schematic * @param projectName The name of the project on which to add the schematics * @param overrideValue Define if the given value should override the one already defined in the workspace */ function setupSchematicsParamsForProject(schematicsDefaultParams, projectName, overrideValue = false) { return (tree, context) => { const workspace = (0, utility_1.getWorkspaceConfig)(tree); if (!workspace) { context.logger.error('No workspace found'); return tree; } Object.entries(schematicsDefaultParams).forEach(([schematicName, defaultParams]) => { workspace.schematics ||= {}; workspace.schematics[schematicName] = overrideValue ? { ...workspace.schematics[schematicName], ...defaultParams } : { ...defaultParams, ...workspace.schematics[schematicName] }; }); if (projectName && workspace.projects[projectName]) { const project = workspace.projects[projectName]; Object.entries(schematicsDefaultParams).forEach(([schematicName, defaultParams]) => { project.schematics ||= {}; if (project.schematics[schematicName]) { project.schematics[schematicName] = overrideValue ? { ...project.schematics[schematicName], ...defaultParams } : { ...defaultParams, ...project.schematics[schematicName] }; } }); } return (0, utility_1.writeAngularJson)(tree, workspace); }; } //# sourceMappingURL=schematics-register.js.map