@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
82 lines • 3.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateCmsAdapter = void 0;
const tslib_1 = require("tslib");
const path = tslib_1.__importStar(require("node:path"));
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@o3r/schematics");
/**
* Update CMS adapter tools
* @param options @see RuleFactory.options
* @param options.projectName
*/
function updateCmsAdapterFn(options) {
if (!options.projectName) {
return schematics_1.noop;
}
/**
* Add cms extractors builder into the angular.json
* @param tree
* @param context
*/
const editAngularJson = (tree, context) => {
const workspace = (0, schematics_2.getWorkspaceConfig)(tree);
const workspaceProject = options.projectName ? workspace?.projects[options.projectName] : undefined;
if (!workspace || !workspaceProject) {
context.logger.error('No project detected, the extractors will not be added');
return tree;
}
if (!workspaceProject.architect) {
workspaceProject.architect = {};
}
workspaceProject.architect['extract-components'] ||= {
builder: '@o3r/components:extractor',
options: {
tsConfig: path.join(workspaceProject?.root || '', 'tsconfig.cms.json'),
libraries: []
}
};
workspaceProject.architect['check-config-migration-metadata'] ||= {
builder: '@o3r/components:check-config-migration-metadata',
options: {
migrationDataPath: 'migration-scripts/dist/MIGRATION-*.json'
}
};
workspace.projects[options.projectName] = workspaceProject;
tree.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
return tree;
};
/**
* Add cms extractors scripts into the package.json
* @param tree
* @param context
*/
const addExtractorsScripts = (tree, context) => {
const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined;
if (!workspaceProject) {
context.logger.error('No package detected, the extractor scripts will not be added');
return tree;
}
const packageJson = (0, schematics_2.readPackageJson)(tree, workspaceProject);
const packageManagerRunner = (0, schematics_2.getPackageManagerRunner)((0, schematics_2.getWorkspaceConfig)(tree));
packageJson.scripts ||= {};
packageJson.scripts['cms-adapters:components'] ||= `ng run ${options.projectName}:extract-components`;
packageJson.scripts['cms-adapters:metadata'] = Object.keys(packageJson.scripts)
.filter((s) => /^cms-adapters:(?!metadata$)/.test(s))
.map((s) => `${packageManagerRunner} ${s}`)
.join(' && ');
tree.overwrite(`${workspaceProject.root}/package.json`, JSON.stringify(packageJson, null, 2));
return tree;
};
return (0, schematics_1.chain)([
addExtractorsScripts,
editAngularJson
]);
}
/**
* Update CMS adapter tools
* @param options @see RuleFactory.options
* @param options.projectName
*/
exports.updateCmsAdapter = (0, schematics_2.createOtterSchematic)(updateCmsAdapterFn);
//# sourceMappingURL=index.js.map