@o3r/rules-engine
Version:
This module provides a rule engine that can be executed on your Otter application to customize your application (translations, placeholders and configs) based on a json file generated by your CMS.
84 lines • 3.55 kB
JavaScript
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 utility_1 = require("@schematics/angular/utility");
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
const ts = tslib_1.__importStar(require("typescript"));
const cms_adapter_1 = require("../cms-adapter");
const devtools_registration_1 = require("./helpers/devtools-registration");
/**
* List of external dependencies to be added to the project as peer dependencies
*/
const dependenciesToInstall = [
'@angular/common',
'@angular/platform-browser-dynamic',
'@angular/core',
'@angular/forms',
'@ngrx/effects',
'@ngrx/entity',
'@ngrx/store',
'@ngx-translate/core',
'jsonpath-plus',
'rxjs'
];
/**
* List of external dependencies to be added to the project as dev dependencies
*/
const devDependenciesToInstall = [
'@angular-devkit/architect'
];
const updateAppModuleOrAppConfig = (projectName) => (tree, context) => {
const moduleFilePath = (0, schematics_2.getAppModuleFilePath)(tree, context, projectName);
if (!moduleFilePath) {
return () => tree;
}
const sourceFileContent = tree.readText(moduleFilePath);
const sourceFile = ts.createSourceFile(moduleFilePath, sourceFileContent, ts.ScriptTarget.ES2015, true);
if ((0, ast_utils_1.isImported)(sourceFile, 'RulesEngineRunnerModule', '@o3r/rules-engine')) {
return () => tree;
}
return (0, utility_1.addRootImport)(projectName, ({ code, external }) => code `\n${external('RulesEngineRunnerModule', '@o3r/rules-engine')}.forRoot()`);
};
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));
/**
* Add Otter rules-engine to an Angular Project
* @param options
*/
function ngAddFn(options) {
const schematicsDefaultOptions = {
useRulesEngine: undefined
};
/* ng add rules */
return (0, schematics_1.chain)([
(_, context) => {
context.logger.info(`The package @o3r/rules-engine comes with a debug mechanism`);
context.logger.info('Get information on https://github.com/AmadeusITGroup/otter/tree/main/docs/rules-engine/how-to-use/debug.md');
},
(0, schematics_2.registerPackageCollectionSchematics)(packageJson),
(0, schematics_2.setupSchematicsParamsForProject)({
'@o3r/core:component': schematicsDefaultOptions,
'@o3r/core:component-container': schematicsDefaultOptions
}, options.projectName),
(0, schematics_2.ngAddDependenciesRule)(options, packageJsonPath, {
dependenciesToInstall,
devDependenciesToInstall,
additionalNgAddToRun: options.enableMetadataExtract ? ['@o3r/extractors'] : undefined
}),
...(options.enableMetadataExtract ? [(0, cms_adapter_1.updateCmsAdapter)(options)] : []),
(0, devtools_registration_1.registerDevtools)(options),
updateAppModuleOrAppConfig(options.projectName)
]);
}
/**
* Add Otter rules-engine to an Angular Project
* @param options
*/
const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options);
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map
;