@o3r/rules-engine 11.1.0-prerelease.40 → 11.1.0-prerelease.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/rules-engine",
3
- "version": "11.1.0-prerelease.40",
3
+ "version": "11.1.0-prerelease.42",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -49,10 +49,10 @@
49
49
  "@ngrx/entity": "~18.0.0",
50
50
  "@ngrx/store": "~18.0.0",
51
51
  "@ngx-translate/core": "~15.0.0",
52
- "@o3r/core": "^11.1.0-prerelease.40",
53
- "@o3r/extractors": "^11.1.0-prerelease.40",
54
- "@o3r/logger": "^11.1.0-prerelease.40",
55
- "@o3r/schematics": "^11.1.0-prerelease.40",
52
+ "@o3r/core": "^11.1.0-prerelease.42",
53
+ "@o3r/extractors": "^11.1.0-prerelease.42",
54
+ "@o3r/logger": "^11.1.0-prerelease.42",
55
+ "@o3r/schematics": "^11.1.0-prerelease.42",
56
56
  "@schematics/angular": "~18.0.0",
57
57
  "globby": "^11.1.0",
58
58
  "jasmine": "^5.0.0",
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA2FtD;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,qBAAqB,KAAG,IAGtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAO9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAqHtD;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,qBAAqB,KAAG,IAGtD,CAAC"}
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ngAdd = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const schematics_1 = require("@angular-devkit/schematics");
6
- const cms_adapter_1 = require("../cms-adapter");
6
+ const utility_1 = require("@schematics/angular/utility");
7
7
  const path = tslib_1.__importStar(require("node:path"));
8
8
  const fs = tslib_1.__importStar(require("node:fs"));
9
+ const ts = tslib_1.__importStar(require("typescript"));
10
+ const cms_adapter_1 = require("../cms-adapter");
9
11
  const devtools_registration_1 = require("./helpers/devtools-registration");
12
+ const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
10
13
  const devDependenciesToInstall = [
11
14
  'jsonpath-plus'
12
15
  ];
@@ -16,6 +19,19 @@ If the error is related to missing @o3r dependencies you need to install '@o3r/c
16
19
  Otherwise, use the error message as guidance.`);
17
20
  throw reason;
18
21
  };
22
+ const updateAppModuleOrAppConfig = (projectName) => async (tree, context) => {
23
+ const { getAppModuleFilePath } = await Promise.resolve().then(() => tslib_1.__importStar(require('@o3r/schematics')));
24
+ const moduleFilePath = getAppModuleFilePath(tree, context, projectName);
25
+ if (!moduleFilePath) {
26
+ return () => tree;
27
+ }
28
+ const sourceFileContent = tree.readText(moduleFilePath);
29
+ const sourceFile = ts.createSourceFile(moduleFilePath, sourceFileContent, ts.ScriptTarget.ES2015, true);
30
+ if ((0, ast_utils_1.isImported)(sourceFile, 'RulesEngineRunnerModule', '@o3r/rules-engine')) {
31
+ return () => tree;
32
+ }
33
+ return (0, utility_1.addRootImport)(projectName, ({ code, external }) => code `\n${external('RulesEngineRunnerModule', '@o3r/rules-engine')}.forRoot()`);
34
+ };
19
35
  /**
20
36
  * Add Otter rules-engine to an Angular Project
21
37
  * @param options
@@ -70,7 +86,8 @@ function ngAddFn(options) {
70
86
  ngAddToRun: depsInfo.o3rPeerDeps
71
87
  }),
72
88
  ...(options.enableMetadataExtract ? [(0, cms_adapter_1.updateCmsAdapter)(options)] : []),
73
- await (0, devtools_registration_1.registerDevtools)(options)
89
+ await (0, devtools_registration_1.registerDevtools)(options),
90
+ updateAppModuleOrAppConfig(options.projectName)
74
91
  ]);
75
92
  context.logger.info(`The package ${depsInfo.packageName} comes with a debug mechanism`);
76
93
  context.logger.info('Get information on https://github.com/AmadeusITGroup/otter/tree/main/docs/rules-engine/how-to-use/debug.md');
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/rules-engine-to-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAiBvF,OAAO,EAAE,gDAAgD,EAAE,MAAM,UAAU,CAAC;AAyJ5E;;;GAGG;AACH,eAAO,MAAM,gCAAgC,qEAA4E,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../schematics/rules-engine-to-component/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAQ,MAAM,4BAA4B,CAAC;AAmBrE,OAAO,EAAE,gDAAgD,EAAE,MAAM,UAAU,CAAC;AAqL5E;;;GAGG;AACH,eAAO,MAAM,gCAAgC,qEAA4E,CAAC"}
@@ -28,83 +28,102 @@ const checkRulesEngine = (componentPath) => (tree) => {
28
28
  * @param options
29
29
  */
30
30
  function ngGenerateRulesEngineToComponentFn(options) {
31
- const generateFiles = (tree, _context) => {
32
- const componentPath = options.path;
33
- const projectName = options.projectName || (0, schematics_2.getLibraryNameFromPath)(componentPath) || '';
34
- const imports = [
35
- {
36
- from: '@angular/core',
37
- importNames: ['inject', 'OnInit', 'OnDestroy']
38
- },
39
- {
40
- from: '@o3r/core',
41
- importNames: ['computeItemIdentifier']
42
- },
43
- {
44
- from: '@o3r/rules-engine',
45
- importNames: ['RulesEngineRunnerService']
46
- }
47
- ];
48
- let sourceFile = ts.createSourceFile(componentPath, tree.readText(componentPath), ts.ScriptTarget.ES2020, true);
49
- const recorder = tree.beginUpdate(componentPath);
50
- const changes = imports.reduce((acc, { importNames, from }) => acc.concat(importNames.map((importName) => (0, ast_utils_1.insertImport)(sourceFile, componentPath, importName, from))), []);
51
- (0, change_1.applyToUpdateRecorder)(recorder, changes);
52
- tree.commitUpdate(recorder);
53
- sourceFile = ts.createSourceFile(componentPath, tree.readText(componentPath), ts.ScriptTarget.ES2020, true);
54
- const result = ts.transform(sourceFile, [
55
- (ctx) => (rootNode) => {
56
- const { factory } = ctx;
57
- const visit = (node) => {
58
- if (ts.isClassDeclaration(node)) {
59
- const implementsClauses = node.heritageClauses?.find((heritageClause) => heritageClause.token === ts.SyntaxKind.ImplementsKeyword);
60
- const interfaceToImplements = (0, schematics_2.generateImplementsExpressionWithTypeArguments)('OnInit, OnDestroy');
61
- const deduplicateHeritageClauses = (clauses) => clauses.filter((h, i) => !clauses.slice(i + 1).some((h2) => h2.kind === h.kind && h2.expression.escapedText === h.expression.escapedText));
62
- const newImplementsClauses = implementsClauses
63
- ? factory.updateHeritageClause(implementsClauses, deduplicateHeritageClauses([...implementsClauses.types, ...interfaceToImplements]))
64
- : factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [...interfaceToImplements]);
65
- const heritageClauses = Array.from(node.heritageClauses ?? [])
66
- .filter((h) => h.token !== ts.SyntaxKind.ImplementsKeyword)
67
- .concat(newImplementsClauses);
68
- const newModifiers = []
69
- .concat(ts.getDecorators(node) || [])
70
- .concat(ts.getModifiers(node) || []);
71
- const propertiesToAdd = (0, schematics_2.generateClassElementsFromString)(`
72
- private readonly componentName = computeItemIdentifier('${node.name?.escapedText}', '${projectName}');
73
- private readonly rulesEngineService = inject(RulesEngineRunnerService, {optional: true});
74
- `);
75
- const newNgOnInit = (0, schematics_2.getSimpleUpdatedMethod)(node, factory, 'ngOnInit', (0, schematics_2.generateBlockStatementsFromString)(`
76
- if (this.rulesEngineService) {
77
- this.rulesEngineService.enableRuleSetFor(this.componentName);
78
- }
79
- `));
80
- const newNgOnDestroy = (0, schematics_2.getSimpleUpdatedMethod)(node, factory, 'ngOnDestroy', (0, schematics_2.generateBlockStatementsFromString)(`
81
- if (this.rulesEngineService) {
82
- this.rulesEngineService.disableRuleSetFor(this.componentName);
83
- }
84
- `));
85
- const newMembers = node.members
86
- .filter((classElement) => !((0, schematics_2.findMethodByName)('ngOnInit')(classElement) || (0, schematics_2.findMethodByName)('ngOnDestroy')(classElement)))
87
- .concat(propertiesToAdd, newNgOnInit, newNgOnDestroy)
88
- .sort(schematics_2.sortClassElement);
89
- return factory.updateClassDeclaration(node, newModifiers, node.name, node.typeParameters, heritageClauses, newMembers);
90
- }
91
- return ts.visitEachChild(node, visit, ctx);
92
- };
93
- return ts.visitNode(rootNode, visit);
94
- },
95
- schematics_2.fixStringLiterals
96
- ]);
97
- const printer = ts.createPrinter({
98
- removeComments: false,
99
- newLine: ts.NewLineKind.LineFeed
100
- });
101
- tree.overwrite(componentPath, printer.printFile(result.transformed[0]));
102
- return tree;
103
- };
31
+ const componentPath = options.path;
104
32
  return (0, schematics_1.chain)([
105
- checkRulesEngine(options.path),
106
- generateFiles,
107
- options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)()
33
+ checkRulesEngine(componentPath),
34
+ (tree) => {
35
+ const { standalone } = (0, schematics_2.getO3rComponentInfoOrThrowIfNotFound)(tree, componentPath);
36
+ const generateFiles = () => {
37
+ const projectName = options.projectName || (0, schematics_2.getLibraryNameFromPath)(componentPath) || '';
38
+ const imports = [
39
+ {
40
+ from: '@angular/core',
41
+ importNames: ['inject', 'OnInit', 'OnDestroy']
42
+ },
43
+ {
44
+ from: '@o3r/core',
45
+ importNames: ['computeItemIdentifier']
46
+ },
47
+ {
48
+ from: '@o3r/rules-engine',
49
+ importNames: ['RulesEngineRunnerService',
50
+ ...(standalone ? ['RulesEngineRunnerModule'] : [])
51
+ ]
52
+ }
53
+ ];
54
+ let sourceFile = ts.createSourceFile(componentPath, tree.readText(componentPath), ts.ScriptTarget.ES2020, true);
55
+ const recorder = tree.beginUpdate(componentPath);
56
+ const changes = imports.reduce((acc, { importNames, from }) => acc.concat(importNames.map((importName) => (0, ast_utils_1.insertImport)(sourceFile, componentPath, importName, from))), []);
57
+ (0, change_1.applyToUpdateRecorder)(recorder, changes);
58
+ tree.commitUpdate(recorder);
59
+ sourceFile = ts.createSourceFile(componentPath, tree.readText(componentPath), ts.ScriptTarget.ES2020, true);
60
+ const result = ts.transform(sourceFile, [
61
+ ...(standalone
62
+ ? [(0, schematics_2.addImportsIntoComponentDecoratorTransformerFactory)(['RulesEngineRunnerModule'])]
63
+ : []),
64
+ (ctx) => (rootNode) => {
65
+ const { factory } = ctx;
66
+ const visit = (node) => {
67
+ if (ts.isClassDeclaration(node)) {
68
+ const implementsClauses = node.heritageClauses?.find((heritageClause) => heritageClause.token === ts.SyntaxKind.ImplementsKeyword);
69
+ const interfaceToImplements = (0, schematics_2.generateImplementsExpressionWithTypeArguments)('OnInit, OnDestroy');
70
+ const deduplicateHeritageClauses = (clauses) => clauses.filter((h, i) => !clauses.slice(i + 1).some((h2) => h2.kind === h.kind && h2.expression.escapedText === h.expression.escapedText));
71
+ const newImplementsClauses = implementsClauses
72
+ ? factory.updateHeritageClause(implementsClauses, deduplicateHeritageClauses([...implementsClauses.types, ...interfaceToImplements]))
73
+ : factory.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [...interfaceToImplements]);
74
+ const heritageClauses = Array.from(node.heritageClauses ?? [])
75
+ .filter((h) => h.token !== ts.SyntaxKind.ImplementsKeyword)
76
+ .concat(newImplementsClauses);
77
+ const newModifiers = []
78
+ .concat(ts.getDecorators(node) || [])
79
+ .concat(ts.getModifiers(node) || []);
80
+ const propertiesToAdd = (0, schematics_2.generateClassElementsFromString)(`
81
+ private readonly componentName = computeItemIdentifier('${node.name?.escapedText}', '${projectName}');
82
+ private readonly rulesEngineService = inject(RulesEngineRunnerService, {optional: true});
83
+ `);
84
+ const newNgOnInit = (0, schematics_2.getSimpleUpdatedMethod)(node, factory, 'ngOnInit', (0, schematics_2.generateBlockStatementsFromString)(`
85
+ if (this.rulesEngineService) {
86
+ this.rulesEngineService.enableRuleSetFor(this.componentName);
87
+ }
88
+ `));
89
+ const newNgOnDestroy = (0, schematics_2.getSimpleUpdatedMethod)(node, factory, 'ngOnDestroy', (0, schematics_2.generateBlockStatementsFromString)(`
90
+ if (this.rulesEngineService) {
91
+ this.rulesEngineService.disableRuleSetFor(this.componentName);
92
+ }
93
+ `));
94
+ const newMembers = node.members
95
+ .filter((classElement) => !((0, schematics_2.findMethodByName)('ngOnInit')(classElement) || (0, schematics_2.findMethodByName)('ngOnDestroy')(classElement)))
96
+ .concat(propertiesToAdd, newNgOnInit, newNgOnDestroy)
97
+ .sort(schematics_2.sortClassElement);
98
+ return factory.updateClassDeclaration(node, newModifiers, node.name, node.typeParameters, heritageClauses, newMembers);
99
+ }
100
+ return ts.visitEachChild(node, visit, ctx);
101
+ };
102
+ return ts.visitNode(rootNode, visit);
103
+ },
104
+ schematics_2.fixStringLiterals
105
+ ]);
106
+ const printer = ts.createPrinter({
107
+ removeComments: false,
108
+ newLine: ts.NewLineKind.LineFeed
109
+ });
110
+ tree.overwrite(componentPath, printer.printFile(result.transformed[0]));
111
+ return tree;
112
+ };
113
+ const updateModuleRule = () => {
114
+ const moduleFilePath = options.path.replace(/component.ts$/, 'module.ts');
115
+ const moduleSourceFile = ts.createSourceFile(moduleFilePath, tree.readText(moduleFilePath), ts.ScriptTarget.ES2020, true);
116
+ const recorder = tree.beginUpdate(moduleFilePath);
117
+ const changes = (0, ast_utils_1.addImportToModule)(moduleSourceFile, moduleFilePath, 'RulesEngineRunnerModule', '@o3r/rules-engine');
118
+ (0, change_1.applyToUpdateRecorder)(recorder, changes);
119
+ tree.commitUpdate(recorder);
120
+ };
121
+ return (0, schematics_1.chain)([
122
+ standalone ? schematics_1.noop : updateModuleRule,
123
+ generateFiles,
124
+ options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)()
125
+ ]);
126
+ }
108
127
  ]);
109
128
  }
110
129
  /**
@@ -2,8 +2,8 @@ import type { SchematicOptionObject } from '@o3r/schematics';
2
2
  export interface NgGenerateRulesEngineToComponentSchematicsSchema extends SchematicOptionObject {
3
3
  /** Project name */
4
4
  projectName?: string | undefined;
5
- /** Component Folder */
6
- path?: string | undefined;
5
+ /** Path to the component */
6
+ path: string;
7
7
  /** Skip the linter process */
8
8
  skipLinter: boolean;
9
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/rules-engine-to-component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,gDAAiD,SAAQ,qBAAqB;IAC7F,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1B,8BAA8B;IAC9B,UAAU,EAAE,OAAO,CAAC;CACrB"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../schematics/rules-engine-to-component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,gDAAiD,SAAQ,qBAAqB;IAC7F,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IAEb,8BAA8B;IAC9B,UAAU,EAAE,OAAO,CAAC;CACrB"}
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "path": {
15
15
  "type": "string",
16
- "description": "Directory containing the component"
16
+ "description": "Path to the component"
17
17
  },
18
18
  "skipLinter": {
19
19
  "type": "boolean",