UNPKG

@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.

65 lines 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ngGenerateFactsService = void 0; const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("node:path")); const strings_1 = require("@angular-devkit/core/src/utils/strings"); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@o3r/schematics"); /** * Generate the facts service * @param options */ function ngGenerateFactsServiceFn(options) { const generateFiles = () => { const name = (0, strings_1.dasherize)(options.name); const serviceFolderPath = path.posix.join(options.path, name); const servicePath = path.posix.join(serviceFolderPath, `${name}-facts.service.ts`); const factsInterfaceName = `${(0, strings_1.classify)(name)}Facts`; return (0, schematics_1.chain)([ (0, schematics_1.externalSchematic)('@schematics/angular', 'service', { project: options.projectName, path: serviceFolderPath, flat: true, name: factsInterfaceName, skipTests: true, type: 'service' }), (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./templates'), [ (0, schematics_1.template)({ name, factsInterfaceName }), (0, schematics_1.renameTemplateFiles)(), (0, schematics_1.move)(serviceFolderPath) ]), schematics_1.MergeStrategy.Overwrite), (0, schematics_2.addImportsRule)(servicePath, [ { from: '@o3r/rules-engine', importNames: ['FactsService', 'RulesEngineService'] }, { from: `./${name}.facts`, importNames: [factsInterfaceName] } ]), (t) => { const serviceText = t.readText(servicePath); t.overwrite(servicePath, serviceText .replace('constructor() { }', 'public facts = {};') .replace('Service {', `Service extends FactsService<${factsInterfaceName}> {`)); return t; } ]); }; return (0, schematics_1.chain)([ generateFiles, options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)() ]); } /** * Generate the facts service * @param options */ exports.ngGenerateFactsService = (0, schematics_2.createOtterSchematic)(ngGenerateFactsServiceFn); //# sourceMappingURL=index.js.map