@igniteui/angular-templates 17.1.13116-beta.1 → 17.1.13116

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.
@@ -1,10 +1,9 @@
1
- import { AddTemplateArgs, ControlExtraConfiguration, Template, TemplateDependency } from "@igniteui/cli-core";
1
+ import { AddTemplateArgs, ControlExtraConfiguration, Template, TemplateDependency, TypeScriptFileUpdate } from "@igniteui/cli-core";
2
2
  export declare class IgniteUIForAngularTemplate implements Template {
3
3
  private rootPath;
4
4
  components: string[];
5
5
  controlGroup: string;
6
6
  listInComponentTemplates: boolean;
7
- addAsNgModelDeclaration: boolean;
8
7
  listInCustomTemplates: boolean;
9
8
  id: string;
10
9
  name: string;
@@ -33,6 +32,7 @@ export declare class IgniteUIForAngularTemplate implements Template {
33
32
  getExtraConfiguration(): ControlExtraConfiguration[];
34
33
  setExtraConfiguration(extraConfigKeys: {}): void;
35
34
  fileExists(filePath: string): boolean;
35
+ protected addClassDeclaration(mainModule: TypeScriptFileUpdate, projPath: string, name: string, modulePath: string): void;
36
36
  protected getBaseVariables(name: string): {
37
37
  [key: string]: string;
38
38
  };
@@ -10,7 +10,6 @@ class IgniteUIForAngularTemplate {
10
10
  constructor(rootPath) {
11
11
  this.rootPath = rootPath;
12
12
  this.listInComponentTemplates = true;
13
- this.addAsNgModelDeclaration = true;
14
13
  this.listInCustomTemplates = false;
15
14
  this.framework = "angular";
16
15
  this.projectType = "igx-ts";
@@ -47,46 +46,32 @@ class IgniteUIForAngularTemplate {
47
46
  // tslint:disable-next-line:variable-name
48
47
  const TsUpdate =
49
48
  // tslint:disable-next-line:no-submodule-imports
50
- require("@igniteui/angular-templates").AngularTypeScriptFileUpdate;
51
- const mainModulePath = path.join(projectPath, `src/app/${modulePath}`);
52
- const folderName = this.folderName(name);
53
- const fileName = this.fileName(name);
54
- const componentFilePath = path.join(projectPath, `src/app/${folderName}/${fileName}.component.ts`);
55
- const className = `${cli_core_1.Util.className(cli_core_1.Util.nameFromPath(name))}Component`;
49
+ require("@igniteui/cli-core/typescript").TypeScriptFileUpdate;
56
50
  // standalone components
51
+ const mainModulePath = path.join(projectPath, `src/app/${modulePath}`);
57
52
  if (!this.fileExists(mainModulePath)) {
58
53
  const appRoutesPath = "src/app/app.routes.ts";
54
+ const folderName = this.folderName(name);
55
+ const fileName = this.fileName(name);
59
56
  if (!(options && options.skipRoute) && this.fileExists(appRoutesPath)) {
60
- const routesConfigPath = path.join(projectPath, appRoutesPath);
61
- const rountesConfig = new TsUpdate(routesConfigPath, true, { indentSize: 2 });
62
- rountesConfig.addRoute({
63
- modulePath: cli_core_1.Util.relativePath(routesConfigPath, componentFilePath, true, true),
64
- path: this.fileName(name),
65
- data: { text: cli_core_1.Util.nameFromPath(name) },
66
- identifierName: className
67
- });
68
- const content = rountesConfig.finalize();
69
- if (content) {
70
- // add to a finalize override in the NG File Update instead?
71
- cli_core_1.TypeScriptUtils.saveFile(routesConfigPath, content);
72
- }
57
+ const rountesConfig = new TsUpdate(path.join(projectPath, appRoutesPath));
58
+ rountesConfig.addRoute(path.join(projectPath, `src/app/${folderName}/${fileName}.component.ts`), this.fileName(name), //path
59
+ cli_core_1.Util.nameFromPath(name) //text
60
+ );
73
61
  }
74
- const componentFile = new TsUpdate(componentFilePath, true, { indentSize: 2 });
62
+ const componentFile = new TsUpdate(path.join(projectPath, `src/app/${folderName}/${fileName}.component.ts`));
75
63
  for (const dep of this.dependencies) {
76
64
  if (dep.from && dep.from.startsWith(".")) {
77
65
  // relative file dependency
78
66
  const copy = Object.assign({}, dep);
79
- copy.from = cli_core_1.Util.relativePath(componentFilePath, path.join(projectPath, copy.from), true, true);
80
- componentFile.addStandaloneComponentMeta(dep, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
67
+ copy.from = cli_core_1.Util.relativePath(path.join(projectPath, `src/app/${folderName}/${fileName}.component.ts`), path.join(projectPath, copy.from), true, true);
68
+ // can use addNgModuleMeta here instead?
69
+ componentFile.addStandaloneImport(copy, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
81
70
  continue;
82
71
  }
83
- componentFile.addStandaloneComponentMeta(dep, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
84
- }
85
- const content = componentFile.finalize();
86
- if (content) {
87
- // add to a finalize override in the NG File Update instead?
88
- cli_core_1.TypeScriptUtils.saveFile(componentFilePath, content);
72
+ componentFile.addStandaloneImport(dep, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
89
73
  }
74
+ componentFile.finalize();
90
75
  return;
91
76
  }
92
77
  // ngModule based components
@@ -94,28 +79,15 @@ class IgniteUIForAngularTemplate {
94
79
  //1) import the component class name,
95
80
  //2) and populate the Routes array with the path and component
96
81
  //for example: { path: 'combo', component: ComboComponent }
97
- const routingModulePath = path.join(projectPath, "src/app/app-routing.module.ts");
98
- const routingModule = new TsUpdate(routingModulePath, false, { indentSize: 2 });
99
- routingModule.addRoute({
100
- modulePath: cli_core_1.Util.relativePath(routingModulePath, componentFilePath, true, true),
101
- path: this.fileName(name),
102
- data: { text: cli_core_1.Util.nameFromPath(name) },
103
- identifierName: className
104
- });
105
- const content = routingModule.finalize();
106
- if (content) {
107
- // add to a finalize override in the NG File Update instead?
108
- cli_core_1.TypeScriptUtils.saveFile(routingModulePath, content);
109
- }
82
+ const routingModule = new TsUpdate(path.join(projectPath, "src/app/app-routing.module.ts"));
83
+ routingModule.addRoute(path.join(projectPath, `src/app/${this.folderName(name)}/${this.fileName(name)}.component.ts`), this.fileName(name), //path
84
+ cli_core_1.Util.nameFromPath(name) //text
85
+ );
110
86
  }
111
87
  //3) add an import of the component class from its file location.
112
88
  //4) populate the declarations portion of the @NgModule with the component class name.
113
- const mainModule = new TsUpdate(mainModulePath, false, { indentSize: 2 });
114
- mainModule.addNgModuleMeta({
115
- declare: this.addAsNgModelDeclaration ? [className] : [],
116
- from: cli_core_1.Util.relativePath(mainModulePath, componentFilePath, true, true),
117
- export: modulePath !== "app.module.ts" ? [className] : []
118
- });
89
+ const mainModule = new TsUpdate(mainModulePath);
90
+ this.addClassDeclaration(mainModule, projectPath, name, modulePath);
119
91
  // import IgxModules and other dependencies
120
92
  for (const dep of this.dependencies) {
121
93
  if (dep.from && dep.from.startsWith(".")) {
@@ -128,11 +100,7 @@ class IgniteUIForAngularTemplate {
128
100
  mainModule.addNgModuleMeta(dep, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
129
101
  }
130
102
  }
131
- const content = mainModule.finalize();
132
- if (content) {
133
- // add to a finalize override in the NG File Update instead?
134
- cli_core_1.TypeScriptUtils.saveFile(mainModulePath, content);
135
- }
103
+ mainModule.finalize();
136
104
  }
137
105
  getExtraConfiguration() {
138
106
  return [];
@@ -141,6 +109,9 @@ class IgniteUIForAngularTemplate {
141
109
  fileExists(filePath) {
142
110
  return cli_core_1.App.container.get(cli_core_1.FS_TOKEN).fileExists(filePath);
143
111
  }
112
+ addClassDeclaration(mainModule, projPath, name, modulePath) {
113
+ mainModule.addDeclaration(path.join(projPath, `src/app/${this.folderName(name)}/${this.fileName(name)}.component.ts`), modulePath !== "app.module.ts");
114
+ }
144
115
  getBaseVariables(name) {
145
116
  const config = {};
146
117
  config["name"] = cli_core_1.Util.nameFromPath(name);
@@ -15,5 +15,8 @@ class IgcDockManagerTemplate extends IgniteUIForAngularTemplate_1.IgniteUIForAng
15
15
  // "igniteui-dockmanager@~1.0.0":
16
16
  this.packages = [`${(0, cli_core_1.resolvePackage)(cli_core_1.NPM_DOCK_MANAGER)}@~1.8.0`];
17
17
  }
18
+ addClassDeclaration(mainModule, projPath, name, modulePath) {
19
+ // not applicable with custom module
20
+ }
18
21
  }
19
22
  module.exports = new IgcDockManagerTemplate();
@@ -95,7 +95,7 @@ class IgxCustomGridTemplate extends IgniteUIForAngularTemplate_1.IgniteUIForAngu
95
95
  checkBoxBind = `[ngModel]="cell.value" (ngModelChange)="cell.update($event)"`;
96
96
  // enable Date Picker, ngModel
97
97
  // this.dependencies.push({ import: "IgxDatePickerModule", from: "<%=igxPackage%>" });
98
- this.dependencies.push({ import: "FormsModule", from: "@angular/forms", standalone: true });
98
+ this.dependencies.push({ import: "FormsModule", from: "@angular/forms" });
99
99
  // datePickerEditor = EOL +
100
100
  // `<ng-template igxCellEditor let-cell="cell">` + EOL +
101
101
  // ` <igx-date-picker cancelButtonLabel="cancel" todayButtonLabel="today" [(ngModel)]="cell.value"` +
@@ -107,7 +107,7 @@ class IgxCustomGridTemplate extends IgniteUIForAngularTemplate_1.IgniteUIForAngu
107
107
  break;
108
108
  case "Row Editing":
109
109
  gridFeatures.push(`[rowEditable]="true"`);
110
- this.dependencies.push({ import: "IgxDatePickerComponent", from: "<%=igxPackage%>", standalone: true });
110
+ this.dependencies.push({ import: "IgxDatePickerComponent", from: "<%=igxPackage%>" });
111
111
  break;
112
112
  case "Row Selection":
113
113
  const gridFeatureText = `rowSelection="multiple"`;
@@ -111,7 +111,7 @@ class IgxHierarchicalGridTemplate extends IgniteUIForAngularTemplate_1.IgniteUIF
111
111
  break;
112
112
  case "Cell Editing":
113
113
  columnFeatures.push(`[editable]="true"`);
114
- this.dependencies.push({ import: "FormsModule", from: "@angular/forms", standalone: true });
114
+ this.dependencies.push({ import: "FormsModule", from: "@angular/forms" });
115
115
  break;
116
116
  case "Row Selection":
117
117
  const gridFeatureText = `rowSelection="multiple"`;
@@ -19,7 +19,7 @@ jobs:
19
19
 
20
20
  strategy:
21
21
  matrix:
22
- node-version: [16.x, 18.x]
22
+ node-version: [18.x, 20.x]
23
23
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
24
24
 
25
25
  steps:
@@ -99,7 +99,12 @@
99
99
  "styles": [
100
100
  "src/styles.scss"
101
101
  ],
102
- "scripts": []
102
+ "scripts": [],
103
+ "stylePreprocessorOptions": {
104
+ "includePaths": [
105
+ "node_modules"
106
+ ]
107
+ }
103
108
  }
104
109
  }
105
110
  }
@@ -19,7 +19,7 @@ jobs:
19
19
 
20
20
  strategy:
21
21
  matrix:
22
- node-version: [16.x, 18.x]
22
+ node-version: [18.x, 20.x]
23
23
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
24
24
 
25
25
  steps:
@@ -8,7 +8,6 @@ class IgcDockManagerTemplate extends IgniteUIForAngularTemplate_1.IgniteUIForAng
8
8
  this.components = ["Dock Manager"];
9
9
  this.controlGroup = "Layouts";
10
10
  this.listInComponentTemplates = true;
11
- this.addAsNgModelDeclaration = false;
12
11
  this.id = "dock-manager";
13
12
  this.projectType = "igx-ts";
14
13
  this.name = "Dock Manager";
@@ -19,5 +18,8 @@ class IgcDockManagerTemplate extends IgniteUIForAngularTemplate_1.IgniteUIForAng
19
18
  // "igniteui-dockmanager@~1.0.0":
20
19
  this.packages = [`${(0, cli_core_1.resolvePackage)(cli_core_1.NPM_DOCK_MANAGER)}@~1.8.0`];
21
20
  }
21
+ addClassDeclaration(mainModule, projPath, name, modulePath) {
22
+ // not applicable with custom module
23
+ }
22
24
  }
23
25
  module.exports = new IgcDockManagerTemplate();
@@ -19,7 +19,7 @@ jobs:
19
19
 
20
20
  strategy:
21
21
  matrix:
22
- node-version: [16.x, 18.x]
22
+ node-version: [18.x, 20.x]
23
23
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
24
24
 
25
25
  steps:
@@ -19,7 +19,7 @@ jobs:
19
19
 
20
20
  strategy:
21
21
  matrix:
22
- node-version: [16.x, 18.x]
22
+ node-version: [18.x, 20.x]
23
23
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
24
24
 
25
25
  steps:
package/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import * as standalone from './igx-ts';
2
- export * from './IgniteUIForAngularTemplate';
3
- export * from './AngularTypeScriptFileUpdate';
4
- export * from './types';
1
+ import * as standalone from "./igx-ts";
2
+ export * from "./IgniteUIForAngularTemplate";
5
3
  declare const _default: (typeof standalone)[];
6
4
  export default _default;
package/index.js CHANGED
@@ -17,6 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  const standalone = require("./igx-ts");
18
18
  const legacy = require("./igx-ts-legacy");
19
19
  __exportStar(require("./IgniteUIForAngularTemplate"), exports);
20
- __exportStar(require("./AngularTypeScriptFileUpdate"), exports);
21
- __exportStar(require("./types"), exports);
22
20
  exports.default = [standalone, legacy];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igniteui/angular-templates",
3
- "version": "17.1.13116-beta.1",
3
+ "version": "17.1.13116",
4
4
  "description": "Templates for Ignite UI for Angular projects and components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,7 @@
12
12
  "author": "Infragistics",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@igniteui/cli-core": "~13.1.16-beta.1",
15
+ "@igniteui/cli-core": "~13.1.16",
16
16
  "typescript": "~5.4.3"
17
17
  }
18
18
  }
@@ -1,121 +0,0 @@
1
- import * as ts from 'typescript';
2
- import { KeyValuePair, TemplateDependency, IFormatSettings } from '@igniteui/cli-core';
3
- import { IAngularRouteLike } from './types';
4
- export declare const NEW_LINE_PLACEHOLDER = "//I keep the new line";
5
- export declare class AngularTypeScriptFileUpdate {
6
- private standalone;
7
- private readonly astTransformer;
8
- constructor(targetPath: string, standalone?: boolean, formatSettings?: IFormatSettings);
9
- /**
10
- * Adds a route to the Angular routing module.
11
- * @param route The route to add.
12
- * @param multiline Whether to format the new entry as multiline.
13
- */
14
- addRoute(route: IAngularRouteLike, multiline?: boolean): ts.SourceFile;
15
- /**
16
- * Adds a child route to a parent route.
17
- * @param parentPath The path of the parent route.
18
- * @param route The child route to add.
19
- * @param multiline Whether to format the new entry as multiline.
20
- * @param prepend Whether to prepend the new added routes.
21
- * @remarks The `parentPath` is used to determine where the child route should be added.
22
- */
23
- addChildRoute(parentPath: string, route: IAngularRouteLike, multiline?: boolean, prepend?: boolean): ts.SourceFile;
24
- /**
25
- * Adds an import identifier to a standalone component's metadata.
26
- * @param dep The dependency to add to the standalone component's metadata.
27
- * @param variables Variables to replace in the dependency strings.
28
- * @param multiline Whether to format the new entry as multiline.
29
- */
30
- addStandaloneComponentMeta(dep: TemplateDependency, variables?: KeyValuePair<string>, multiline?: boolean): ts.SourceFile;
31
- /**
32
- * Adds metadata to an NgModule decorator.
33
- * @param dep The dependency to add to the NgModule decorator.
34
- * @param variables Variables to replace in the dependency strings.
35
- * @param multiline Whether to format the new entry as multiline.
36
- */
37
- addNgModuleMeta(dep: TemplateDependency, variables?: KeyValuePair<string>, multiline?: boolean): ts.SourceFile;
38
- /**
39
- * Parses the AST and returns the resulting formatted source code.
40
- * @remarks This method should be called after all modifications have been made to the AST.
41
- */
42
- finalize(): string;
43
- /**
44
- * Updates an Angular decorator's metadata.
45
- * @param name The name of the decorator to update.
46
- * @param meta Names of identifiers to be added.
47
- * @param target The target metadata property to update.
48
- * @param multiline Whether to format the new entry as multiline.
49
- */
50
- private mutateNgDecoratorMeta;
51
- /**
52
- * Checks if a node has an ancestor with a specific decorator.
53
- * @param name The name of the decorator.
54
- * @param node The node to start checking from.
55
- */
56
- private checkNgDecorator;
57
- /**
58
- * Finds a property assignment that exists in a specific NG decorator meta.
59
- * @param decoratorName The name of the decorator to check.
60
- * @param propName The property name to check.
61
- * @param node The node to start checking from.
62
- */
63
- private findNgDecoratorProperty;
64
- /**
65
- * Creates an arrow function of the form `() => import(path).then(m => m.prop)`.
66
- * @param path The path to the module to import.
67
- * @param importedEntity The entity to import from the module.
68
- * @param root Whether it should be `loadChildren` or `loadComponent`.
69
- * @remarks If the `root` param is `true` the function will use `routes` as an `importedEntity`.
70
- */
71
- private createDynamicImport;
72
- /**
73
- * Converts a string or string array union to array.
74
- * @param value The value to convert.
75
- * @param variables Variables to replace in the strings.
76
- * @remarks Splits strings as comma delimited.
77
- */
78
- private asArray;
79
- /**
80
- * Applies a configuration transformation to a string.
81
- * @param data The string to transform.
82
- * @param configuration The items to replace in the string.
83
- */
84
- private applyConfigTransformation;
85
- /**
86
- * Adds a new entry to the routes array. With a component identifier and path or with redirect option.
87
- * @param route The route to add.
88
- * @param visitCondition The condition used to find the appropriate route node.
89
- * @param anchorElement The anchor element to insert.
90
- * @param multiline Whether to format the new entry as multiline.
91
- * @param prepend Whether to insert the new entry before the anchor element.
92
- */
93
- private addRedirectOrSimpleRouteEntry;
94
- /**
95
- * Adds a new not lazy-loaded route entry to the routes array. With a component identifier and path.
96
- * @param route The route to add.
97
- * @param visitCondition The condition used to find the appropriate route node.
98
- * @param anchorElement The anchor element to insert to.
99
- * @param multiline Whether to format the new entry as multiline.
100
- * @param prepend Whether to insert the new entry before the anchor element.
101
- */
102
- private addRouteEntry;
103
- /**
104
- * Adds a new not lazy-loaded route entry to the routes array. With a redirect option.
105
- * @param route The route to add.
106
- * @param visitCondition The condition used to find the appropriate route node.
107
- * @param anchorElement The anchor element to insert to.
108
- * @param multiline Whether to format the new entry as multiline.
109
- * @param prepend Whether to insert the new entry before the anchor element.
110
- */
111
- private addRedirectRouteEntry;
112
- /**
113
- * Adds a new lazy-loaded route entry to the routes array.
114
- * @param route The route to add.
115
- * @param visitCondition The condition used to find the appropriate route node.
116
- * @param anchorElement The anchor element to insert to.
117
- * @param multiline Whether to format the new entry as multiline.
118
- * @param prepend Whether to insert the new entry before the anchor element.
119
- */
120
- private addLazyLoadedRouteEntry;
121
- }
@@ -1,401 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AngularTypeScriptFileUpdate = exports.NEW_LINE_PLACEHOLDER = void 0;
4
- const ts = require("typescript");
5
- const os_1 = require("os");
6
- const cli_core_1 = require("@igniteui/cli-core");
7
- const types_1 = require("./types");
8
- // TODO: consider creating a global-constants file
9
- const ROUTES_VARIABLE_NAME = 'routes';
10
- const THEN_IDENTIFIER_NAME = 'then';
11
- const IMPORT_IDENTIFIER_NAME = 'import';
12
- const NG_MODULE_DECORATOR_NAME = 'NgModule';
13
- const NG_SA_DECORATOR_NAME = 'Component';
14
- const NG_FOR_ROOT_IDENTIFIER_NAME = 'forRoot';
15
- const NG_LOAD_CHILDREN_IDENTIFIER_NAME = 'loadChildren';
16
- const NG_LOAD_COMPONENT_IDENTIFIER_NAME = 'loadComponent';
17
- exports.NEW_LINE_PLACEHOLDER = '//I keep the new line';
18
- // insert before node that contains this element
19
- const anchorElement = {
20
- name: 'path',
21
- value: ts.factory.createStringLiteral('**'),
22
- };
23
- const printerOptions = {
24
- newLine: os_1.EOL === '\n'
25
- ? ts.NewLineKind.LineFeed
26
- : ts.NewLineKind.CarriageReturnLineFeed,
27
- };
28
- class AngularTypeScriptFileUpdate {
29
- constructor(targetPath, standalone = false, formatSettings) {
30
- this.standalone = standalone;
31
- /**
32
- * Applies a configuration transformation to a string.
33
- * @param data The string to transform.
34
- * @param configuration The items to replace in the string.
35
- */
36
- this.applyConfigTransformation = (data, configuration) => {
37
- let key;
38
- for (key in configuration) {
39
- data = data.replace(new RegExp(cli_core_1.Util.escapeRegExp(key), 'g'), configuration[key]);
40
- }
41
- return data;
42
- };
43
- const sourceFile = cli_core_1.TypeScriptUtils.getFileSource(targetPath);
44
- this.astTransformer = new cli_core_1.TypeScriptASTTransformer(sourceFile, new cli_core_1.FormattingService(sourceFile, null, formatSettings, printerOptions), printerOptions // TODO: may not be needed
45
- );
46
- }
47
- //#region Public API
48
- /**
49
- * Adds a route to the Angular routing module.
50
- * @param route The route to add.
51
- * @param multiline Whether to format the new entry as multiline.
52
- */
53
- addRoute(route, multiline = false) {
54
- const visitCondition = (node) => !!this.astTransformer.findNodeAncenstor(node, (node) => ts.isVariableDeclaration(node) &&
55
- node.name.getText() === ROUTES_VARIABLE_NAME);
56
- if (route.lazyload &&
57
- route.path &&
58
- route.identifierName &&
59
- route.modulePath) {
60
- return this.addLazyLoadedRouteEntry(route, visitCondition, anchorElement, multiline, true // prepend
61
- );
62
- }
63
- return this.addRedirectOrSimpleRouteEntry(route, visitCondition, anchorElement, multiline, true // prepend
64
- );
65
- }
66
- /**
67
- * Adds a child route to a parent route.
68
- * @param parentPath The path of the parent route.
69
- * @param route The child route to add.
70
- * @param multiline Whether to format the new entry as multiline.
71
- * @param prepend Whether to prepend the new added routes.
72
- * @remarks The `parentPath` is used to determine where the child route should be added.
73
- */
74
- addChildRoute(parentPath, route, multiline = false, prepend = false) {
75
- // find a node that has the parent's path
76
- const visitCondition = (node) => ts.isPropertyAssignment(node) &&
77
- node.name.getText() === cli_core_1.RouteTarget.Path &&
78
- ts.isStringLiteral(node.initializer) &&
79
- node.initializer.text === parentPath;
80
- const parentRoute = this.astTransformer.findPropertyAssignment(visitCondition);
81
- if (!parentRoute)
82
- return this.astTransformer.sourceFile;
83
- const childrenKey = 'children';
84
- const parentContainsChildrenKey = ts.isObjectLiteralExpression(parentRoute.parent) &&
85
- parentRoute.parent.properties.find((p) => { var _a; return ts.isPropertyAssignment(p) && ((_a = p.name) === null || _a === void 0 ? void 0 : _a.getText()) === childrenKey; });
86
- if (!parentContainsChildrenKey) {
87
- // if the parent route does not have the children array, create it
88
- this.astTransformer.addMemberToObjectLiteral((node) => ts.isObjectLiteralExpression(node) &&
89
- node.properties.some(visitCondition), {
90
- name: childrenKey,
91
- value: this.astTransformer.createArrayLiteralExpression([], multiline),
92
- });
93
- }
94
- // add the child route to the parent's children array
95
- return this.addRedirectOrSimpleRouteEntry(route, (node) => ts.isPropertyAssignment(node.parent) &&
96
- node.parent.name.getText() === childrenKey &&
97
- // check if the parent route is the one we're looking for
98
- !!this.astTransformer.findNodeAncenstor(node, (node) => ts.isObjectLiteralExpression(node) &&
99
- node.properties.some(visitCondition)), anchorElement, multiline, prepend);
100
- }
101
- /**
102
- * Adds an import identifier to a standalone component's metadata.
103
- * @param dep The dependency to add to the standalone component's metadata.
104
- * @param variables Variables to replace in the dependency strings.
105
- * @param multiline Whether to format the new entry as multiline.
106
- */
107
- addStandaloneComponentMeta(dep, variables, multiline = false) {
108
- if (!this.standalone || !dep.standalone)
109
- return this.astTransformer.sourceFile;
110
- const copy = {
111
- import: this.asArray(dep.import || [], variables || {}),
112
- provide: this.asArray(dep.provide || [], variables || {}),
113
- };
114
- if (dep.from) {
115
- // add an import declaration for the dependency
116
- const uniqueIdentifiers = new Set([
117
- ...copy.import,
118
- ...copy.provide,
119
- ]);
120
- const identifiers = [...uniqueIdentifiers].map((name) => ({ name }));
121
- this.astTransformer.addImportDeclaration(identifiers.filter((i) => !this.astTransformer.importDeclarationCollides(i)), this.applyConfigTransformation(dep.from, variables));
122
- }
123
- if (copy.import.length > 0) {
124
- return this.mutateNgDecoratorMeta(NG_SA_DECORATOR_NAME, copy.import, types_1.AngularDecoratorMetaTarget.Imports, multiline);
125
- }
126
- if (copy.provide.length > 0) {
127
- return this.mutateNgDecoratorMeta(NG_SA_DECORATOR_NAME, copy.provide, types_1.AngularDecoratorMetaTarget.Providers, multiline);
128
- }
129
- return this.astTransformer.sourceFile;
130
- }
131
- /**
132
- * Adds metadata to an NgModule decorator.
133
- * @param dep The dependency to add to the NgModule decorator.
134
- * @param variables Variables to replace in the dependency strings.
135
- * @param multiline Whether to format the new entry as multiline.
136
- */
137
- addNgModuleMeta(dep, variables, multiline = false) {
138
- if (this.standalone || dep.standalone)
139
- return this.astTransformer.sourceFile;
140
- const copy = {
141
- import: this.asArray(dep.import || [], variables || {}),
142
- declare: this.asArray(dep.declare || [], variables || {}),
143
- provide: this.asArray(dep.provide || [], variables || {}),
144
- export: this.asArray(dep.export || [], variables || {}),
145
- };
146
- if (dep.from) {
147
- // add an import declaration for the dependency
148
- const uniqueIdentifiers = new Set([
149
- ...copy.import,
150
- ...copy.declare,
151
- ...copy.provide,
152
- ...copy.export,
153
- ]);
154
- const identifiers = [...uniqueIdentifiers].map((name) => ({ name }));
155
- this.astTransformer.addImportDeclaration(identifiers.filter((i) => !this.astTransformer.importDeclarationCollides(i)), this.applyConfigTransformation(dep.from, variables));
156
- }
157
- if (dep.root && copy.import.length > 0) {
158
- // add forRoot to the module
159
- copy.import = copy.import.map((i) => this.astTransformer.printer.printNode(ts.EmitHint.Unspecified, this.astTransformer.createCallExpression(i, NG_FOR_ROOT_IDENTIFIER_NAME), this.astTransformer.sourceFile));
160
- }
161
- if (copy.declare.length > 0) {
162
- this.mutateNgDecoratorMeta(NG_MODULE_DECORATOR_NAME, copy.declare, types_1.AngularDecoratorMetaTarget.Declarations, multiline);
163
- }
164
- if (copy.import.length > 0) {
165
- this.mutateNgDecoratorMeta(NG_MODULE_DECORATOR_NAME, copy.import, types_1.AngularDecoratorMetaTarget.Imports, multiline);
166
- }
167
- if (copy.provide.length > 0) {
168
- this.mutateNgDecoratorMeta(NG_MODULE_DECORATOR_NAME, copy.provide, types_1.AngularDecoratorMetaTarget.Providers, multiline);
169
- }
170
- if (copy.export.length > 0) {
171
- this.mutateNgDecoratorMeta(NG_MODULE_DECORATOR_NAME, copy.export, types_1.AngularDecoratorMetaTarget.Exports, multiline);
172
- }
173
- return this.astTransformer.sourceFile;
174
- }
175
- /**
176
- * Parses the AST and returns the resulting formatted source code.
177
- * @remarks This method should be called after all modifications have been made to the AST.
178
- */
179
- finalize() {
180
- return this.astTransformer.finalize();
181
- }
182
- //#endregion
183
- //#region Internals
184
- /**
185
- * Updates an Angular decorator's metadata.
186
- * @param name The name of the decorator to update.
187
- * @param meta Names of identifiers to be added.
188
- * @param target The target metadata property to update.
189
- * @param multiline Whether to format the new entry as multiline.
190
- */
191
- mutateNgDecoratorMeta(name, meta, target, multiline = false) {
192
- const identifiers = meta.map(ts.factory.createIdentifier);
193
- const targetMetaProp = this.findNgDecoratorProperty(name, target);
194
- if (!targetMetaProp) {
195
- return this.astTransformer.addMemberToObjectLiteral((node) => this.checkNgDecorator(name, node), {
196
- name: target,
197
- value: this.astTransformer.createArrayLiteralExpression(identifiers, multiline),
198
- });
199
- }
200
- if (ts.isArrayLiteralExpression(targetMetaProp.initializer)) {
201
- // prop assignment of the form { member: [...] }
202
- // store to avoid second type check due to different context in the filter
203
- const elementsAsNodeArray = targetMetaProp.initializer.elements;
204
- const elementsToAdd = identifiers.filter((i) => !elementsAsNodeArray.some((el) => el.getText() === i.text));
205
- return this.astTransformer.addMembersToArrayLiteral((node) => ts.isPropertyAssignment(node.parent) &&
206
- node.parent.name.getText() === target &&
207
- this.checkNgDecorator(name, node), elementsToAdd);
208
- }
209
- // prop assignment of the form { member: <some-val> }
210
- return this.astTransformer.updateObjectLiteralMember((node) => this.checkNgDecorator(name, node), {
211
- name: target,
212
- value: this.astTransformer.createArrayLiteralExpression([targetMetaProp.initializer, ...identifiers], multiline),
213
- });
214
- }
215
- /**
216
- * Checks if a node has an ancestor with a specific decorator.
217
- * @param name The name of the decorator.
218
- * @param node The node to start checking from.
219
- */
220
- checkNgDecorator(name, node) {
221
- return !!this.astTransformer.findNodeAncenstor(node, (node) => {
222
- var _a;
223
- return ts.isDecorator(node) &&
224
- ((_a = node.expression.getFirstToken()) === null || _a === void 0 ? void 0 : _a.getText()) === name;
225
- });
226
- }
227
- /**
228
- * Finds a property assignment that exists in a specific NG decorator meta.
229
- * @param decoratorName The name of the decorator to check.
230
- * @param propName The property name to check.
231
- * @param node The node to start checking from.
232
- */
233
- findNgDecoratorProperty(decoratorName, propName) {
234
- return this.astTransformer.findPropertyAssignment((node) => ts.isPropertyAssignment(node) &&
235
- node.name.getText() === propName &&
236
- !!this.astTransformer.findNodeAncenstor(node, (node) => {
237
- var _a;
238
- return ts.isDecorator(node) &&
239
- ((_a = node.expression.getFirstToken()) === null || _a === void 0 ? void 0 : _a.getText()) === decoratorName;
240
- }));
241
- }
242
- /**
243
- * Creates an arrow function of the form `() => import(path).then(m => m.prop)`.
244
- * @param path The path to the module to import.
245
- * @param importedEntity The entity to import from the module.
246
- * @param root Whether it should be `loadChildren` or `loadComponent`.
247
- * @remarks If the `root` param is `true` the function will use `routes` as an `importedEntity`.
248
- */
249
- createDynamicImport(path, importedEntity, root = false) {
250
- const thenClause = root ? ROUTES_VARIABLE_NAME : importedEntity;
251
- // create the 'import(path)' expression
252
- const importExpression = ts.factory.createCallExpression(ts.factory.createIdentifier(IMPORT_IDENTIFIER_NAME), undefined, // type arguments
253
- [ts.factory.createStringLiteral(path)]);
254
- const thenFuncParamName = 'm';
255
- // create the 'm => m.prop' arrow function
256
- const thenExprArrowFuncBody = ts.factory.createArrowFunction(undefined, // modifiers
257
- undefined, // type parameters
258
- [
259
- ts.factory.createParameterDeclaration(undefined, // decorators
260
- undefined, // modifiers
261
- ts.factory.createIdentifier(thenFuncParamName)),
262
- ], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createPropertyAccessChain(ts.factory.createIdentifier(thenFuncParamName), undefined, // question-dot token
263
- thenClause));
264
- // build the '.then(m => m.prop)' expression and add it to the import expression
265
- const body = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(importExpression, THEN_IDENTIFIER_NAME), undefined, // type arguments
266
- [thenExprArrowFuncBody]);
267
- // Create the '() => import(path).then(m => m.prop)' arrow function
268
- const dynamicImport = ts.factory.createArrowFunction(undefined, // modifiers
269
- undefined, // type parameters
270
- [], // parameters
271
- undefined, // type
272
- ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), body);
273
- return dynamicImport;
274
- }
275
- /**
276
- * Converts a string or string array union to array.
277
- * @param value The value to convert.
278
- * @param variables Variables to replace in the strings.
279
- * @remarks Splits strings as comma delimited.
280
- */
281
- asArray(value, variables) {
282
- let result = [];
283
- if (value) {
284
- result = typeof value === 'string' ? value.split(/\s*,\s*/) : value;
285
- result = result.map((x) => this.applyConfigTransformation(x, variables));
286
- }
287
- return result;
288
- }
289
- /**
290
- * Adds a new entry to the routes array. With a component identifier and path or with redirect option.
291
- * @param route The route to add.
292
- * @param visitCondition The condition used to find the appropriate route node.
293
- * @param anchorElement The anchor element to insert.
294
- * @param multiline Whether to format the new entry as multiline.
295
- * @param prepend Whether to insert the new entry before the anchor element.
296
- */
297
- addRedirectOrSimpleRouteEntry(route, visitCondition, anchorElement, multiline = false, prepend = false) {
298
- var _a;
299
- if (route.lazyload)
300
- return this.astTransformer.sourceFile;
301
- if (route.path && route.identifierName) {
302
- this.addRouteEntry(route, visitCondition, anchorElement, multiline, prepend);
303
- }
304
- if (route.redirectTo) {
305
- this.addRedirectRouteEntry(route, visitCondition, anchorElement, multiline, prepend);
306
- }
307
- if ((_a = route.children) === null || _a === void 0 ? void 0 : _a.length) {
308
- route.children.forEach((child) => {
309
- this.addChildRoute(route.path, child, multiline, false);
310
- });
311
- }
312
- return this.astTransformer.sourceFile;
313
- }
314
- /**
315
- * Adds a new not lazy-loaded route entry to the routes array. With a component identifier and path.
316
- * @param route The route to add.
317
- * @param visitCondition The condition used to find the appropriate route node.
318
- * @param anchorElement The anchor element to insert to.
319
- * @param multiline Whether to format the new entry as multiline.
320
- * @param prepend Whether to insert the new entry before the anchor element.
321
- */
322
- addRouteEntry(route, visitCondition, anchorElement, multiline = false, prepend = false) {
323
- if (route.modulePath) {
324
- // add an import for the given identifier
325
- const routeIdentifier = { name: route.identifierName };
326
- if (!this.astTransformer.importDeclarationCollides(routeIdentifier)) {
327
- // if identifierName, there must be a modulePath as well
328
- this.astTransformer.addImportDeclaration([routeIdentifier], route.modulePath);
329
- }
330
- }
331
- const structure = [
332
- {
333
- name: cli_core_1.RouteTarget.Path,
334
- value: ts.factory.createStringLiteral(route.path),
335
- },
336
- {
337
- name: cli_core_1.RouteTarget.Component,
338
- value: ts.factory.createIdentifier(route.identifierName),
339
- },
340
- ];
341
- if (route.data) {
342
- structure.push({
343
- name: types_1.AngularRouteTarget.Data,
344
- value: this.astTransformer.createObjectLiteralExpression([route.data], multiline, ts.factory.createStringLiteral),
345
- });
346
- }
347
- const newRoute = this.astTransformer.createObjectLiteralExpression(structure, multiline);
348
- return this.astTransformer.addMembersToArrayLiteral(visitCondition, [newRoute], prepend, anchorElement);
349
- }
350
- /**
351
- * Adds a new not lazy-loaded route entry to the routes array. With a redirect option.
352
- * @param route The route to add.
353
- * @param visitCondition The condition used to find the appropriate route node.
354
- * @param anchorElement The anchor element to insert to.
355
- * @param multiline Whether to format the new entry as multiline.
356
- * @param prepend Whether to insert the new entry before the anchor element.
357
- */
358
- addRedirectRouteEntry(route, visitCondition, anchorElement, multiline = false, prepend = false) {
359
- const structure = [
360
- {
361
- name: cli_core_1.RouteTarget.Path,
362
- value: ts.factory.createStringLiteral(route.path || ''),
363
- },
364
- {
365
- name: types_1.AngularRouteTarget.RedirectTo,
366
- value: ts.factory.createStringLiteral(route.redirectTo),
367
- },
368
- ];
369
- if (route.pathMatch) {
370
- structure.push({
371
- name: types_1.AngularRouteTarget.PathMatch,
372
- value: ts.factory.createStringLiteral(route.pathMatch),
373
- });
374
- }
375
- const newRoute = this.astTransformer.createObjectLiteralExpression(structure, multiline);
376
- return this.astTransformer.addMembersToArrayLiteral(visitCondition, [newRoute], prepend, anchorElement);
377
- }
378
- /**
379
- * Adds a new lazy-loaded route entry to the routes array.
380
- * @param route The route to add.
381
- * @param visitCondition The condition used to find the appropriate route node.
382
- * @param anchorElement The anchor element to insert to.
383
- * @param multiline Whether to format the new entry as multiline.
384
- * @param prepend Whether to insert the new entry before the anchor element.
385
- */
386
- addLazyLoadedRouteEntry(route, visitCondition, anchorElement, multiline = false, prepend = false) {
387
- const lazyLoadedModule = this.createDynamicImport(route.modulePath, route.identifierName, route.root);
388
- const propAssignmentName = route.root
389
- ? NG_LOAD_CHILDREN_IDENTIFIER_NAME
390
- : NG_LOAD_COMPONENT_IDENTIFIER_NAME;
391
- const newRoute = this.astTransformer.createObjectLiteralExpression([
392
- {
393
- name: cli_core_1.RouteTarget.Path,
394
- value: ts.factory.createStringLiteral(route.path),
395
- },
396
- { name: propAssignmentName, value: lazyLoadedModule },
397
- ], multiline);
398
- return this.astTransformer.addMembersToArrayLiteral(visitCondition, [newRoute], prepend, anchorElement);
399
- }
400
- }
401
- exports.AngularTypeScriptFileUpdate = AngularTypeScriptFileUpdate;
@@ -1,5 +0,0 @@
1
- import { IRouteEntry, RouteTarget } from "@igniteui/cli-core";
2
- import { AngularRouteTarget } from "./enumerations/AngularRouteTarget";
3
- export interface IAngularRouteEntry extends Pick<IRouteEntry, 'value'> {
4
- name: RouteTarget | AngularRouteTarget;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
1
- import { IRouteLike, KeyValuePair } from "@igniteui/cli-core";
2
- export interface IAngularRouteLike extends IRouteLike {
3
- pathMatch?: 'prefix' | 'full';
4
- root?: boolean;
5
- data?: KeyValuePair<string>;
6
- redirectTo?: string;
7
- children?: IAngularRouteLike[];
8
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- export declare enum AngularDecoratorMetaTarget {
2
- Imports = "imports",
3
- Declarations = "declarations",
4
- Providers = "providers",
5
- Exports = "exports"
6
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AngularDecoratorMetaTarget = void 0;
4
- var AngularDecoratorMetaTarget;
5
- (function (AngularDecoratorMetaTarget) {
6
- AngularDecoratorMetaTarget["Imports"] = "imports";
7
- AngularDecoratorMetaTarget["Declarations"] = "declarations";
8
- AngularDecoratorMetaTarget["Providers"] = "providers";
9
- AngularDecoratorMetaTarget["Exports"] = "exports";
10
- })(AngularDecoratorMetaTarget || (exports.AngularDecoratorMetaTarget = AngularDecoratorMetaTarget = {}));
@@ -1,6 +0,0 @@
1
- export declare enum AngularRouteTarget {
2
- PathMatch = "pathMatch",
3
- Root = "root",
4
- Data = "data",
5
- RedirectTo = "redirectTo"
6
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AngularRouteTarget = void 0;
4
- var AngularRouteTarget;
5
- (function (AngularRouteTarget) {
6
- AngularRouteTarget["PathMatch"] = "pathMatch";
7
- AngularRouteTarget["Root"] = "root";
8
- AngularRouteTarget["Data"] = "data";
9
- AngularRouteTarget["RedirectTo"] = "redirectTo";
10
- })(AngularRouteTarget || (exports.AngularRouteTarget = AngularRouteTarget = {}));
package/types/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './enumerations/AngularDecoratorMetaTarget';
2
- export * from './enumerations/AngularRouteTarget';
3
- export * from './IAngularRouteEntry';
4
- export * from './IAngularRouteLike';
package/types/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./enumerations/AngularDecoratorMetaTarget"), exports);
18
- __exportStar(require("./enumerations/AngularRouteTarget"), exports);
19
- __exportStar(require("./IAngularRouteEntry"), exports);
20
- __exportStar(require("./IAngularRouteLike"), exports);