@o3r/schematics 9.6.0-alpha.40 → 9.6.0-alpha.42

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/schematics",
3
- "version": "9.6.0-alpha.40",
3
+ "version": "9.6.0-alpha.42",
4
4
  "description": "Schematics module of the Otter framework",
5
5
  "main": "./src/public_api.js",
6
6
  "typings": "./src/public_api.d.ts",
@@ -67,9 +67,9 @@
67
67
  "@nx/jest": "~16.10.0",
68
68
  "@nx/js": "~16.10.0",
69
69
  "@nx/linter": "~16.10.0",
70
- "@o3r/build-helpers": "^9.6.0-alpha.40",
71
- "@o3r/dev-tools": "^9.6.0-alpha.40",
72
- "@o3r/eslint-plugin": "^9.6.0-alpha.40",
70
+ "@o3r/build-helpers": "^9.6.0-alpha.42",
71
+ "@o3r/dev-tools": "^9.6.0-alpha.42",
72
+ "@o3r/eslint-plugin": "^9.6.0-alpha.42",
73
73
  "@schematics/angular": "~16.2.0",
74
74
  "@types/jest": "~29.5.2",
75
75
  "@types/node": "^18.0.0",
@@ -10,6 +10,11 @@ export interface DevtoolRegisterOptions {
10
10
  /** Name of the devtools service (if available) */
11
11
  serviceName?: string;
12
12
  }
13
+ /**
14
+ * Rule to inject a service after `bootstrapModule` or `bootstrapApplication`
15
+ * @param options
16
+ */
17
+ export declare const injectServiceInMain: (options: DevtoolRegisterOptions) => Rule;
13
18
  /**
14
19
  * Register Devtools to the application
15
20
  * @param tree
@@ -1 +1 @@
1
- {"version":3,"file":"devtools-registration.d.ts","sourceRoot":"","sources":["../../../../src/rule-factories/dev-tools/devtools-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAOzD,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAqCD;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,YAAa,sBAAsB,KAAG,IAqB/E,CAAC"}
1
+ {"version":3,"file":"devtools-registration.d.ts","sourceRoot":"","sources":["../../../../src/rule-factories/dev-tools/devtools-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAQzD,qDAAqD;AACrD,MAAM,WAAW,sBAAsB;IACrC,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAqCD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,YAAa,sBAAsB,KAAG,IAoDrE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,YAAa,sBAAsB,KAAG,IAsB/E,CAAC"}
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerDevtoolsToApplication = void 0;
3
+ exports.registerDevtoolsToApplication = exports.injectServiceInMain = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
5
  const ts = require("typescript");
6
6
  const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
7
7
  const utility_1 = require("../../utility");
8
8
  const utility_2 = require("../../utility");
9
+ const change_1 = require("@schematics/angular/utility/change");
9
10
  const registerModule = (options) => (tree, context) => {
10
11
  const moduleFilePath = (0, utility_1.getAppModuleFilePath)(tree, context, options.projectName);
11
12
  if (!moduleFilePath) {
@@ -24,6 +25,44 @@ const registerModule = (options) => (tree, context) => {
24
25
  tree.commitUpdate(recorder);
25
26
  return tree;
26
27
  };
28
+ /**
29
+ * Rule to inject a service after `bootstrapModule` or `bootstrapApplication`
30
+ * @param options
31
+ */
32
+ const injectServiceInMain = (options) => (tree, context) => {
33
+ if (!options.serviceName) {
34
+ return tree;
35
+ }
36
+ const mainFilePath = (0, utility_1.getMainFilePath)(tree, context, options.projectName);
37
+ if (!mainFilePath || !tree.exists(mainFilePath)) {
38
+ return tree;
39
+ }
40
+ const content = tree.readText(mainFilePath);
41
+ if (content.includes(`inject(${options.serviceName})`)) {
42
+ return tree;
43
+ }
44
+ const match = /bootstrap(Module|Application)\([^)]*\)/.exec(content);
45
+ if (!match) {
46
+ return tree;
47
+ }
48
+ const sourceFile = ts.createSourceFile(mainFilePath, content, ts.ScriptTarget.ES2015, true);
49
+ const recorder = tree.beginUpdate(mainFilePath);
50
+ const changes = [];
51
+ if (!(0, ast_utils_1.isImported)(sourceFile, options.serviceName, options.packageName)) {
52
+ changes.push((0, ast_utils_1.insertImport)(sourceFile, mainFilePath, options.serviceName, options.packageName));
53
+ }
54
+ if (!(0, ast_utils_1.isImported)(sourceFile, 'inject', '@angular/core')) {
55
+ changes.push((0, ast_utils_1.insertImport)(sourceFile, mainFilePath, 'inject', '@angular/core'));
56
+ }
57
+ if (!(0, ast_utils_1.isImported)(sourceFile, 'runInInjectionContext', '@angular/core')) {
58
+ changes.push((0, ast_utils_1.insertImport)(sourceFile, mainFilePath, 'runInInjectionContext', '@angular/core'));
59
+ }
60
+ changes.push(new change_1.InsertChange(mainFilePath, match.index + match[0].length, `\n .then((m) => { runInInjectionContext(m.injector, () => { inject(${options.serviceName}); }); return m; })`));
61
+ (0, change_1.applyToUpdateRecorder)(recorder, changes);
62
+ tree.commitUpdate(recorder);
63
+ return tree;
64
+ };
65
+ exports.injectServiceInMain = injectServiceInMain;
27
66
  /**
28
67
  * Register Devtools to the application
29
68
  * @param tree
@@ -43,6 +82,7 @@ const registerDevtoolsToApplication = (options) => (tree, context) => {
43
82
  }
44
83
  return (0, schematics_1.chain)([
45
84
  registerModule(options),
85
+ (0, exports.injectServiceInMain)(options),
46
86
  (_, ctx) => ctx.logger.info(`The devtools module ${options.moduleName} has been registered and automatically activated${options.serviceName ? ', its activation can be driven via ' + options.serviceName : ''}.`)
47
87
  ])(tree, context);
48
88
  };
@@ -1 +1 @@
1
- {"version":3,"file":"devtools-registration.js","sourceRoot":"","sources":["../../../../src/rule-factories/dev-tools/devtools-registration.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AACzD,iCAAiC;AACjC,qEAAyF;AACzF,2CAAwG;AAExG,2CAAkF;AAclF,MAAM,cAAc,GAAG,CAAC,OAA+B,EAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;IAClF,MAAM,cAAc,GAAG,IAAA,8BAAoB,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAChF,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,CAAC;IAChE,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,cAAc,EACd,iBAAiB,EACjB,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;IAEF,IAAI,IAAA,sBAAU,EAAC,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE;QACnE,OAAO,IAAI,CAAC;KACb;IAED,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,iBAAiB,GAAG,IAAA,gCAAoB,EAAC,UAAU,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;IACxF,MAAM,WAAW,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,iBAA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C,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CACzB,uBAAuB,OAAO,CAAC,UAAU,mDAAmD,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,qCAAqC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,CACtL;KACF,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpB,CAAC,CAAC;AArBW,QAAA,6BAA6B,iCAqBxC"}
1
+ {"version":3,"file":"devtools-registration.js","sourceRoot":"","sources":["../../../../src/rule-factories/dev-tools/devtools-registration.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AACzD,iCAAiC;AACjC,qEAAuG;AACvG,2CAAyH;AAEzH,2CAAkF;AAClF,+DAAyF;AAczF,MAAM,cAAc,GAAG,CAAC,OAA+B,EAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;IAClF,MAAM,cAAc,GAAG,IAAA,8BAAoB,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAChF,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,CAAC;IAChE,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,cAAc,EACd,iBAAiB,EACjB,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;IAEF,IAAI,IAAA,sBAAU,EAAC,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE;QACnE,OAAO,IAAI,CAAC;KACb;IAED,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,iBAAiB,GAAG,IAAA,gCAAoB,EAAC,UAAU,EAAE,UAAU,EAAE,eAAe,CAAC,CAA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