@abp/ng.schematics 9.2.0-rc.2 → 9.2.0-rc.3

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.
Files changed (117) hide show
  1. package/commands/change-theme/index.d.ts +7 -3
  2. package/commands/change-theme/index.js +264 -70
  3. package/commands/change-theme/index.js.map +1 -1
  4. package/commands/change-theme/style-map.d.ts +1 -0
  5. package/commands/change-theme/style-map.js +90 -9
  6. package/commands/change-theme/style-map.js.map +1 -1
  7. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/.eslintrc.json.template +44 -0
  8. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/config/ng-package.json.template +7 -0
  9. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/config/src/enums/index.ts.template +1 -0
  10. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/config/src/enums/route-names.ts.template +3 -0
  11. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/config/src/providers/index.ts.template +1 -0
  12. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/config/src/providers/route.provider.ts.template +30 -0
  13. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/config/src/public-api.ts.template +2 -0
  14. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/karma.conf.js.template +44 -0
  15. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/ng-package.json.template +7 -0
  16. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/package.json.template +11 -0
  17. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/src/lib/__libraryName@kebab__.component.ts.template +11 -0
  18. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/src/lib/__libraryName@kebab__.routes.ts.template +9 -0
  19. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/src/lib/index.ts.template +1 -0
  20. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/src/public-api.ts.template +4 -0
  21. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/src/test.ts.template +26 -0
  22. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/tsconfig.lib.json.template +20 -0
  23. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/tsconfig.lib.prod.json.template +10 -0
  24. package/commands/create-lib/files-package-standalone/__libraryName@kebab__/tsconfig.spec.json.template +17 -0
  25. package/commands/create-lib/files-secondary-entrypoint-standalone/__libraryName@kebab__/ng-package.json.template +6 -0
  26. package/commands/create-lib/files-secondary-entrypoint-standalone/__libraryName@kebab__/src/lib/__target@kebab__-__libraryName@kebab__.ts.template +7 -0
  27. package/commands/create-lib/files-secondary-entrypoint-standalone/__libraryName@kebab__/src/lib/index.ts.template +1 -0
  28. package/commands/create-lib/files-secondary-entrypoint-standalone/__libraryName@kebab__/src/public-api.ts.template +1 -0
  29. package/commands/create-lib/index.d.ts +7 -3
  30. package/commands/create-lib/index.js +161 -58
  31. package/commands/create-lib/index.js.map +1 -1
  32. package/commands/create-lib/models/generate-lib-schema.d.ts +8 -1
  33. package/commands/create-lib/models/generate-lib-schema.js +6 -0
  34. package/commands/create-lib/models/generate-lib-schema.js.map +1 -1
  35. package/commands/create-lib/schema.json +13 -9
  36. package/package.json +1 -1
  37. package/utils/angular/add-declaration-to-ng-module.d.ts +2 -1
  38. package/utils/angular/add-declaration-to-ng-module.js +4 -4
  39. package/utils/angular/add-declaration-to-ng-module.js.map +1 -1
  40. package/utils/angular/ast-utils.d.ts +18 -8
  41. package/utils/angular/ast-utils.js +70 -41
  42. package/utils/angular/ast-utils.js.map +1 -1
  43. package/utils/angular/change.d.ts +1 -1
  44. package/utils/angular/change.js +4 -4
  45. package/utils/angular/change.js.map +1 -1
  46. package/utils/angular/dependencies.d.ts +1 -1
  47. package/utils/angular/dependencies.js +1 -1
  48. package/utils/angular/dependency.d.ts +1 -1
  49. package/utils/angular/dependency.js +2 -2
  50. package/utils/angular/dependency.js.map +1 -1
  51. package/utils/angular/eol.d.ts +8 -0
  52. package/utils/angular/eol.js +24 -0
  53. package/utils/angular/eol.js.map +1 -0
  54. package/utils/angular/find-module.d.ts +1 -1
  55. package/utils/angular/find-module.js +5 -5
  56. package/utils/angular/find-module.js.map +1 -1
  57. package/utils/angular/generate-from-files.d.ts +3 -1
  58. package/utils/angular/generate-from-files.js +15 -2
  59. package/utils/angular/generate-from-files.js.map +1 -1
  60. package/utils/angular/index.d.ts +1 -0
  61. package/utils/angular/index.js +1 -0
  62. package/utils/angular/index.js.map +1 -1
  63. package/utils/angular/json-file.d.ts +3 -2
  64. package/utils/angular/json-file.js +6 -3
  65. package/utils/angular/json-file.js.map +1 -1
  66. package/utils/angular/ng-ast-utils.d.ts +2 -2
  67. package/utils/angular/ng-ast-utils.js +19 -7
  68. package/utils/angular/ng-ast-utils.js.map +1 -1
  69. package/utils/angular/parse-name.d.ts +1 -1
  70. package/utils/angular/parse-name.js +1 -1
  71. package/utils/angular/paths.d.ts +1 -1
  72. package/utils/angular/paths.js +4 -7
  73. package/utils/angular/paths.js.map +1 -1
  74. package/utils/angular/project-targets.d.ts +3 -1
  75. package/utils/angular/project-targets.js +9 -2
  76. package/utils/angular/project-targets.js.map +1 -1
  77. package/utils/angular/standalone/app_component.d.ts +29 -0
  78. package/utils/angular/standalone/app_component.js +108 -0
  79. package/utils/angular/standalone/app_component.js.map +1 -0
  80. package/utils/angular/standalone/app_config.d.ts +23 -0
  81. package/utils/angular/standalone/app_config.js +90 -0
  82. package/utils/angular/standalone/app_config.js.map +1 -0
  83. package/utils/angular/standalone/code_block.d.ts +53 -0
  84. package/utils/angular/standalone/code_block.js +80 -0
  85. package/utils/angular/standalone/code_block.js.map +1 -0
  86. package/utils/angular/standalone/index.d.ts +9 -0
  87. package/utils/angular/standalone/index.js +14 -0
  88. package/utils/angular/standalone/index.js.map +1 -0
  89. package/utils/angular/standalone/rules.d.ts +45 -0
  90. package/utils/angular/standalone/rules.js +189 -0
  91. package/utils/angular/standalone/rules.js.map +1 -0
  92. package/utils/angular/standalone/util.d.ts +35 -0
  93. package/utils/angular/standalone/util.js +136 -0
  94. package/utils/angular/standalone/util.js.map +1 -0
  95. package/utils/angular/validation.d.ts +1 -1
  96. package/utils/angular/validation.js +2 -2
  97. package/utils/angular/validation.js.map +1 -1
  98. package/utils/angular/workspace-models.d.ts +12 -6
  99. package/utils/angular/workspace-models.js +11 -3
  100. package/utils/angular/workspace-models.js.map +1 -1
  101. package/utils/angular/workspace.d.ts +12 -1
  102. package/utils/angular/workspace.js +6 -6
  103. package/utils/angular/workspace.js.map +1 -1
  104. package/utils/ast.d.ts +1 -0
  105. package/utils/ast.js +6 -1
  106. package/utils/ast.js.map +1 -1
  107. package/utils/index.d.ts +2 -0
  108. package/utils/index.js +2 -0
  109. package/utils/index.js.map +1 -1
  110. package/utils/ng-module.d.ts +46 -0
  111. package/utils/ng-module.js +126 -0
  112. package/utils/ng-module.js.map +1 -0
  113. package/utils/standalone.d.ts +59 -0
  114. package/utils/standalone.js +146 -0
  115. package/utils/standalone.js.map +1 -0
  116. package/utils/workspace.js +1 -1
  117. package/utils/workspace.js.map +1 -1
@@ -0,0 +1,44 @@
1
+ {
2
+ "extends": "../../.eslintrc.json",
3
+ "ignorePatterns": [
4
+ "!**/*"
5
+ ],
6
+ "overrides": [
7
+ {
8
+ "files": [
9
+ "*.ts"
10
+ ],
11
+ "parserOptions": {
12
+ "project": [
13
+ "projects/<%= kebab(libraryName) %>/tsconfig.lib.json",
14
+ "projects/<%= kebab(libraryName) %>/tsconfig.spec.json"
15
+ ],
16
+ "createDefaultProgram": true
17
+ },
18
+ "rules": {
19
+ "@angular-eslint/directive-selector": [
20
+ "error",
21
+ {
22
+ "type": "attribute",
23
+ "prefix": "lib",
24
+ "style": "camelCase"
25
+ }
26
+ ],
27
+ "@angular-eslint/component-selector": [
28
+ "error",
29
+ {
30
+ "type": "element",
31
+ "prefix": "lib",
32
+ "style": "kebab-case"
33
+ }
34
+ ]
35
+ }
36
+ },
37
+ {
38
+ "files": [
39
+ "*.html"
40
+ ],
41
+ "rules": {}
42
+ }
43
+ ]
44
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-entrypoint.schema.json",
3
+ "dest": "../../dist/<%= kebab(libraryName) %>/config",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ export const enum e<%= pascal(libraryName) %>RouteNames {
2
+ <%= pascal(libraryName) %> = '<%= pascal(libraryName) %>',
3
+ }
@@ -0,0 +1,30 @@
1
+ import { eLayoutType, RoutesService } from '@abp/ng.core';
2
+ import { e<%= pascal(libraryName) %>RouteNames } from '../enums/route-names';
3
+ import { makeEnvironmentProviders, provideAppInitializer, inject, EnvironmentProviders } from '@angular/core';
4
+
5
+ export const <%= macro(libraryName) %>_ROUTE_PROVIDERS = [
6
+ provideAppInitializer(() => {
7
+ configureRoutes();
8
+ }),
9
+ ];
10
+
11
+ export function configureRoutes() {
12
+ const routes = inject(RoutesService);
13
+ routes.add([
14
+ {
15
+ path: '/<%= kebab(libraryName) %>',
16
+ name: e<%= pascal(libraryName) %>RouteNames.<%= pascal(libraryName) %>,
17
+ iconClass: 'fas fa-book',
18
+ layout: eLayoutType.application,
19
+ order: 3,
20
+ },
21
+ ]);
22
+ }
23
+
24
+ export const <%= macro(libraryName) %>_PROVIDERS: EnvironmentProviders[] = [
25
+ ...<%= macro(libraryName) %>_ROUTE_PROVIDERS,
26
+ ];
27
+
28
+ export function provide<%= pascal(libraryName) %>Config() {
29
+ return makeEnvironmentProviders(<%= macro(libraryName) %>_PROVIDERS);
30
+ }
@@ -0,0 +1,2 @@
1
+ export * from './enums';
2
+ export * from './providers';
@@ -0,0 +1,44 @@
1
+ // Karma configuration file, see link for more information
2
+ // https://karma-runner.github.io/1.0/config/configuration-file.html
3
+
4
+ module.exports = function (config) {
5
+ config.set({
6
+ basePath: '',
7
+ frameworks: ['jasmine', '@angular-devkit/build-angular'],
8
+ plugins: [
9
+ require('karma-jasmine'),
10
+ require('karma-chrome-launcher'),
11
+ require('karma-jasmine-html-reporter'),
12
+ require('karma-coverage'),
13
+ require('@angular-devkit/build-angular/plugins/karma')
14
+ ],
15
+ client: {
16
+ jasmine: {
17
+ // you can add configuration options for Jasmine here
18
+ // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19
+ // for example, you can disable the random execution with `random: false`
20
+ // or set a specific seed with `seed: 4321`
21
+ },
22
+ clearContext: false // leave Jasmine Spec Runner output visible in browser
23
+ },
24
+ jasmineHtmlReporter: {
25
+ suppressAll: true // removes the duplicated traces
26
+ },
27
+ coverageReporter: {
28
+ dir: require('path').join(__dirname, '../../coverage/<%= kebab(libraryName) %>'),
29
+ subdir: '.',
30
+ reporters: [
31
+ { type: 'html' },
32
+ { type: 'text-summary' }
33
+ ]
34
+ },
35
+ reporters: ['progress', 'kjhtml'],
36
+ port: 9876,
37
+ colors: true,
38
+ logLevel: config.LOG_INFO,
39
+ autoWatch: true,
40
+ browsers: ['Chrome'],
41
+ singleRun: false,
42
+ restartOnFileChange: true
43
+ });
44
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/<%= kebab(libraryName) %>",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@<%= kebab(libraryName) %>/<%= kebab(libraryName) %>",
3
+ "version": "0.0.1",
4
+ "peerDependencies": {
5
+ "@abp/ng.core": "<%= abpVersion %>",
6
+ "@abp/ng.theme.shared": "<%= abpVersion %>"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.1.0"
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ import { Component } from '@angular/core';
2
+ import {CoreModule} from "@abp/ng.core";
3
+ import {ThemeSharedModule} from "@abp/ng.theme.shared";
4
+
5
+ @Component({
6
+ standalone: true,
7
+ selector: '<%= camel(libraryName) %>-home',
8
+ template: `<h1>Lazy Loaded Test Component</h1>`,
9
+ imports: [CoreModule, ThemeSharedModule],
10
+ })
11
+ export class <%= pascal(libraryName) %>Component {}
@@ -0,0 +1,9 @@
1
+ import { Routes } from '@angular/router';
2
+
3
+ export const <%= macro(libraryName) %>_ROUTES: Routes = [
4
+ {
5
+ path: '',
6
+ loadComponent: () =>
7
+ import('./<%= kebab(libraryName) %>.component').then(m => m.<%= pascal(libraryName) %>Component),
8
+ },
9
+ ];
@@ -0,0 +1 @@
1
+ export * from './<%= kebab(libraryName) %>.routes';
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Public API Surface of my-project-name
3
+ */
4
+ export * from './lib';
@@ -0,0 +1,26 @@
1
+ // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2
+
3
+ import 'zone.js';
4
+ import 'zone.js/testing';
5
+ import { getTestBed } from '@angular/core/testing';
6
+ import {
7
+ BrowserDynamicTestingModule,
8
+ platformBrowserDynamicTesting
9
+ } from '@angular/platform-browser-dynamic/testing';
10
+
11
+ declare const require: {
12
+ context(path: string, deep?: boolean, filter?: RegExp): {
13
+ keys(): string[];
14
+ <T>(id: string): T;
15
+ };
16
+ };
17
+
18
+ // First, initialize the Angular testing environment.
19
+ getTestBed().initTestEnvironment(
20
+ BrowserDynamicTestingModule,
21
+ platformBrowserDynamicTesting()
22
+ );
23
+ // Then we find all the tests.
24
+ const context = require.context('./', true, /\.spec\.ts$/);
25
+ // And load the modules.
26
+ context.keys().map(context);
@@ -0,0 +1,20 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/lib",
6
+ "target": "es2020",
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "inlineSources": true,
10
+ "types": [],
11
+ "lib": [
12
+ "dom",
13
+ "es2018"
14
+ ]
15
+ },
16
+ "exclude": [
17
+ "src/test.ts",
18
+ "**/*.spec.ts"
19
+ ]
20
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.lib.json",
4
+ "compilerOptions": {
5
+ "declarationMap": false
6
+ },
7
+ "angularCompilerOptions": {
8
+ "compilationMode": "partial"
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/spec",
6
+ "types": [
7
+ "jasmine"
8
+ ]
9
+ },
10
+ "files": [
11
+ "src/test.ts"
12
+ ],
13
+ "include": [
14
+ "**/*.spec.ts",
15
+ "**/*.d.ts"
16
+ ]
17
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-entrypoint.schema.json",
3
+ "lib": {
4
+ "entryFile": "src/public-api.ts"
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ import { Provider } from '@angular/core';
2
+
3
+ export function provide<%= pascal(target) %><%= pascal(libraryName) %>(): Provider[] {
4
+ return [
5
+ // Add your providers here
6
+ ];
7
+ }
@@ -0,0 +1 @@
1
+ export * from './<%= kebab(target) %>-<%= kebab(libraryName) %>';
@@ -1,9 +1,13 @@
1
1
  import { Rule, Tree } from '@angular-devkit/schematics';
2
+ import * as ts from 'typescript';
3
+ import { InsertChange } from '../../utils';
2
4
  import { WorkspaceDefinition } from '../../utils/angular/workspace';
3
5
  import { GenerateLibSchema } from './models/generate-lib-schema';
4
6
  export default function (schema: GenerateLibSchema): (tree: Tree) => Promise<Rule | undefined>;
5
- export declare function addLibToWorkspaceIfNotExist(name: string, packagesDir: string): Rule;
7
+ export declare function addLibToWorkspaceIfNotExist(options: GenerateLibSchema, packagesDir: string): Rule;
6
8
  export declare function updateTsConfig(packageName: string, path: string): (host: Tree) => import("@angular-devkit/schematics/src/tree/interface").Tree | undefined;
7
9
  export declare function createLibSecondaryEntry(tree: Tree, options: GenerateLibSchema): Promise<Rule>;
8
- export declare function importConfigModuleToDefaultProjectAppModule(workspace: WorkspaceDefinition, packageName: string): (tree: Tree) => void;
9
- export declare function addRoutingToAppRoutingModule(workspace: WorkspaceDefinition, packageName: string): (tree: Tree) => void;
10
+ export declare function createLibSecondaryEntryWithStandaloneTemplate(tree: Tree, options: GenerateLibSchema): Promise<Rule>;
11
+ export declare function importConfigModuleToDefaultProjectAppModule(packageName: string, options: GenerateLibSchema): (tree: Tree) => Promise<Rule | undefined>;
12
+ export declare function addRoutingToAppRoutingModule(workspace: WorkspaceDefinition, packageName: string, options: GenerateLibSchema): Rule;
13
+ export declare function addRouteToRoutesArray(source: ts.SourceFile, arrayName: string, routeToAdd: string): InsertChange | null;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addRoutingToAppRoutingModule = exports.importConfigModuleToDefaultProjectAppModule = exports.createLibSecondaryEntry = exports.updateTsConfig = exports.addLibToWorkspaceIfNotExist = void 0;
3
+ exports.addRouteToRoutesArray = exports.addRoutingToAppRoutingModule = exports.importConfigModuleToDefaultProjectAppModule = exports.createLibSecondaryEntryWithStandaloneTemplate = exports.createLibSecondaryEntry = exports.updateTsConfig = exports.addLibToWorkspaceIfNotExist = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
5
  const ts = require("typescript");
6
6
  const core_1 = require("@angular-devkit/core");
7
7
  const utils_1 = require("../../utils");
8
8
  const generate_lib_1 = require("../../utils/angular-schematic/generate-lib");
9
9
  const cases = require("../../utils/text");
10
+ const generate_lib_schema_1 = require("./models/generate-lib-schema");
11
+ const util_1 = require("../../utils/angular/standalone/util");
10
12
  function default_1(schema) {
11
13
  return async (tree) => {
12
14
  if (schema.override || !(await checkLibExist(schema, tree))) {
@@ -36,11 +38,19 @@ function createLibrary(options) {
36
38
  return async (tree) => {
37
39
  const target = await (0, utils_1.resolveProject)(tree, options.packageName, null);
38
40
  if (!target || options.override) {
39
- if (options.isModuleTemplate) {
41
+ if (options.isSecondaryEntrypoint) {
42
+ if (options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone) {
43
+ return createLibSecondaryEntryWithStandaloneTemplate(tree, options);
44
+ }
45
+ else {
46
+ return createLibSecondaryEntry(tree, options);
47
+ }
48
+ }
49
+ if (options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Module) {
40
50
  return createLibFromModuleTemplate(tree, options);
41
51
  }
42
- if (options.isSecondaryEntrypoint) {
43
- return createLibSecondaryEntry(tree, options);
52
+ else {
53
+ return createLibFromModuleStandaloneTemplate(tree, options);
44
54
  }
45
55
  }
46
56
  else {
@@ -71,13 +81,29 @@ async function createLibFromModuleTemplate(tree, options) {
71
81
  }),
72
82
  (0, schematics_1.move)((0, core_1.normalize)(packagesDir)),
73
83
  ]),
74
- addLibToWorkspaceIfNotExist(options.packageName, packagesDir),
84
+ addLibToWorkspaceIfNotExist(options, packagesDir),
85
+ ]);
86
+ }
87
+ async function createLibFromModuleStandaloneTemplate(tree, options) {
88
+ const packagesDir = await resolvePackagesDirFromAngularJson(tree);
89
+ const packageJson = JSON.parse(tree.read('./package.json').toString());
90
+ const abpVersion = packageJson.dependencies['@abp/ng.core'];
91
+ return (0, schematics_1.chain)([
92
+ (0, utils_1.applyWithOverwrite)((0, schematics_1.url)('./files-package-standalone'), [
93
+ (0, schematics_1.applyTemplates)({
94
+ ...cases,
95
+ libraryName: options.packageName,
96
+ abpVersion,
97
+ }),
98
+ (0, schematics_1.move)((0, core_1.normalize)(packagesDir)),
99
+ ]),
100
+ addLibToWorkspaceIfNotExist(options, packagesDir),
75
101
  ]);
76
102
  }
77
- function addLibToWorkspaceIfNotExist(name, packagesDir) {
103
+ function addLibToWorkspaceIfNotExist(options, packagesDir) {
78
104
  return async (tree) => {
79
105
  const workspace = await (0, utils_1.getWorkspace)(tree);
80
- const packageName = (0, utils_1.kebab)(name);
106
+ const packageName = (0, utils_1.kebab)(options.packageName);
81
107
  const isProjectExist = workspace.projects.has(packageName);
82
108
  const projectRoot = (0, core_1.join)((0, core_1.normalize)(packagesDir), packageName);
83
109
  const pathImportLib = `${packagesDir}/${packageName}`;
@@ -89,8 +115,8 @@ function addLibToWorkspaceIfNotExist(name, packagesDir) {
89
115
  : (0, schematics_1.noop)(),
90
116
  (0, generate_lib_1.addLibToWorkspaceFile)(projectRoot, packageName),
91
117
  updateTsConfig(packageName, pathImportLib),
92
- importConfigModuleToDefaultProjectAppModule(workspace, packageName),
93
- addRoutingToAppRoutingModule(workspace, packageName),
118
+ importConfigModuleToDefaultProjectAppModule(packageName, options),
119
+ addRoutingToAppRoutingModule(workspace, packageName, options),
94
120
  ]);
95
121
  };
96
122
  }
@@ -127,67 +153,144 @@ async function createLibSecondaryEntry(tree, options) {
127
153
  ]);
128
154
  }
129
155
  exports.createLibSecondaryEntry = createLibSecondaryEntry;
130
- function importConfigModuleToDefaultProjectAppModule(workspace, packageName) {
131
- return (tree) => {
132
- const projectName = (0, utils_1.readWorkspaceSchema)(tree).defaultProject || (0, utils_1.getFirstApplication)(tree).name;
133
- const project = workspace.projects.get(projectName);
134
- const appModulePath = `${project?.sourceRoot}/app/app.module.ts`;
135
- const appModule = tree.read(appModulePath);
136
- if (!appModule) {
137
- return;
138
- }
139
- const appModuleContent = appModule.toString();
140
- if (appModuleContent.includes(`${(0, utils_1.camel)(packageName)}ConfigModule`)) {
141
- return;
142
- }
143
- const forRootStatement = `${(0, utils_1.pascal)(packageName)}ConfigModule.forRoot()`;
144
- const text = tree.read(appModulePath);
145
- if (!text) {
156
+ async function createLibSecondaryEntryWithStandaloneTemplate(tree, options) {
157
+ const targetLib = await (0, utils_1.resolveProject)(tree, options.target);
158
+ const packageName = `${(0, utils_1.kebab)(targetLib.name)}/${(0, utils_1.kebab)(options.packageName)}`;
159
+ const importPath = `${targetLib.definition.root}/${(0, utils_1.kebab)(options.packageName)}`;
160
+ return (0, schematics_1.chain)([
161
+ (0, utils_1.applyWithOverwrite)((0, schematics_1.url)('./files-secondary-entrypoint-standalone'), [
162
+ (0, schematics_1.applyTemplates)({
163
+ ...cases,
164
+ libraryName: options.packageName,
165
+ target: targetLib.name,
166
+ }),
167
+ (0, schematics_1.move)((0, core_1.normalize)(targetLib.definition.root)),
168
+ updateTsConfig(packageName, importPath),
169
+ ]),
170
+ ]);
171
+ }
172
+ exports.createLibSecondaryEntryWithStandaloneTemplate = createLibSecondaryEntryWithStandaloneTemplate;
173
+ function importConfigModuleToDefaultProjectAppModule(packageName, options) {
174
+ return async (tree) => {
175
+ const projectName = (0, utils_1.getFirstApplication)(tree).name;
176
+ const mainFilePath = await (0, util_1.getMainFilePath)(tree, projectName);
177
+ const isSourceStandalone = (0, utils_1.isStandaloneApp)(tree, mainFilePath);
178
+ const rules = [];
179
+ const providerAlreadyExists = isSourceStandalone
180
+ ? await (0, utils_1.hasProviderInStandaloneAppConfig)(tree, projectName, `provide${(0, utils_1.pascal)(packageName)}Config`)
181
+ : await (0, utils_1.hasImportInNgModule)(tree, projectName, options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone
182
+ ? `provide${(0, utils_1.pascal)(packageName)}Config`
183
+ : `${(0, utils_1.pascal)(packageName)}ConfigModule`, options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone ? 'providers' : 'imports');
184
+ if (providerAlreadyExists) {
146
185
  return;
147
186
  }
148
- const sourceText = text.toString();
149
- if (sourceText.includes(forRootStatement)) {
150
- return;
187
+ if (options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone) {
188
+ rules.push((0, utils_1.addRootProvider)(projectName, code => {
189
+ const configFn = code.external(`provide${(0, utils_1.pascal)(packageName)}Config`, `${(0, utils_1.kebab)(packageName)}/config`);
190
+ return code.code `${configFn}()`;
191
+ }));
151
192
  }
152
- const source = ts.createSourceFile(appModulePath, sourceText, ts.ScriptTarget.Latest, true);
153
- const changes = (0, utils_1.addImportToModule)(source, appModulePath, forRootStatement, `${(0, utils_1.kebab)(packageName)}/config`);
154
- const recorder = tree.beginUpdate(appModulePath);
155
- for (const change of changes) {
156
- if (change instanceof utils_1.InsertChange) {
157
- recorder.insertLeft(change.pos, change.toAdd);
158
- }
193
+ else {
194
+ rules.push((0, utils_1.addRootImport)(projectName, code => {
195
+ const configFn = code.external(`${(0, utils_1.pascal)(packageName)}ConfigModule`, `${(0, utils_1.kebab)(packageName)}/config`);
196
+ return code.code `${configFn}.forRoot()`;
197
+ }));
159
198
  }
160
- tree.commitUpdate(recorder);
161
- return;
199
+ return (0, schematics_1.chain)(rules);
162
200
  };
163
201
  }
164
202
  exports.importConfigModuleToDefaultProjectAppModule = importConfigModuleToDefaultProjectAppModule;
165
- function addRoutingToAppRoutingModule(workspace, packageName) {
166
- return (tree) => {
167
- const projectName = (0, utils_1.readWorkspaceSchema)(tree).defaultProject || (0, utils_1.getFirstApplication)(tree).name;
203
+ function addRoutingToAppRoutingModule(workspace, packageName, options) {
204
+ return async (tree) => {
205
+ const projectName = (0, utils_1.getFirstApplication)(tree).name;
168
206
  const project = workspace.projects.get(projectName);
169
- const appRoutingModulePath = `${project?.sourceRoot}/app/app-routing.module.ts`;
170
- const appRoutingModule = tree.read(appRoutingModulePath);
171
- if (!appRoutingModule) {
172
- return;
173
- }
174
- const appRoutingModuleContent = appRoutingModule.toString();
175
- const moduleName = `${(0, utils_1.pascal)(packageName)}Module`;
176
- if (appRoutingModuleContent.includes(moduleName)) {
177
- return;
207
+ const mainFilePath = await (0, util_1.getMainFilePath)(tree, projectName);
208
+ const isSourceStandalone = (0, utils_1.isStandaloneApp)(tree, mainFilePath);
209
+ const pascalName = (0, utils_1.pascal)(packageName);
210
+ const macroName = (0, utils_1.macro)(packageName);
211
+ const routePath = `${(0, utils_1.kebab)(packageName)}`;
212
+ const moduleName = `${pascalName}Module`;
213
+ if (isSourceStandalone) {
214
+ const appRoutesPath = (0, utils_1.findAppRoutesPath)(tree, mainFilePath) || `${project?.sourceRoot}/app/app.routes.ts`;
215
+ const buffer = tree.read(appRoutesPath);
216
+ if (!buffer) {
217
+ throw new schematics_1.SchematicsException(`Cannot find routes file: ${appRoutesPath}`);
218
+ }
219
+ const content = buffer.toString();
220
+ const source = ts.createSourceFile(appRoutesPath, content, ts.ScriptTarget.Latest, true);
221
+ const routeExpr = options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone
222
+ ? `() => import('${routePath}').then(m => m.${macroName}_ROUTES)`
223
+ : `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`;
224
+ const routeToAdd = `{ path: '${routePath}', loadChildren: ${routeExpr} }`;
225
+ const change = addRouteToRoutesArray(source, 'APP_ROUTES', routeToAdd);
226
+ if (change instanceof utils_1.InsertChange) {
227
+ const recorder = tree.beginUpdate(appRoutesPath);
228
+ recorder.insertLeft(change.pos, change.toAdd);
229
+ tree.commitUpdate(recorder);
230
+ }
178
231
  }
179
- const source = ts.createSourceFile(appRoutingModulePath, appRoutingModuleContent, ts.ScriptTarget.Latest, true);
180
- const importPath = `${(0, utils_1.kebab)(packageName)}`;
181
- const importStatement = `() => import('${importPath}').then(m => m.${moduleName}.forLazy())`;
182
- const routeDefinition = `{ path: '${(0, utils_1.kebab)(packageName)}', loadChildren: ${importStatement} }`;
183
- const change = (0, utils_1.addRouteDeclarationToModule)(source, `${(0, utils_1.kebab)(packageName)}`, routeDefinition);
184
- const recorder = tree.beginUpdate(appRoutingModulePath);
185
- if (change instanceof utils_1.InsertChange) {
186
- recorder.insertLeft(change.pos, change.toAdd);
232
+ else {
233
+ const appRoutingModulePath = await (0, utils_1.findAppRoutesModulePath)(tree, mainFilePath);
234
+ if (!appRoutingModulePath) {
235
+ throw new schematics_1.SchematicsException(`Cannot find routing module: ${appRoutingModulePath}`);
236
+ }
237
+ const appRoutingModule = tree.read(appRoutingModulePath);
238
+ if (!appRoutingModule) {
239
+ return;
240
+ }
241
+ const appRoutingModuleContent = appRoutingModule.toString();
242
+ const routeExpr = options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone
243
+ ? `${macroName}_ROUTES`
244
+ : moduleName;
245
+ if (appRoutingModuleContent.includes(routeExpr)) {
246
+ return;
247
+ }
248
+ const source = ts.createSourceFile(appRoutingModulePath, appRoutingModuleContent, ts.ScriptTarget.Latest, true);
249
+ const importStatement = options.templateType === generate_lib_schema_1.GenerateLibTemplateType.Standalone
250
+ ? `() => import('${routePath}').then(m => m.${macroName}_ROUTES)`
251
+ : `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`;
252
+ const routeDefinition = `{ path: '${routePath}', loadChildren: ${importStatement} }`;
253
+ const change = (0, utils_1.addRouteDeclarationToModule)(source, routePath, routeDefinition);
254
+ const recorder = tree.beginUpdate(appRoutingModulePath);
255
+ if (change instanceof utils_1.InsertChange) {
256
+ recorder.insertLeft(change.pos, change.toAdd);
257
+ }
258
+ tree.commitUpdate(recorder);
187
259
  }
188
- tree.commitUpdate(recorder);
189
260
  return;
190
261
  };
191
262
  }
192
263
  exports.addRoutingToAppRoutingModule = addRoutingToAppRoutingModule;
264
+ function addRouteToRoutesArray(source, arrayName, routeToAdd) {
265
+ const routesVar = source.statements.find(stmt => ts.isVariableStatement(stmt) &&
266
+ stmt.declarationList.declarations.some(decl => ts.isVariableDeclaration(decl) &&
267
+ (decl.name.getText() === arrayName || decl.name.getText() === arrayName.toUpperCase()) &&
268
+ decl.initializer !== undefined &&
269
+ ts.isArrayLiteralExpression(decl.initializer)));
270
+ if (!routesVar || !ts.isVariableStatement(routesVar)) {
271
+ throw new Error(`Could not find routes array named "${arrayName}".`);
272
+ }
273
+ const declaration = routesVar.declarationList.declarations.find(decl => decl.name.getText() === arrayName);
274
+ const arrayLiteral = declaration.initializer;
275
+ const getPathValue = (routeText) => {
276
+ const match = routeText.match(/path:\s*['"`](.+?)['"`]/);
277
+ return match?.[1] ?? null;
278
+ };
279
+ const newPath = getPathValue(routeToAdd);
280
+ const alreadyExists = arrayLiteral.elements.some(el => {
281
+ const existingPath = getPathValue(el.getText());
282
+ return existingPath === newPath;
283
+ });
284
+ if (alreadyExists) {
285
+ return null;
286
+ }
287
+ const hasTrailingComma = arrayLiteral.elements.hasTrailingComma ?? false;
288
+ const insertPos = hasTrailingComma || arrayLiteral.elements.length === 0
289
+ ? arrayLiteral.getEnd() - 1
290
+ : arrayLiteral.elements[arrayLiteral.elements.length - 1].getEnd();
291
+ const prefix = arrayLiteral.elements.length > 0 && !hasTrailingComma ? ',\n ' : ' ';
292
+ const toAdd = `${prefix}${routeToAdd}`;
293
+ return new utils_1.InsertChange(source.fileName, insertPos, toAdd);
294
+ }
295
+ exports.addRouteToRoutesArray = addRouteToRoutesArray;
193
296
  //# sourceMappingURL=index.js.map