@igniteui/angular-templates 17.2.1321 → 17.2.1322-beta.0

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.
@@ -0,0 +1,93 @@
1
+ import * as ts from 'typescript';
2
+ import { KeyValuePair, FormatSettings, PropertyAssignment, TemplateDependency, TypeScriptFileUpdate } from '@igniteui/cli-core';
3
+ import { AngularRouteLike } from './types';
4
+ export declare class AngularTypeScriptFileUpdate extends TypeScriptFileUpdate {
5
+ protected targetPath: string;
6
+ private standalone;
7
+ constructor(targetPath: string, standalone?: boolean, formatSettings?: FormatSettings);
8
+ /**
9
+ * Adds a route entry to the Angular routing module's routes variable instance.
10
+ * @param route The route to add.
11
+ * @param multiline Whether to format the new entry as multiline.
12
+ * @param prepend Whether to insert the new entry before the anchor element.
13
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
14
+ * @param anchorElement The anchor element to insert to.
15
+ */
16
+ addRoute(route: AngularRouteLike, multiline?: boolean, prepend?: boolean, anchorElement?: PropertyAssignment): ts.SourceFile;
17
+ /**
18
+ * Adds a child route to a parent route.
19
+ * @param parentPath The path of the parent route.
20
+ * @param route The child route to add.
21
+ * @param asIdentifier Whether to initialize the {@link RouteTarget.Children} member with an identifier or an array literal.
22
+ * @param multiline Whether to format the new entry as multiline.
23
+ * @param prepend Whether to prepend the new added routes.
24
+ * @param anchorElement The anchor element to insert to.
25
+ * @remarks The `parentPath` is used to determine where the child route should be added.
26
+ */
27
+ addChildRoute(parentPath: string, route: AngularRouteLike, asIdentifier?: boolean, multiline?: boolean, prepend?: boolean, anchorElement?: PropertyAssignment): ts.SourceFile;
28
+ /** // TODO: update description
29
+ * Adds an import identifier to a standalone component's metadata.
30
+ * @param dep The dependency to add to the standalone component's metadata.
31
+ * @param variables Variables to replace in the dependency strings.
32
+ * @param multiline Whether to format the new entry as multiline.
33
+ */
34
+ addStandaloneComponentMeta(dep: TemplateDependency, variables?: KeyValuePair<string>, multiline?: boolean): ts.SourceFile;
35
+ /**
36
+ * Adds metadata to an NgModule decorator.
37
+ * @param dep The dependency to add to the NgModule decorator.
38
+ * @param variables Variables to replace in the dependency strings.
39
+ * @param multiline Whether to format the new entry as multiline.
40
+ */
41
+ addNgModuleMeta(dep: TemplateDependency, variables?: KeyValuePair<string>, multiline?: boolean): ts.SourceFile;
42
+ /**
43
+ * Adds a new not lazy-loaded route entry to the routes array. With a component identifier and path.
44
+ * @param route The route to add.
45
+ * @param visitCondition The condition used to find the appropriate route node.
46
+ * @param multiline Whether to format the new entry as multiline.
47
+ * @param prepend Whether to insert the new entry before the anchor element.
48
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
49
+ * @param anchorElement The anchor element to insert to.
50
+ */
51
+ protected addRouteEntry(route: AngularRouteLike, visitCondition: (node: ts.Node) => boolean, multiline: boolean, prepend: boolean, anchorElement: PropertyAssignment): ts.SourceFile;
52
+ /**
53
+ * Adds a new not lazy-loaded route entry to the routes array. With a redirect option.
54
+ * @param route The route to add.
55
+ * @param visitCondition The condition used to find the appropriate route node.
56
+ * @param multiline Whether to format the new entry as multiline.
57
+ * @param prepend Whether to insert the new entry before the anchor element.
58
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
59
+ * @param anchorElement The anchor element to insert to.
60
+ */
61
+ protected addRedirectRouteEntry(route: AngularRouteLike, visitCondition: (node: ts.Node) => boolean, multiline: boolean, prepend: boolean, anchorElement: PropertyAssignment): ts.SourceFile;
62
+ /**
63
+ * Updates an Angular decorator's metadata.
64
+ * @param name The name of the decorator to update.
65
+ * @param meta Names of identifiers to be added.
66
+ * @param target The target metadata property to update.
67
+ * @param multiline Whether to format the new entry as multiline.
68
+ */
69
+ private mutateNgDecoratorMeta;
70
+ /**
71
+ * Checks if a node has an ancestor with a specific decorator.
72
+ * @param name The name of the decorator.
73
+ * @param node The node to start checking from.
74
+ */
75
+ private checkNgDecorator;
76
+ /**
77
+ * Finds a property assignment that exists in a specific NG decorator meta.
78
+ * @param decoratorName The name of the decorator to check.
79
+ * @param propName The property name to check.
80
+ * @param node The node to start checking from.
81
+ */
82
+ private findNgDecoratorProperty;
83
+ /**
84
+ * Adds a new lazy-loaded route entry to the routes array.
85
+ * @param route The route to add.
86
+ * @param visitCondition The condition used to find the appropriate route node.
87
+ * @param multiline Whether to format the new entry as multiline.
88
+ * @param prepend Whether to insert the new entry before the anchor element.
89
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
90
+ * @param anchorElement The anchor element to insert to.
91
+ */
92
+ private addLazyLoadedRouteEntry;
93
+ }
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AngularTypeScriptFileUpdate = void 0;
4
+ const ts = require("typescript");
5
+ const cli_core_1 = require("@igniteui/cli-core");
6
+ const types_1 = require("./types");
7
+ class AngularTypeScriptFileUpdate extends cli_core_1.TypeScriptFileUpdate {
8
+ constructor(targetPath, standalone = false, formatSettings) {
9
+ super(targetPath, formatSettings);
10
+ this.targetPath = targetPath;
11
+ this.standalone = standalone;
12
+ }
13
+ //#region Public API
14
+ /**
15
+ * Adds a route entry to the Angular routing module's routes variable instance.
16
+ * @param route The route to add.
17
+ * @param multiline Whether to format the new entry as multiline.
18
+ * @param prepend Whether to insert the new entry before the anchor element.
19
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
20
+ * @param anchorElement The anchor element to insert to.
21
+ */
22
+ addRoute(route, multiline = false, prepend = true, anchorElement = cli_core_1.ANCHOR_ELEMENT) {
23
+ if (route.lazyload &&
24
+ route.path &&
25
+ route.identifierName &&
26
+ route.modulePath) {
27
+ return this.addLazyLoadedRouteEntry(route, (0, cli_core_1.RoutesVariableAsParentCondition)(this.astTransformer), multiline, prepend, anchorElement);
28
+ }
29
+ return this.addRedirectOrSimpleRouteEntry(route, (0, cli_core_1.RoutesVariableAsParentCondition)(this.astTransformer), multiline, prepend, anchorElement);
30
+ }
31
+ /**
32
+ * Adds a child route to a parent route.
33
+ * @param parentPath The path of the parent route.
34
+ * @param route The child route to add.
35
+ * @param asIdentifier Whether to initialize the {@link RouteTarget.Children} member with an identifier or an array literal.
36
+ * @param multiline Whether to format the new entry as multiline.
37
+ * @param prepend Whether to prepend the new added routes.
38
+ * @param anchorElement The anchor element to insert to.
39
+ * @remarks The `parentPath` is used to determine where the child route should be added.
40
+ */
41
+ addChildRoute(parentPath, route, asIdentifier = false, multiline = false, prepend = false, anchorElement = cli_core_1.ANCHOR_ELEMENT) {
42
+ if (route.lazyload &&
43
+ route.path &&
44
+ route.identifierName &&
45
+ route.modulePath) {
46
+ return this.addLazyLoadedRouteEntry(route, (0, cli_core_1.PropertyAssignmentWithStringLiteralValueCondition)(cli_core_1.RouteTarget.Path, parentPath), multiline, true, // prepend
47
+ cli_core_1.ANCHOR_ELEMENT);
48
+ }
49
+ return super.addChildRoute(parentPath, route, asIdentifier, multiline, prepend, anchorElement);
50
+ }
51
+ /** // TODO: update description
52
+ * Adds an import identifier to a standalone component's metadata.
53
+ * @param dep The dependency to add to the standalone component's metadata.
54
+ * @param variables Variables to replace in the dependency strings.
55
+ * @param multiline Whether to format the new entry as multiline.
56
+ */
57
+ addStandaloneComponentMeta(dep, variables, multiline = false) {
58
+ if (!this.standalone || !dep.standalone)
59
+ return this.astTransformer.sourceFile;
60
+ const copy = {
61
+ import: this.asArray(dep.import || [], variables || {}),
62
+ provide: this.asArray(dep.provide || [], variables || {}),
63
+ };
64
+ if (dep.from) {
65
+ // add an import declaration for the dependency
66
+ const uniqueIdentifiers = new Set([
67
+ ...copy.import,
68
+ ...copy.provide,
69
+ ]);
70
+ const identifiers = [...uniqueIdentifiers]
71
+ .filter((name) => !this.astTransformer.importDeclarationCollides({ name }))
72
+ .map((name) => ({ name }));
73
+ this.astTransformer.addImportDeclaration({
74
+ identifiers,
75
+ moduleName: this.applyConfigTransformation(dep.from, variables),
76
+ });
77
+ }
78
+ if (copy.import.length > 0) {
79
+ return this.mutateNgDecoratorMeta(cli_core_1.NG_SA_DECORATOR_NAME, copy.import, types_1.AngularDecoratorMetaTarget.Imports, multiline);
80
+ }
81
+ if (copy.provide.length > 0) {
82
+ return this.mutateNgDecoratorMeta(cli_core_1.NG_SA_DECORATOR_NAME, copy.provide, types_1.AngularDecoratorMetaTarget.Providers, multiline);
83
+ }
84
+ return this.astTransformer.sourceFile;
85
+ }
86
+ /**
87
+ * Adds metadata to an NgModule decorator.
88
+ * @param dep The dependency to add to the NgModule decorator.
89
+ * @param variables Variables to replace in the dependency strings.
90
+ * @param multiline Whether to format the new entry as multiline.
91
+ */
92
+ addNgModuleMeta(dep, variables, multiline = false) {
93
+ if (this.standalone || dep.standalone)
94
+ return this.astTransformer.sourceFile;
95
+ const copy = {
96
+ import: this.asArray(dep.import || [], variables || {}),
97
+ declare: this.asArray(dep.declare || [], variables || {}),
98
+ provide: this.asArray(dep.provide || [], variables || {}),
99
+ export: this.asArray(dep.export || [], variables || {}),
100
+ };
101
+ if (dep.from) {
102
+ // add an import declaration for the dependency
103
+ const uniqueIdentifiers = new Set([
104
+ ...copy.import,
105
+ ...copy.declare,
106
+ ...copy.provide,
107
+ ...copy.export,
108
+ ]);
109
+ const identifiers = [...uniqueIdentifiers]
110
+ .filter((name) => !this.astTransformer.importDeclarationCollides({ name }))
111
+ .map((name) => ({ name }));
112
+ this.astTransformer.addImportDeclaration({
113
+ identifiers,
114
+ moduleName: this.applyConfigTransformation(dep.from, variables),
115
+ });
116
+ }
117
+ if (dep.root && copy.import.length > 0) {
118
+ // add forRoot to the module
119
+ copy.import = copy.import.map((i) => this.astTransformer.printer.printNode(ts.EmitHint.Unspecified, this.astTransformer.createCallExpression(i, cli_core_1.NG_FOR_ROOT_IDENTIFIER_NAME), this.astTransformer.sourceFile));
120
+ }
121
+ if (copy.declare.length > 0) {
122
+ this.mutateNgDecoratorMeta(cli_core_1.NG_MODULE_DECORATOR_NAME, copy.declare, types_1.AngularDecoratorMetaTarget.Declarations, multiline);
123
+ }
124
+ if (copy.import.length > 0) {
125
+ this.mutateNgDecoratorMeta(cli_core_1.NG_MODULE_DECORATOR_NAME, copy.import, types_1.AngularDecoratorMetaTarget.Imports, multiline);
126
+ }
127
+ if (copy.provide.length > 0) {
128
+ this.mutateNgDecoratorMeta(cli_core_1.NG_MODULE_DECORATOR_NAME, copy.provide, types_1.AngularDecoratorMetaTarget.Providers, multiline);
129
+ }
130
+ if (copy.export.length > 0) {
131
+ this.mutateNgDecoratorMeta(cli_core_1.NG_MODULE_DECORATOR_NAME, copy.export, types_1.AngularDecoratorMetaTarget.Exports, multiline);
132
+ }
133
+ return this.astTransformer.sourceFile;
134
+ }
135
+ //#endregion
136
+ //#region Protected Overrides
137
+ /**
138
+ * Adds a new not lazy-loaded route entry to the routes array. With a component identifier and path.
139
+ * @param route The route to add.
140
+ * @param visitCondition The condition used to find the appropriate route node.
141
+ * @param multiline Whether to format the new entry as multiline.
142
+ * @param prepend Whether to insert the new entry before the anchor element.
143
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
144
+ * @param anchorElement The anchor element to insert to.
145
+ */
146
+ addRouteEntry(route, visitCondition, multiline = false, prepend = false, anchorElement) {
147
+ if (route.modulePath) {
148
+ // add an import for the given identifier
149
+ const routeIdentifier = { name: route.identifierName };
150
+ if (!this.astTransformer.importDeclarationCollides(routeIdentifier)) {
151
+ // if there is an identifierName, there must be a modulePath as well
152
+ this.astTransformer.addImportDeclaration({
153
+ identifiers: routeIdentifier,
154
+ moduleName: route.modulePath,
155
+ });
156
+ }
157
+ }
158
+ const structure = [
159
+ {
160
+ name: cli_core_1.RouteTarget.Path,
161
+ value: ts.factory.createStringLiteral(route.path),
162
+ },
163
+ {
164
+ name: cli_core_1.RouteTarget.Component,
165
+ value: ts.factory.createIdentifier(route.identifierName),
166
+ },
167
+ ];
168
+ if (route.data) {
169
+ structure.push({
170
+ name: types_1.AngularRouteTarget.Data,
171
+ value: this.astTransformer.createObjectLiteralExpression([route.data], multiline, ts.factory.createStringLiteral),
172
+ });
173
+ }
174
+ const newRoute = this.astTransformer.createObjectLiteralExpression(structure, multiline);
175
+ return this.astTransformer.addMembersToArrayLiteral(visitCondition, [newRoute], prepend, anchorElement);
176
+ }
177
+ /**
178
+ * Adds a new not lazy-loaded route entry to the routes array. With a redirect option.
179
+ * @param route The route to add.
180
+ * @param visitCondition The condition used to find the appropriate route node.
181
+ * @param multiline Whether to format the new entry as multiline.
182
+ * @param prepend Whether to insert the new entry before the anchor element.
183
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
184
+ * @param anchorElement The anchor element to insert to.
185
+ */
186
+ addRedirectRouteEntry(route, visitCondition, multiline = false, prepend = false, anchorElement) {
187
+ const structure = [
188
+ {
189
+ name: cli_core_1.RouteTarget.Path,
190
+ value: ts.factory.createStringLiteral(route.path || ''),
191
+ },
192
+ {
193
+ name: types_1.AngularRouteTarget.RedirectTo,
194
+ value: ts.factory.createStringLiteral(route.redirectTo),
195
+ },
196
+ ];
197
+ if (route.pathMatch) {
198
+ structure.push({
199
+ name: types_1.AngularRouteTarget.PathMatch,
200
+ value: ts.factory.createStringLiteral(route.pathMatch),
201
+ });
202
+ }
203
+ const newRoute = this.astTransformer.createObjectLiteralExpression(structure, multiline);
204
+ return this.astTransformer.addMembersToArrayLiteral(visitCondition, [newRoute], prepend, anchorElement);
205
+ }
206
+ //#endregion
207
+ //#region Internals
208
+ /**
209
+ * Updates an Angular decorator's metadata.
210
+ * @param name The name of the decorator to update.
211
+ * @param meta Names of identifiers to be added.
212
+ * @param target The target metadata property to update.
213
+ * @param multiline Whether to format the new entry as multiline.
214
+ */
215
+ mutateNgDecoratorMeta(name, meta, target, multiline = false) {
216
+ const identifiers = meta.map(ts.factory.createIdentifier);
217
+ const targetMetaProp = this.findNgDecoratorProperty(name, target);
218
+ if (!targetMetaProp) {
219
+ return this.astTransformer.addMemberToObjectLiteral((node) => this.checkNgDecorator(name, node), {
220
+ name: target,
221
+ value: this.astTransformer.createArrayLiteralExpression(identifiers, multiline),
222
+ });
223
+ }
224
+ if (ts.isArrayLiteralExpression(targetMetaProp.initializer)) {
225
+ // prop assignment of the form { member: [...] }
226
+ // store to avoid second type check due to different context in the filter
227
+ const elementsAsNodeArray = targetMetaProp.initializer.elements;
228
+ const elementsToAdd = identifiers.filter((i) => !elementsAsNodeArray.some((el) => el.getText() === i.text));
229
+ return this.astTransformer.addMembersToArrayLiteral((node) => ts.isPropertyAssignment(node.parent) &&
230
+ node.parent.name.getText() === target &&
231
+ this.checkNgDecorator(name, node), elementsToAdd);
232
+ }
233
+ // prop assignment of the form { member: <some-val> }
234
+ return this.astTransformer.updateObjectLiteralMember((node) => this.checkNgDecorator(name, node), {
235
+ name: target,
236
+ value: this.astTransformer.createArrayLiteralExpression([targetMetaProp.initializer, ...identifiers], multiline),
237
+ });
238
+ }
239
+ /**
240
+ * Checks if a node has an ancestor with a specific decorator.
241
+ * @param name The name of the decorator.
242
+ * @param node The node to start checking from.
243
+ */
244
+ checkNgDecorator(name, node) {
245
+ return !!this.astTransformer.findNodeAncestor(node, (node) => {
246
+ var _a;
247
+ return ts.isDecorator(node) &&
248
+ ((_a = node.expression.getFirstToken()) === null || _a === void 0 ? void 0 : _a.getText()) === name;
249
+ });
250
+ }
251
+ /**
252
+ * Finds a property assignment that exists in a specific NG decorator meta.
253
+ * @param decoratorName The name of the decorator to check.
254
+ * @param propName The property name to check.
255
+ * @param node The node to start checking from.
256
+ */
257
+ findNgDecoratorProperty(decoratorName, propName) {
258
+ return this.astTransformer.findPropertyAssignment((node) => node.name.getText() === propName &&
259
+ !!this.astTransformer.findNodeAncestor(node, (node) => {
260
+ var _a;
261
+ return ts.isDecorator(node) &&
262
+ ((_a = node.expression.getFirstToken()) === null || _a === void 0 ? void 0 : _a.getText()) === decoratorName;
263
+ }));
264
+ }
265
+ /**
266
+ * Adds a new lazy-loaded route entry to the routes array.
267
+ * @param route The route to add.
268
+ * @param visitCondition The condition used to find the appropriate route node.
269
+ * @param multiline Whether to format the new entry as multiline.
270
+ * @param prepend Whether to insert the new entry before the anchor element.
271
+ * If no anchor is provided, the new entry will be added to the start or end of the array.
272
+ * @param anchorElement The anchor element to insert to.
273
+ */
274
+ addLazyLoadedRouteEntry(route, visitCondition, multiline = false, prepend = false, anchorElement) {
275
+ const lazyLoadedModule = this.createDynamicImport(route.modulePath, route.identifierName, route.root);
276
+ const propAssignmentName = route.root
277
+ ? types_1.AngularRouteTarget.LoadChildren
278
+ : types_1.AngularRouteTarget.LoadComponent;
279
+ const structure = [
280
+ {
281
+ name: cli_core_1.RouteTarget.Path,
282
+ value: ts.factory.createStringLiteral(route.path),
283
+ },
284
+ { name: propAssignmentName, value: lazyLoadedModule },
285
+ ];
286
+ if (route.data) {
287
+ structure.push({
288
+ name: types_1.AngularRouteTarget.Data,
289
+ value: this.astTransformer.createObjectLiteralExpression([route.data], multiline, ts.factory.createStringLiteral),
290
+ });
291
+ }
292
+ const newRoute = this.astTransformer.createObjectLiteralExpression(structure, multiline);
293
+ return this.astTransformer.addMembersToArrayLiteral(visitCondition, [newRoute], prepend, anchorElement);
294
+ }
295
+ }
296
+ exports.AngularTypeScriptFileUpdate = AngularTypeScriptFileUpdate;
@@ -1,9 +1,10 @@
1
- import { AddTemplateArgs, ControlExtraConfiguration, Template, TemplateDependency, TypeScriptFileUpdate } from "@igniteui/cli-core";
1
+ import { AddTemplateArgs, ControlExtraConfiguration, Template, TemplateDependency } 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;
7
8
  listInCustomTemplates: boolean;
8
9
  id: string;
9
10
  name: string;
@@ -32,7 +33,6 @@ export declare class IgniteUIForAngularTemplate implements Template {
32
33
  getExtraConfiguration(): ControlExtraConfiguration[];
33
34
  setExtraConfiguration(extraConfigKeys: {}): void;
34
35
  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,6 +10,7 @@ class IgniteUIForAngularTemplate {
10
10
  constructor(rootPath) {
11
11
  this.rootPath = rootPath;
12
12
  this.listInComponentTemplates = true;
13
+ this.addAsNgModelDeclaration = true;
13
14
  this.listInCustomTemplates = false;
14
15
  this.framework = "angular";
15
16
  this.projectType = "igx-ts";
@@ -46,32 +47,46 @@ class IgniteUIForAngularTemplate {
46
47
  // tslint:disable-next-line:variable-name
47
48
  const TsUpdate =
48
49
  // tslint:disable-next-line:no-submodule-imports
49
- require("@igniteui/cli-core/typescript").TypeScriptFileUpdate;
50
- // standalone components
50
+ require("@igniteui/angular-templates").AngularTypeScriptFileUpdate;
51
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`;
56
+ // standalone components
52
57
  if (!this.fileExists(mainModulePath)) {
53
58
  const appRoutesPath = "src/app/app.routes.ts";
54
- const folderName = this.folderName(name);
55
- const fileName = this.fileName(name);
56
59
  if (!(options && options.skipRoute) && this.fileExists(appRoutesPath)) {
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
- );
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
+ }
61
73
  }
62
- const componentFile = new TsUpdate(path.join(projectPath, `src/app/${folderName}/${fileName}.component.ts`));
74
+ const componentFile = new TsUpdate(componentFilePath, true, { indentSize: 2 });
63
75
  for (const dep of this.dependencies) {
64
76
  if (dep.from && dep.from.startsWith(".")) {
65
77
  // relative file dependency
66
78
  const copy = Object.assign({}, dep);
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));
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));
70
81
  continue;
71
82
  }
72
- componentFile.addStandaloneImport(dep, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
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);
73
89
  }
74
- componentFile.finalize();
75
90
  return;
76
91
  }
77
92
  // ngModule based components
@@ -79,15 +94,28 @@ class IgniteUIForAngularTemplate {
79
94
  //1) import the component class name,
80
95
  //2) and populate the Routes array with the path and component
81
96
  //for example: { path: 'combo', component: ComboComponent }
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
- );
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
+ }
86
110
  }
87
111
  //3) add an import of the component class from its file location.
88
112
  //4) populate the declarations portion of the @NgModule with the component class name.
89
- const mainModule = new TsUpdate(mainModulePath);
90
- this.addClassDeclaration(mainModule, projectPath, name, modulePath);
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
+ });
91
119
  // import IgxModules and other dependencies
92
120
  for (const dep of this.dependencies) {
93
121
  if (dep.from && dep.from.startsWith(".")) {
@@ -100,7 +128,11 @@ class IgniteUIForAngularTemplate {
100
128
  mainModule.addNgModuleMeta(dep, cli_core_1.Util.applyDelimiters(this.getBaseVariables(name), this.delimiters.content));
101
129
  }
102
130
  }
103
- mainModule.finalize();
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
+ }
104
136
  }
105
137
  getExtraConfiguration() {
106
138
  return [];
@@ -109,9 +141,6 @@ class IgniteUIForAngularTemplate {
109
141
  fileExists(filePath) {
110
142
  return cli_core_1.App.container.get(cli_core_1.FS_TOKEN).fileExists(filePath);
111
143
  }
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
- }
115
144
  getBaseVariables(name) {
116
145
  const config = {};
117
146
  config["name"] = cli_core_1.Util.nameFromPath(name);
@@ -15,8 +15,5 @@ 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
- }
21
18
  }
22
19
  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" });
98
+ this.dependencies.push({ import: "FormsModule", from: "@angular/forms", standalone: true });
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%>" });
110
+ this.dependencies.push({ import: "IgxDatePickerComponent", from: "<%=igxPackage%>", standalone: true });
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" });
114
+ this.dependencies.push({ import: "FormsModule", from: "@angular/forms", standalone: true });
115
115
  break;
116
116
  case "Row Selection":
117
117
  const gridFeatureText = `rowSelection="multiple"`;
@@ -8,6 +8,7 @@ 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;
11
12
  this.id = "dock-manager";
12
13
  this.projectType = "igx-ts";
13
14
  this.name = "Dock Manager";
@@ -18,8 +19,5 @@ class IgcDockManagerTemplate extends IgniteUIForAngularTemplate_1.IgniteUIForAng
18
19
  // "igniteui-dockmanager@~1.0.0":
19
20
  this.packages = [`${(0, cli_core_1.resolvePackage)(cli_core_1.NPM_DOCK_MANAGER)}@~1.8.0`];
20
21
  }
21
- addClassDeclaration(mainModule, projPath, name, modulePath) {
22
- // not applicable with custom module
23
- }
24
22
  }
25
23
  module.exports = new IgcDockManagerTemplate();
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import * as standalone from "./igx-ts";
2
- export * from "./IgniteUIForAngularTemplate";
1
+ import * as standalone from './igx-ts';
2
+ export * from './IgniteUIForAngularTemplate';
3
+ export * from './AngularTypeScriptFileUpdate';
4
+ export * from './types';
3
5
  declare const _default: (typeof standalone)[];
4
6
  export default _default;
package/index.js CHANGED
@@ -17,4 +17,6 @@ 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);
20
22
  exports.default = [standalone, legacy];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igniteui/angular-templates",
3
- "version": "17.2.1321",
3
+ "version": "17.2.1322-beta.0",
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.2.1",
15
+ "@igniteui/cli-core": "~13.2.2-beta.0",
16
16
  "typescript": "~5.4.3"
17
17
  }
18
18
  }
@@ -0,0 +1,6 @@
1
+ import { RouteEntry, RouteTarget } from "@igniteui/cli-core";
2
+ import { AngularRouteTarget } from "./enumerations/AngularRouteTarget";
3
+ /** Represents an Angular route entry in a routes collection. */
4
+ export interface AngularRouteEntry extends Pick<RouteEntry, "value"> {
5
+ name: RouteTarget | AngularRouteTarget;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { RouteLike, KeyValuePair } from "@igniteui/cli-core";
2
+ /** A route member in an Angular routes collection. */
3
+ export interface AngularRouteLike extends RouteLike {
4
+ /** The path-matching strategy, one of 'prefix' or 'full'. Default is 'prefix'. */
5
+ pathMatch?: "prefix" | "full";
6
+ /** For lazy loaded routes - if it should load the routes' children or its component. */
7
+ root?: boolean;
8
+ /** Additional developer-defined data provided to the component via `ActivatedRoute`. */
9
+ data?: KeyValuePair<string>;
10
+ /** An array of child `Route` objects that specifies a nested route configuration. */
11
+ children?: AngularRouteLike | AngularRouteLike[];
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ /** Represents possible meta data members in an Angular decorator. */
2
+ export declare enum AngularDecoratorMetaTarget {
3
+ Imports = "imports",
4
+ Declarations = "declarations",
5
+ Providers = "providers",
6
+ Exports = "exports"
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AngularDecoratorMetaTarget = void 0;
4
+ /** Represents possible meta data members in an Angular decorator. */
5
+ var AngularDecoratorMetaTarget;
6
+ (function (AngularDecoratorMetaTarget) {
7
+ AngularDecoratorMetaTarget["Imports"] = "imports";
8
+ AngularDecoratorMetaTarget["Declarations"] = "declarations";
9
+ AngularDecoratorMetaTarget["Providers"] = "providers";
10
+ AngularDecoratorMetaTarget["Exports"] = "exports";
11
+ })(AngularDecoratorMetaTarget || (exports.AngularDecoratorMetaTarget = AngularDecoratorMetaTarget = {}));
@@ -0,0 +1,10 @@
1
+ /** Represents possible members in an Angular route object. */
2
+ export declare enum AngularRouteTarget {
3
+ PathMatch = "pathMatch",
4
+ Root = "root",
5
+ Data = "data",
6
+ Children = "children",
7
+ RedirectTo = "redirectTo",
8
+ LoadChildren = "loadChildren",
9
+ LoadComponent = "loadComponent"
10
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AngularRouteTarget = void 0;
4
+ /** Represents possible members in an Angular route object. */
5
+ var AngularRouteTarget;
6
+ (function (AngularRouteTarget) {
7
+ AngularRouteTarget["PathMatch"] = "pathMatch";
8
+ AngularRouteTarget["Root"] = "root";
9
+ AngularRouteTarget["Data"] = "data";
10
+ AngularRouteTarget["Children"] = "children";
11
+ AngularRouteTarget["RedirectTo"] = "redirectTo";
12
+ AngularRouteTarget["LoadChildren"] = "loadChildren";
13
+ AngularRouteTarget["LoadComponent"] = "loadComponent";
14
+ })(AngularRouteTarget || (exports.AngularRouteTarget = AngularRouteTarget = {}));
@@ -0,0 +1,4 @@
1
+ export * from "./enumerations/AngularDecoratorMetaTarget";
2
+ export * from "./enumerations/AngularRouteTarget";
3
+ export * from "./AngularRouteEntry";
4
+ export * from "./AngularRouteLike";
package/types/index.js ADDED
@@ -0,0 +1,20 @@
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("./AngularRouteEntry"), exports);
20
+ __exportStar(require("./AngularRouteLike"), exports);