@magic-xpa/cli 4.1300.0-dev4130.26 → 4.1300.0-dev4130.260
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/schematics/magic-utils/Util.js +2 -1
- package/src/schematics/magic-utils/Util.js.map +1 -1
- package/src/schematics/magic-utils/config.js +2 -2
- package/src/schematics/magic-utils/config.js.map +1 -1
- package/src/schematics/magic-utils/config.ts +2 -2
- package/src/schematics/magic-utils/env.js +12 -11
- package/src/schematics/magic-utils/env.js.map +1 -1
- package/src/schematics/magic-utils/env.ts +16 -15
- package/src/schematics/magic-utils/metadata.class.js +1 -1
- package/src/schematics/magic-utils/metadata.class.js.map +1 -1
- package/src/schematics/magic-utils/metadata.class.ts +1 -1
- package/src/schematics/magic-utils/rules/build-control.rule.js +3 -2
- package/src/schematics/magic-utils/rules/build-control.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/component-list.rule.js +3 -2
- package/src/schematics/magic-utils/rules/component-list.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/generate.rule.js +3 -2
- package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
- package/src/schematics/mg-add/files/src/app/app.routes.ts +2 -1
- package/src/schematics/mg-add/files/src/app/custom.routes.ts +23 -0
- package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +6 -7
- package/src/schematics/mg-add/index.js +129 -10
- package/src/schematics/mg-add/index.js.map +1 -1
- package/src/schematics/mg-add/index.ts +149 -10
- package/src/schematics/mg-add/webModule/app.routes.ts +2 -1
- package/src/schematics/mg-add/webModule/custom.routes.ts +23 -0
- package/src/schematics/mg-routes/index.js +13 -4
- package/src/schematics/mg-routes/index.js.map +1 -1
- package/src/schematics/mg-routes/index.ts +16 -5
- package/src/schematics/utils/ast.js +2 -1
- package/src/schematics/utils/ast.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils.js +2 -1
- package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils_old.js +2 -1
- package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
- package/src/schematics/utils/devkit-utils/component.js +2 -1
- package/src/schematics/utils/devkit-utils/component.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ng-ast-utils.js +2 -1
- package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
- package/src/schematics/utils/devkit-utils/route-utils.js +2 -1
- package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
- package/src/schematics/utils/html.js +2 -1
- package/src/schematics/utils/html.js.map +1 -1
- package/templates/angular/src/{app.module.ts → app-module.ts} +3 -3
- package/templates/angular/src/app.routes.ts +2 -0
- package/templates/angular/src/{app.component.ts → app.ts} +1 -1
- package/templates/angular/src/custom.routes.ts +23 -0
- package/templates/attributes/common/row_editing_button_attributes.ejs +2 -2
- package/templates/component/view.component.ts +5 -56
- package/templates/themes/basicHTML/combobox.ejs +10 -7
- package/templates/themes/basicHTML/edit.ejs +20 -10
- package/templates/themes/basicHTML/image.ejs +3 -2
- package/templates/themes/basicHTML/listbox.ejs +3 -4
- package/templates/themes/basicHTML/push-button.ejs +0 -1
- package/templates/themes/basicHTML/radio.ejs +24 -3
- package/templates/themes/basicHTML/tab.ejs +3 -1
- package/templates/themes/basicHiddenHTML/radio.ejs +3 -2
- package/templates/themes/basicHiddenHTML/table.ejs +7 -3
- package/templates/themes/container.ejs +12 -1
- package/templates/themes/material/combobox.ejs +12 -7
- package/templates/themes/material/edit.ejs +32 -28
- package/templates/themes/material/listbox.ejs +3 -4
- package/templates/themes/material/push-button.ejs +0 -1
- package/templates/themes/material/radio.ejs +29 -12
- package/templates/themes/material/tab.ejs +3 -1
- package/templates/themes/table/HTMLTable/table.ejs +7 -3
- package/templates/themes/table/repeatable/table.ejs +7 -3
- package/tsconfig.json +2 -0
- /package/src/schematics/mg-add/files/src/app/{app.component.html → app.html} +0 -0
- /package/templates/angular/src/app/{app.component.html.ejs → app.html.ejs} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mgAdd = mgAdd;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
6
|
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
6
7
|
const package_1 = require("./../utils/package");
|
|
@@ -12,7 +13,7 @@ const Util_1 = require("../magic-utils/Util");
|
|
|
12
13
|
const generate_rule_1 = require("../magic-utils/rules/generate.rule");
|
|
13
14
|
const generated_file_types_enum_1 = require("../../types/enums/generated-file-types.enum");
|
|
14
15
|
const ast_utils_1 = require("../utils/devkit-utils/ast-utils");
|
|
15
|
-
const ts = require("typescript");
|
|
16
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
16
17
|
const change_1 = require("../utils/devkit-utils/change");
|
|
17
18
|
function mgAdd(options) {
|
|
18
19
|
return (0, schematics_1.chain)([
|
|
@@ -24,7 +25,8 @@ function mgAdd(options) {
|
|
|
24
25
|
updateAngularJsonWithMagicStyle(options),
|
|
25
26
|
updateTsConfigAppJson(options),
|
|
26
27
|
addLazyLoadProvider(),
|
|
27
|
-
|
|
28
|
+
addZoneChangeDetectionProviderRule(),
|
|
29
|
+
//handel app.html
|
|
28
30
|
//updateAppComponentHtmlFiles (options),
|
|
29
31
|
//handel package.Json
|
|
30
32
|
//addMagicDependenciesToPackageJson (options),
|
|
@@ -32,8 +34,8 @@ function mgAdd(options) {
|
|
|
32
34
|
}
|
|
33
35
|
function updateAppComponentHtmlFiles(options) {
|
|
34
36
|
return (0, generate_rule_1.generate)({
|
|
35
|
-
template: "./templates/angular/src/app/app.
|
|
36
|
-
name: "app.
|
|
37
|
+
template: "./templates/angular/src/app/app.html.ejs",
|
|
38
|
+
name: "app.html",
|
|
37
39
|
destination: env_1.env.metadata.paths.rootMagicGenFolder,
|
|
38
40
|
type: generated_file_types_enum_1.GeneratedFileTypes.HTML,
|
|
39
41
|
data: {
|
|
@@ -43,19 +45,36 @@ function updateAppComponentHtmlFiles(options) {
|
|
|
43
45
|
}
|
|
44
46
|
function updateAngularJsonWithMagicStyle(options) {
|
|
45
47
|
return (host, context) => {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
46
49
|
const project = env_1.env.project;
|
|
47
50
|
let isDirty = false;
|
|
48
51
|
let fullPathmagicStylePath = env_1.env.metadata.paths.magicStylePath;
|
|
49
|
-
if (!project.architect.test.options.styles.includes(fullPathmagicStylePath)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
52
|
+
// if (!project.architect.test.options.styles.includes(fullPathmagicStylePath)) {
|
|
53
|
+
// context.logger.info(` [>]add file ${fullPathmagicStylePath} to test`);
|
|
54
|
+
// project.architect.test.options.styles.push(fullPathmagicStylePath);
|
|
55
|
+
// isDirty = true;
|
|
56
|
+
// }
|
|
54
57
|
if (!project.architect.build.options.styles.includes(fullPathmagicStylePath)) {
|
|
55
58
|
context.logger.info(` [>]add file ${fullPathmagicStylePath} to build`);
|
|
56
59
|
project.architect.build.options.styles.push(fullPathmagicStylePath);
|
|
57
60
|
isDirty = true;
|
|
58
61
|
}
|
|
62
|
+
const buildOptions = (_b = (_a = project === null || project === void 0 ? void 0 : project.architect) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.options;
|
|
63
|
+
const testOptions = (_d = (_c = project === null || project === void 0 ? void 0 : project.architect) === null || _c === void 0 ? void 0 : _c.test) === null || _d === void 0 ? void 0 : _d.options;
|
|
64
|
+
if (buildOptions) {
|
|
65
|
+
const changed = ensurePolyfills(buildOptions, ['zone.js']);
|
|
66
|
+
if (changed) {
|
|
67
|
+
context.logger.info(` [>]add polyfill zone.js to build`);
|
|
68
|
+
isDirty = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (testOptions) {
|
|
72
|
+
const changed = ensurePolyfills(testOptions, ['zone.js', 'zone.js/testing']);
|
|
73
|
+
if (changed) {
|
|
74
|
+
context.logger.info(` [>]add polyfills zone.js, zone.js/testing to test`);
|
|
75
|
+
isDirty = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
59
78
|
if (isDirty) {
|
|
60
79
|
let fullPath = env_1.env.metadata.paths.angularJsonPath;
|
|
61
80
|
host.overwrite(fullPath, JSON.stringify(env_1.env.workspace, null, 2));
|
|
@@ -63,6 +82,26 @@ function updateAngularJsonWithMagicStyle(options) {
|
|
|
63
82
|
return host;
|
|
64
83
|
};
|
|
65
84
|
}
|
|
85
|
+
function ensurePolyfills(options, requiredPolyfills) {
|
|
86
|
+
let polyfills = [];
|
|
87
|
+
if (Array.isArray(options.polyfills)) {
|
|
88
|
+
polyfills = [...options.polyfills];
|
|
89
|
+
}
|
|
90
|
+
else if (typeof options.polyfills === 'string' && options.polyfills.trim()) {
|
|
91
|
+
polyfills = [options.polyfills];
|
|
92
|
+
}
|
|
93
|
+
let changed = !Array.isArray(options.polyfills);
|
|
94
|
+
for (const entry of requiredPolyfills) {
|
|
95
|
+
if (!polyfills.includes(entry)) {
|
|
96
|
+
polyfills.push(entry);
|
|
97
|
+
changed = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (changed) {
|
|
101
|
+
options.polyfills = polyfills;
|
|
102
|
+
}
|
|
103
|
+
return changed;
|
|
104
|
+
}
|
|
66
105
|
// Angular 10 , does not include .ts file for compilation
|
|
67
106
|
// So to avoid compilation error , add *.module.ts in includes section
|
|
68
107
|
function updateTsConfigAppJson(option) {
|
|
@@ -78,6 +117,10 @@ function updateTsConfigAppJson(option) {
|
|
|
78
117
|
//Add module files for compilation
|
|
79
118
|
if (!config['include'].includes('src/**/*module.ts'))
|
|
80
119
|
config['include'].push('src/**/*module.ts');
|
|
120
|
+
if (!config['compilerOptions'])
|
|
121
|
+
config['compilerOptions'] = {};
|
|
122
|
+
// Ensures forceConsistentCasingInFileNames is set to false inorder to avoid path casing differences while compilation
|
|
123
|
+
config['compilerOptions']['forceConsistentCasingInFileNames'] = false;
|
|
81
124
|
// append the comment again and write the file
|
|
82
125
|
host.overwrite(tsConfigPath, comment + "\n" + JSON.stringify(config, null, 2));
|
|
83
126
|
return host;
|
|
@@ -123,7 +166,7 @@ function addMagicModuleToAppModule(options) {
|
|
|
123
166
|
}
|
|
124
167
|
function addLazyLoadProvider() {
|
|
125
168
|
return (host) => {
|
|
126
|
-
const appmodule = env_1.env.metadata.paths.rootMagicGenFolder + '/app
|
|
169
|
+
const appmodule = env_1.env.metadata.paths.rootMagicGenFolder + '/app-module.ts';
|
|
127
170
|
const lazyLoaderService = 'LazyLoaderService';
|
|
128
171
|
const lazyLoaderServicePath = './magic/lazy-loader.service';
|
|
129
172
|
let text = host.read(appmodule);
|
|
@@ -138,16 +181,92 @@ function addLazyLoadProvider() {
|
|
|
138
181
|
}
|
|
139
182
|
}
|
|
140
183
|
host.commitUpdate(providerRecorder);
|
|
184
|
+
sourceText = host.read(appmodule).toString('utf-8');
|
|
185
|
+
source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
141
186
|
const lazyLoaderServiceImport = (0, ast_utils_1.insertImport)(source, appmodule, lazyLoaderService, lazyLoaderServicePath, false);
|
|
142
187
|
const lazyLoaderServiceChangesRecorder = host.beginUpdate(appmodule);
|
|
143
188
|
if (lazyLoaderServiceImport instanceof change_1.InsertChange)
|
|
144
189
|
lazyLoaderServiceChangesRecorder.insertLeft(lazyLoaderServiceImport.pos, lazyLoaderServiceImport.toAdd);
|
|
145
190
|
host.commitUpdate(lazyLoaderServiceChangesRecorder);
|
|
146
191
|
// add import for MagicLazyLoaderService
|
|
192
|
+
sourceText = host.read(appmodule).toString('utf-8');
|
|
193
|
+
source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
147
194
|
const magicLazyLoaderServiceImportChanges = (0, ast_utils_1.insertImport)(source, appmodule, 'MagicLazyLoaderService', '@magic-xpa/angular', false);
|
|
148
195
|
const magicImportChangesRecorder = host.beginUpdate(appmodule);
|
|
149
196
|
magicImportChangesRecorder.insertLeft(magicLazyLoaderServiceImportChanges.pos, magicLazyLoaderServiceImportChanges.toAdd);
|
|
150
197
|
host.commitUpdate(magicImportChangesRecorder);
|
|
151
198
|
};
|
|
152
199
|
}
|
|
200
|
+
function addZoneChangeDetectionProviderRule() {
|
|
201
|
+
return (host) => {
|
|
202
|
+
// Resolve the generated root module path (src/app/app-module.ts in this project layout).
|
|
203
|
+
const appmodule = env_1.env.metadata.paths.rootMagicGenFolder + '/app-module.ts';
|
|
204
|
+
// Append provideZoneChangeDetection() to NgModule.providers if it does not already exist.
|
|
205
|
+
addZoneChangeDetectionProvider(host, appmodule);
|
|
206
|
+
// Re-parse from disk after provider update so import insertion uses fresh AST positions.
|
|
207
|
+
const sourceText = host.read(appmodule).toString('utf-8');
|
|
208
|
+
const source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
209
|
+
// Ensure the symbol import exists; insertImport is idempotent and avoids duplicates.
|
|
210
|
+
const zoneChangeDetectionImport = (0, ast_utils_1.insertImport)(source, appmodule, 'provideZoneChangeDetection', '@angular/core', false);
|
|
211
|
+
const zoneChangeDetectionImportChangesRecorder = host.beginUpdate(appmodule);
|
|
212
|
+
if (zoneChangeDetectionImport instanceof change_1.InsertChange)
|
|
213
|
+
zoneChangeDetectionImportChangesRecorder.insertLeft(zoneChangeDetectionImport.pos, zoneChangeDetectionImport.toAdd);
|
|
214
|
+
host.commitUpdate(zoneChangeDetectionImportChangesRecorder);
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function addZoneChangeDetectionProvider(host, appmodule) {
|
|
218
|
+
const zoneProvider = 'provideZoneChangeDetection()';
|
|
219
|
+
const sourceText = host.read(appmodule).toString('utf-8');
|
|
220
|
+
const source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
221
|
+
// Locate the first @NgModule({...}) metadata object in app-module.ts.
|
|
222
|
+
const ngModules = (0, ast_utils_1.getDecoratorMetadata)(source, 'NgModule', '@angular/core');
|
|
223
|
+
if (!ngModules.length) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const ngModuleMetadata = ngModules[0];
|
|
227
|
+
// Find the `providers` property assignment inside @NgModule metadata.
|
|
228
|
+
const providersProperty = ngModuleMetadata.properties
|
|
229
|
+
.filter(ts.isPropertyAssignment)
|
|
230
|
+
.find((prop) => {
|
|
231
|
+
if (ts.isIdentifier(prop.name)) {
|
|
232
|
+
return prop.name.text === 'providers';
|
|
233
|
+
}
|
|
234
|
+
return ts.isStringLiteral(prop.name) && prop.name.text === 'providers';
|
|
235
|
+
});
|
|
236
|
+
if (!providersProperty || !ts.isArrayLiteralExpression(providersProperty.initializer)) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const providersArray = providersProperty.initializer;
|
|
240
|
+
// Keep this operation idempotent: do nothing if provider already exists.
|
|
241
|
+
const hasZoneProvider = providersArray.elements.some((el) => {
|
|
242
|
+
return el.getText(source).replace(/\s+/g, '') === zoneProvider;
|
|
243
|
+
});
|
|
244
|
+
if (hasZoneProvider) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let insertPos;
|
|
248
|
+
let toAdd;
|
|
249
|
+
if (providersArray.elements.length === 0) {
|
|
250
|
+
// Empty providers: inject the item directly between [].
|
|
251
|
+
insertPos = providersArray.getEnd() - 1;
|
|
252
|
+
toAdd = zoneProvider;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Non-empty providers: append after last provider, preserving line formatting when possible.
|
|
256
|
+
const lastProvider = providersArray.elements[providersArray.elements.length - 1];
|
|
257
|
+
insertPos = lastProvider.getEnd();
|
|
258
|
+
const lastProviderText = lastProvider.getFullText(source);
|
|
259
|
+
const newLineMatch = lastProviderText.match(/^\r?\n(\r?)\s+/);
|
|
260
|
+
if (newLineMatch) {
|
|
261
|
+
toAdd = `,${newLineMatch[0]}${zoneProvider}`;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
toAdd = `, ${zoneProvider}`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Apply the computed insertion at the exact Abstract Syntax Tree-derived position.
|
|
268
|
+
const recorder = host.beginUpdate(appmodule);
|
|
269
|
+
recorder.insertLeft(insertPos, toAdd);
|
|
270
|
+
host.commitUpdate(recorder);
|
|
271
|
+
}
|
|
153
272
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAoBA,sBAoBC;AAxCD,2DAKoC;AACpC,4DAAwE;AAExE,gDAA2D;AAC3D,4CAAuE;AACvE,gDAAwE;AACxE,4FAAiF;AACjF,sCAA2D;AAC3D,8CAA4C;AAC5C,sEAA8D;AAC9D,2FAAiF;AAEjF,+DAAkF;AAClF,iCAAiC;AACjC,yDAA0D;AAC1D,SAAgB,KAAK,CAAC,OAAyB;IAC7C,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,4CAAiB,EAAkB,OAAO,CAAC;QAC3C,IAAA,sBAAc,EAAqB,OAAO,CAAC;QAE3C,wBAAwB;QACxB,yBAAyB,CAAU,OAAO,CAAC;QAE3C,sBAAsB;QACtB,+BAA+B,CAAI,OAAO,CAAC;QAE3C,qBAAqB,CAAG,OAAO,CAAC;QAEhC,mBAAmB,EAAE;QACrB,4BAA4B;QAC5B,8CAA8C;QAE9C,qBAAqB;QACrB,8CAA8C;KAC/C,CAAC,CAAC;AACL,CAAC;AAED,SAAS,2BAA2B,CAAC,OAAyB;IAC5D,OAAO,IAAA,wBAAQ,EAAC;QACd,QAAQ,EAAM,oDAAoD;QAClE,IAAI,EAAU,oBAAoB;QAClC,WAAW,EAAG,SAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,kBAAkB;QACnD,IAAI,EAAS,8CAAkB,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EAAE,iBAAiB,EAAE,qBAAqB,EAAE,KAAK,CAAC,CAAC;QACjH,MAAM,gCAAgC,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACrE,IAAI,uBAAuB,YAAY,qBAAY;YACjD,gCAAgC,CAAC,UAAU,CAAC,uBAAuB,CAAC,GAAG,EAAE,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAC1G,IAAI,CAAC,YAAY,CAAC,gCAAgC,CAAC,CAAC;QAEpD,wCAAwC;QACxC,MAAM,mCAAmC,GAA+B,IAAA,wBAAY,EAAC,MAAM,EAAE,SAAS,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAC/J,MAAM,0BAA0B,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC/D,0BAA0B,CAAC,UAAU,CAAC,mCAAmC,CAAC,GAAG,EAAE,mCAAmC,CAAC,KAAK,CAAC,CAAA;QACzH,IAAI,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAAC;IAChD,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {\r\n Rule,\r\n chain,\r\n Tree,\r\n SchematicContext\r\n} from \"@angular-devkit/schematics\";\r\nimport {NodePackageInstallTask} from \"@angular-devkit/schematics/tasks\";\r\n\r\nimport {addPackageToPackageJson} from './../utils/package';\r\nimport { dependencies, devDependencies, env} from \"../magic-utils/env\";\r\nimport { addImportTSModule, copyMagicFiles} from \"../magic-utils/utils\";\r\nimport { initMagicMetadata} from \"../magic-utils/rules/init-magic-metadata.rule\";\r\nimport { addModuleImportToRootModule } from \"../utils/ast\";\r\nimport { LogLn } from \"../magic-utils/Util\";\r\nimport { generate } from \"../magic-utils/rules/generate.rule\";\r\nimport { GeneratedFileTypes } from \"../../types/enums/generated-file-types.enum\";\r\nimport { MagicOptionScheme } from \"../magic-utils/rules/magic-option.scheme\";\r\nimport {addProviderToModule, insertImport} from \"../utils/devkit-utils/ast-utils\";\r\nimport * as ts from 'typescript';\r\nimport {InsertChange} from \"../utils/devkit-utils/change\";\r\nexport function mgAdd(options:MagicOptionScheme): Rule {\r\n return chain([\r\n initMagicMetadata (options),\r\n copyMagicFiles (options),\r\n\r\n // handel app.modules.ts\r\n addMagicModuleToAppModule (options),\r\n\r\n // handel Angular.json\r\n updateAngularJsonWithMagicStyle (options),\r\n\r\n updateTsConfigAppJson (options),\r\n\r\n addLazyLoadProvider(),\r\n // handel app.component.html\r\n //updateAppComponentHtmlFiles (options),\r\n\r\n //handel package.Json\r\n //addMagicDependenciesToPackageJson (options),\r\n ]);\r\n}\r\n\r\nfunction updateAppComponentHtmlFiles(options:MagicOptionScheme): Rule {\r\n return generate({\r\n template : \"./templates/angular/src/app/app.component.html.ejs\",\r\n name : \"app.component.html\",\r\n destination : env.metadata.paths.rootMagicGenFolder,\r\n type :GeneratedFileTypes.HTML,\r\n data : {\r\n skipHelp : options.skipHelp\r\n }\r\n },options)\r\n}\r\nfunction updateAngularJsonWithMagicStyle(options:MagicOptionScheme): Rule {\r\n return (host: Tree, context: SchematicContext) => {\r\n const project = env.project;\r\n let isDirty = false;\r\n\r\n let fullPathmagicStylePath = env.metadata.paths.magicStylePath;\r\n if (!project.architect.test.options.styles.includes(fullPathmagicStylePath)) {\r\n context.logger.info(` [>]add file ${fullPathmagicStylePath} to test`);\r\n project.architect.test.options.styles.push(fullPathmagicStylePath);\r\n isDirty = true;\r\n }\r\n\r\n if (!project.architect.build.options.styles.includes(fullPathmagicStylePath)) {\r\n context.logger.info(` [>]add file ${fullPathmagicStylePath} to build`);\r\n project.architect.build.options.styles.push(fullPathmagicStylePath);\r\n isDirty = true;\r\n }\r\n\r\n if(isDirty){\r\n let fullPath = env.metadata.paths.angularJsonPath;\r\n host.overwrite(fullPath, JSON.stringify(env.workspace, null, 2));\r\n }\r\n\r\n return host;\r\n };\r\n}\r\n\r\n// Angular 10 , does not include .ts file for compilation\r\n// So to avoid compilation error , add *.module.ts in includes section\r\nfunction updateTsConfigAppJson (option: MagicOptionScheme): Rule{\r\n return (host: Tree, context: SchematicContext) => {\r\n\r\n const tsConfigPath = env.metadata.paths.tsConfigAppJsonPath;\r\n const tsConfig = host.read(tsConfigPath).toString();\r\n\r\n // extract the comment\r\n let firstIndex = tsConfig.indexOf('*/');\r\n let secondIndex = tsConfig.indexOf('*/', firstIndex + 2);\r\n let comment = tsConfig.substring(0, secondIndex + 2);\r\n\r\n // replace the comment as parsing json with comment throws exception\r\n var config = JSON.parse(tsConfig.replace(comment, ''));\r\n\r\n //Add module files for compilation\r\n if(!config['include'].includes('src/**/*module.ts'))\r\n config['include'].push('src/**/*module.ts');\r\n\r\n // append the comment again and write the file\r\n host.overwrite(tsConfigPath, comment + \"\\n\" + JSON.stringify(config, null , 2));\r\n return host;\r\n }\r\n}\r\n\r\nfunction addMagicDependenciesToPackageJson(option:MagicOptionScheme): Rule {\r\n\treturn (host: Tree, context: SchematicContext) => {\r\n\t if(!option.skipPackageJson){\r\n for (let dep of dependencies){\r\n LogLn(`[>] Add dependencies ${dep.name}`);\r\n addPackageToPackageJson(host, 'dependencies', dep.name, dep.version);\r\n }\r\n /*\r\n // done in pre-install step\r\n for (let dep of devDependencies){\r\n LogLn(`[>] Add devDependencies ${dep.name}`);\r\n addPackageToPackageJson(host, 'devDependencies', dep.name, dep.version);\r\n }\r\n */\r\n }\r\n\r\n\t\tif(!option.skipInstall){\r\n LogLn(`[>] Install dependencies.`);\r\n context.addTask(new NodePackageInstallTask());\r\n }else{\r\n LogLn(`skipIstalls ${dependencies.length} dependencies`);\r\n LogLn(`skipIstalls ${devDependencies.length} devDependencies`);\r\n }\r\n\r\n\t\treturn host;\r\n\t};\r\n}\r\nfunction addMagicModuleToAppModule(options: MagicOptionScheme) : Rule {\r\n return (host: Tree , context : SchematicContext)=>{\r\n const workspace = env.workspace;\r\n const project = env.project;\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'BrowserAnimationsModule',\r\n '@angular/platform-browser/animations',\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'ReactiveFormsModule',\r\n '@angular/forms',\r\n project);\r\n\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicModule',\r\n \"@magic-xpa/angular\",\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicAngularMaterialModule',\r\n \"@magic-xpa/angular-material-core\",\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicGenLibModule',\r\n \"./magic/magic.gen.lib.module\",\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicRoutingModule',\r\n \"./app.routes\",\r\n project);\r\n\r\n\r\n }\r\n}\r\n\r\nfunction addLazyLoadProvider(): Rule {\r\n return (host: Tree) => {\r\n const appmodule = env.metadata.paths.rootMagicGenFolder + '/app.module.ts';\r\n\r\n const lazyLoaderService = 'LazyLoaderService';\r\n const lazyLoaderServicePath = './magic/lazy-loader.service';\r\n\r\n let text = host.read(appmodule);\r\n let sourceText = text.toString('utf-8');\r\n let source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);\r\n let providerChanges = addProviderToModule(source, appmodule, '{ provide: MagicLazyLoaderService, useClass: LazyLoaderService }', lazyLoaderServicePath)\r\n\r\n const providerRecorder = host.beginUpdate(appmodule);\r\n for (const change of providerChanges) {\r\n if (change instanceof InsertChange) {\r\n if (!change.toAdd.includes('import')) // skip import change\r\n providerRecorder.insertLeft(change.pos, change.toAdd);\r\n }\r\n }\r\n host.commitUpdate(providerRecorder);\r\n\r\n const lazyLoaderServiceImport = insertImport(source, appmodule, lazyLoaderService, lazyLoaderServicePath, false);\r\n const lazyLoaderServiceChangesRecorder = host.beginUpdate(appmodule);\r\n if (lazyLoaderServiceImport instanceof InsertChange)\r\n lazyLoaderServiceChangesRecorder.insertLeft(lazyLoaderServiceImport.pos, lazyLoaderServiceImport.toAdd);\r\n host.commitUpdate(lazyLoaderServiceChangesRecorder);\r\n\r\n // add import for MagicLazyLoaderService\r\n const magicLazyLoaderServiceImportChanges: InsertChange = <InsertChange>insertImport(source, appmodule, 'MagicLazyLoaderService', '@magic-xpa/angular', false);\r\n const magicImportChangesRecorder = host.beginUpdate(appmodule);\r\n magicImportChangesRecorder.insertLeft(magicLazyLoaderServiceImportChanges.pos, magicLazyLoaderServiceImportChanges.toAdd)\r\n host.commitUpdate(magicImportChangesRecorder);\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAoBA,sBAsBC;;AA1CD,2DAKoC;AACpC,4DAAwE;AAExE,gDAA2D;AAC3D,4CAAuE;AACvE,gDAAwE;AACxE,4FAAiF;AACjF,sCAA2D;AAC3D,8CAA4C;AAC5C,sEAA8D;AAC9D,2FAAiF;AAEjF,+DAAwG;AACxG,uDAAiC;AACjC,yDAA0D;AAC1D,SAAgB,KAAK,CAAC,OAAyB;IAC7C,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,4CAAiB,EAAkB,OAAO,CAAC;QAC3C,IAAA,sBAAc,EAAqB,OAAO,CAAC;QAE3C,wBAAwB;QACxB,yBAAyB,CAAU,OAAO,CAAC;QAE3C,sBAAsB;QACtB,+BAA+B,CAAI,OAAO,CAAC;QAE3C,qBAAqB,CAAG,OAAO,CAAC;QAEhC,mBAAmB,EAAE;QAErB,kCAAkC,EAAE;QACpC,iBAAiB;QACjB,8CAA8C;QAE9C,qBAAqB;QACrB,8CAA8C;KAC/C,CAAC,CAAC;AACL,CAAC;AAED,SAAS,2BAA2B,CAAC,OAAyB;IAC5D,OAAO,IAAA,wBAAQ,EAAC;QACd,QAAQ,EAAM,0CAA0C;QACxD,IAAI,EAAU,UAAU;QACxB,WAAW,EAAG,SAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,kBAAkB;QACnD,IAAI,EAAS,8CAAkB,CAAC,IAAI;QACpC,IAAI,EAAU;YACZ,QAAQ,EAAG,OAAO,CAAC,QAAQ;SAC5B;KACF,EAAC,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,CAAC;QACzC,wDAAwD;QACxD,SAAS,GAAG,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACxC,KAAK,GAAG,YAAY,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,6FAA6F;QAC7F,MAAM,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjF,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;QAClC,MAAM,gBAAgB,GAAG,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,gBAAgB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC9D,IAAI,YAAY,EAAE,CAAC;YACjB,KAAK,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,KAAK,YAAY,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,mFAAmF;IACnF,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC7C,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACtC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import {\r\n Rule,\r\n chain,\r\n Tree,\r\n SchematicContext\r\n} from \"@angular-devkit/schematics\";\r\nimport {NodePackageInstallTask} from \"@angular-devkit/schematics/tasks\";\r\n\r\nimport {addPackageToPackageJson} from './../utils/package';\r\nimport { dependencies, devDependencies, env} from \"../magic-utils/env\";\r\nimport { addImportTSModule, copyMagicFiles} from \"../magic-utils/utils\";\r\nimport { initMagicMetadata} from \"../magic-utils/rules/init-magic-metadata.rule\";\r\nimport { addModuleImportToRootModule } from \"../utils/ast\";\r\nimport { LogLn } from \"../magic-utils/Util\";\r\nimport { generate } from \"../magic-utils/rules/generate.rule\";\r\nimport { GeneratedFileTypes } from \"../../types/enums/generated-file-types.enum\";\r\nimport { MagicOptionScheme } from \"../magic-utils/rules/magic-option.scheme\";\r\nimport {addProviderToModule, getDecoratorMetadata, insertImport} from \"../utils/devkit-utils/ast-utils\";\r\nimport * as ts from 'typescript';\r\nimport {InsertChange} from \"../utils/devkit-utils/change\";\r\nexport function mgAdd(options:MagicOptionScheme): Rule {\r\n return chain([\r\n initMagicMetadata (options),\r\n copyMagicFiles (options),\r\n\r\n // handel app.modules.ts\r\n addMagicModuleToAppModule (options),\r\n\r\n // handel Angular.json\r\n updateAngularJsonWithMagicStyle (options),\r\n\r\n updateTsConfigAppJson (options),\r\n\r\n addLazyLoadProvider(),\r\n\r\n addZoneChangeDetectionProviderRule(),\r\n //handel app.html\r\n //updateAppComponentHtmlFiles (options),\r\n\r\n //handel package.Json\r\n //addMagicDependenciesToPackageJson (options),\r\n ]);\r\n}\r\n\r\nfunction updateAppComponentHtmlFiles(options:MagicOptionScheme): Rule {\r\n return generate({\r\n template : \"./templates/angular/src/app/app.html.ejs\",\r\n name : \"app.html\",\r\n destination : env.metadata.paths.rootMagicGenFolder,\r\n type :GeneratedFileTypes.HTML,\r\n data : {\r\n skipHelp : options.skipHelp\r\n }\r\n },options)\r\n}\r\nfunction updateAngularJsonWithMagicStyle(options:MagicOptionScheme): Rule {\r\n return (host: Tree, context: SchematicContext) => {\r\n const project = env.project;\r\n let isDirty = false;\r\n\r\n let fullPathmagicStylePath = env.metadata.paths.magicStylePath;\r\n // if (!project.architect.test.options.styles.includes(fullPathmagicStylePath)) {\r\n // context.logger.info(` [>]add file ${fullPathmagicStylePath} to test`);\r\n // project.architect.test.options.styles.push(fullPathmagicStylePath);\r\n // isDirty = true;\r\n // }\r\n\r\n if (!project.architect.build.options.styles.includes(fullPathmagicStylePath)) {\r\n context.logger.info(` [>]add file ${fullPathmagicStylePath} to build`);\r\n project.architect.build.options.styles.push(fullPathmagicStylePath);\r\n isDirty = true;\r\n }\r\n\r\n const buildOptions = project?.architect?.build?.options;\r\n const testOptions = project?.architect?.test?.options;\r\n\r\n if (buildOptions) {\r\n const changed = ensurePolyfills(buildOptions, ['zone.js']);\r\n if (changed) {\r\n context.logger.info(` [>]add polyfill zone.js to build`);\r\n isDirty = true;\r\n }\r\n }\r\n\r\n if (testOptions) {\r\n const changed = ensurePolyfills(testOptions, ['zone.js', 'zone.js/testing']);\r\n if (changed) {\r\n context.logger.info(` [>]add polyfills zone.js, zone.js/testing to test`);\r\n isDirty = true;\r\n }\r\n }\r\n\r\n if(isDirty){\r\n let fullPath = env.metadata.paths.angularJsonPath;\r\n host.overwrite(fullPath, JSON.stringify(env.workspace, null, 2));\r\n }\r\n\r\n return host;\r\n };\r\n}\r\n\r\nfunction ensurePolyfills(options: any, requiredPolyfills: string[]): boolean {\r\n let polyfills: any[] = [];\r\n\r\n if (Array.isArray(options.polyfills)) {\r\n polyfills = [...options.polyfills];\r\n } else if (typeof options.polyfills === 'string' && options.polyfills.trim()) {\r\n polyfills = [options.polyfills];\r\n }\r\n\r\n let changed = !Array.isArray(options.polyfills);\r\n for (const entry of requiredPolyfills) {\r\n if (!polyfills.includes(entry)) {\r\n polyfills.push(entry);\r\n changed = true;\r\n }\r\n }\r\n\r\n if (changed) {\r\n options.polyfills = polyfills;\r\n }\r\n\r\n return changed;\r\n}\r\n\r\n// Angular 10 , does not include .ts file for compilation\r\n// So to avoid compilation error , add *.module.ts in includes section\r\nfunction updateTsConfigAppJson (option: MagicOptionScheme): Rule{\r\n return (host: Tree, context: SchematicContext) => {\r\n\r\n const tsConfigPath = env.metadata.paths.tsConfigAppJsonPath;\r\n const tsConfig = host.read(tsConfigPath).toString();\r\n\r\n // extract the comment\r\n let firstIndex = tsConfig.indexOf('*/');\r\n let secondIndex = tsConfig.indexOf('*/', firstIndex + 2);\r\n let comment = tsConfig.substring(0, secondIndex + 2);\r\n\r\n // replace the comment as parsing json with comment throws exception\r\n var config = JSON.parse(tsConfig.replace(comment, ''));\r\n\r\n //Add module files for compilation\r\n if(!config['include'].includes('src/**/*module.ts'))\r\n config['include'].push('src/**/*module.ts');\r\n\r\n if (!config['compilerOptions'])\r\n config['compilerOptions'] = {};\r\n\r\n // Ensures forceConsistentCasingInFileNames is set to false inorder to avoid path casing differences while compilation\r\n config['compilerOptions']['forceConsistentCasingInFileNames'] = false;\r\n\r\n // append the comment again and write the file\r\n host.overwrite(tsConfigPath, comment + \"\\n\" + JSON.stringify(config, null , 2));\r\n return host;\r\n }\r\n}\r\n\r\nfunction addMagicDependenciesToPackageJson(option:MagicOptionScheme): Rule {\r\n\treturn (host: Tree, context: SchematicContext) => {\r\n\t if(!option.skipPackageJson){\r\n for (let dep of dependencies){\r\n LogLn(`[>] Add dependencies ${dep.name}`);\r\n addPackageToPackageJson(host, 'dependencies', dep.name, dep.version);\r\n }\r\n /*\r\n // done in pre-install step\r\n for (let dep of devDependencies){\r\n LogLn(`[>] Add devDependencies ${dep.name}`);\r\n addPackageToPackageJson(host, 'devDependencies', dep.name, dep.version);\r\n }\r\n */\r\n }\r\n\r\n\t\tif(!option.skipInstall){\r\n LogLn(`[>] Install dependencies.`);\r\n context.addTask(new NodePackageInstallTask());\r\n }else{\r\n LogLn(`skipIstalls ${dependencies.length} dependencies`);\r\n LogLn(`skipIstalls ${devDependencies.length} devDependencies`);\r\n }\r\n\r\n\t\treturn host;\r\n\t};\r\n}\r\nfunction addMagicModuleToAppModule(options: MagicOptionScheme) : Rule {\r\n return (host: Tree , context : SchematicContext)=>{\r\n const workspace = env.workspace;\r\n const project = env.project;\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'BrowserAnimationsModule',\r\n '@angular/platform-browser/animations',\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'ReactiveFormsModule',\r\n '@angular/forms',\r\n project);\r\n\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicModule',\r\n \"@magic-xpa/angular\",\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicAngularMaterialModule',\r\n \"@magic-xpa/angular-material-core\",\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicGenLibModule',\r\n \"./magic/magic.gen.lib.module\",\r\n project);\r\n\r\n addModuleImportToRootModule(\r\n host,\r\n 'MagicRoutingModule',\r\n \"./app.routes\",\r\n project);\r\n\r\n\r\n }\r\n}\r\n\r\nfunction addLazyLoadProvider(): Rule {\r\n return (host: Tree) => {\r\n const appmodule = env.metadata.paths.rootMagicGenFolder + '/app-module.ts';\r\n\r\n const lazyLoaderService = 'LazyLoaderService';\r\n const lazyLoaderServicePath = './magic/lazy-loader.service';\r\n\r\n let text = host.read(appmodule);\r\n let sourceText = text.toString('utf-8');\r\n let source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);\r\n let providerChanges = addProviderToModule(source, appmodule, '{ provide: MagicLazyLoaderService, useClass: LazyLoaderService }', lazyLoaderServicePath)\r\n\r\n const providerRecorder = host.beginUpdate(appmodule);\r\n for (const change of providerChanges) {\r\n if (change instanceof InsertChange) {\r\n if (!change.toAdd.includes('import')) // skip import change\r\n providerRecorder.insertLeft(change.pos, change.toAdd);\r\n }\r\n }\r\n host.commitUpdate(providerRecorder);\r\n\r\n sourceText = host.read(appmodule).toString('utf-8');\r\n source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);\r\n const lazyLoaderServiceImport = insertImport(source, appmodule, lazyLoaderService, lazyLoaderServicePath, false);\r\n const lazyLoaderServiceChangesRecorder = host.beginUpdate(appmodule);\r\n if (lazyLoaderServiceImport instanceof InsertChange)\r\n lazyLoaderServiceChangesRecorder.insertLeft(lazyLoaderServiceImport.pos, lazyLoaderServiceImport.toAdd);\r\n host.commitUpdate(lazyLoaderServiceChangesRecorder);\r\n\r\n // add import for MagicLazyLoaderService\r\n sourceText = host.read(appmodule).toString('utf-8');\r\n source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);\r\n const magicLazyLoaderServiceImportChanges: InsertChange = <InsertChange>insertImport(source, appmodule, 'MagicLazyLoaderService', '@magic-xpa/angular', false);\r\n const magicImportChangesRecorder = host.beginUpdate(appmodule);\r\n magicImportChangesRecorder.insertLeft(magicLazyLoaderServiceImportChanges.pos, magicLazyLoaderServiceImportChanges.toAdd)\r\n host.commitUpdate(magicImportChangesRecorder);\r\n }\r\n}\r\n\r\nfunction addZoneChangeDetectionProviderRule(): Rule {\r\n return (host: Tree) => {\r\n // Resolve the generated root module path (src/app/app-module.ts in this project layout).\r\n const appmodule = env.metadata.paths.rootMagicGenFolder + '/app-module.ts';\r\n\r\n // Append provideZoneChangeDetection() to NgModule.providers if it does not already exist.\r\n addZoneChangeDetectionProvider(host, appmodule);\r\n\r\n // Re-parse from disk after provider update so import insertion uses fresh AST positions.\r\n const sourceText = host.read(appmodule).toString('utf-8');\r\n const source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);\r\n\r\n // Ensure the symbol import exists; insertImport is idempotent and avoids duplicates.\r\n const zoneChangeDetectionImport = insertImport(source, appmodule, 'provideZoneChangeDetection', '@angular/core', false);\r\n const zoneChangeDetectionImportChangesRecorder = host.beginUpdate(appmodule);\r\n if (zoneChangeDetectionImport instanceof InsertChange)\r\n zoneChangeDetectionImportChangesRecorder.insertLeft(zoneChangeDetectionImport.pos, zoneChangeDetectionImport.toAdd);\r\n host.commitUpdate(zoneChangeDetectionImportChangesRecorder);\r\n };\r\n}\r\n\r\nfunction addZoneChangeDetectionProvider(host: Tree, appmodule: string): void {\r\n const zoneProvider = 'provideZoneChangeDetection()';\r\n const sourceText = host.read(appmodule).toString('utf-8');\r\n const source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);\r\n\r\n // Locate the first @NgModule({...}) metadata object in app-module.ts.\r\n const ngModules = getDecoratorMetadata(source, 'NgModule', '@angular/core');\r\n\r\n if (!ngModules.length) {\r\n return;\r\n }\r\n\r\n const ngModuleMetadata = ngModules[0] as ts.ObjectLiteralExpression;\r\n // Find the `providers` property assignment inside @NgModule metadata.\r\n const providersProperty = ngModuleMetadata.properties\r\n .filter(ts.isPropertyAssignment)\r\n .find((prop: ts.PropertyAssignment) => {\r\n if (ts.isIdentifier(prop.name)) {\r\n return prop.name.text === 'providers';\r\n }\r\n\r\n return ts.isStringLiteral(prop.name) && prop.name.text === 'providers';\r\n });\r\n\r\n if (!providersProperty || !ts.isArrayLiteralExpression(providersProperty.initializer)) {\r\n return;\r\n }\r\n\r\n const providersArray = providersProperty.initializer;\r\n // Keep this operation idempotent: do nothing if provider already exists.\r\n const hasZoneProvider = providersArray.elements.some((el: ts.Expression) => {\r\n return el.getText(source).replace(/\\s+/g, '') === zoneProvider;\r\n });\r\n\r\n if (hasZoneProvider) {\r\n return;\r\n }\r\n\r\n let insertPos: number;\r\n let toAdd: string;\r\n if (providersArray.elements.length === 0) {\r\n // Empty providers: inject the item directly between [].\r\n insertPos = providersArray.getEnd() - 1;\r\n toAdd = zoneProvider;\r\n } else {\r\n // Non-empty providers: append after last provider, preserving line formatting when possible.\r\n const lastProvider = providersArray.elements[providersArray.elements.length - 1];\r\n insertPos = lastProvider.getEnd();\r\n const lastProviderText = lastProvider.getFullText(source);\r\n const newLineMatch = lastProviderText.match(/^\\r?\\n(\\r?)\\s+/);\r\n if (newLineMatch) {\r\n toAdd = `,${newLineMatch[0]}${zoneProvider}`;\r\n } else {\r\n toAdd = `, ${zoneProvider}`;\r\n }\r\n }\r\n\r\n // Apply the computed insertion at the exact Abstract Syntax Tree-derived position.\r\n const recorder = host.beginUpdate(appmodule);\r\n recorder.insertLeft(insertPos, toAdd);\r\n host.commitUpdate(recorder);\r\n}\r\n\r\n"]}
|
|
@@ -15,7 +15,7 @@ import { LogLn } from "../magic-utils/Util";
|
|
|
15
15
|
import { generate } from "../magic-utils/rules/generate.rule";
|
|
16
16
|
import { GeneratedFileTypes } from "../../types/enums/generated-file-types.enum";
|
|
17
17
|
import { MagicOptionScheme } from "../magic-utils/rules/magic-option.scheme";
|
|
18
|
-
import {addProviderToModule, insertImport} from "../utils/devkit-utils/ast-utils";
|
|
18
|
+
import {addProviderToModule, getDecoratorMetadata, insertImport} from "../utils/devkit-utils/ast-utils";
|
|
19
19
|
import * as ts from 'typescript';
|
|
20
20
|
import {InsertChange} from "../utils/devkit-utils/change";
|
|
21
21
|
export function mgAdd(options:MagicOptionScheme): Rule {
|
|
@@ -32,7 +32,9 @@ export function mgAdd(options:MagicOptionScheme): Rule {
|
|
|
32
32
|
updateTsConfigAppJson (options),
|
|
33
33
|
|
|
34
34
|
addLazyLoadProvider(),
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
addZoneChangeDetectionProviderRule(),
|
|
37
|
+
//handel app.html
|
|
36
38
|
//updateAppComponentHtmlFiles (options),
|
|
37
39
|
|
|
38
40
|
//handel package.Json
|
|
@@ -42,8 +44,8 @@ export function mgAdd(options:MagicOptionScheme): Rule {
|
|
|
42
44
|
|
|
43
45
|
function updateAppComponentHtmlFiles(options:MagicOptionScheme): Rule {
|
|
44
46
|
return generate({
|
|
45
|
-
template : "./templates/angular/src/app/app.
|
|
46
|
-
name : "app.
|
|
47
|
+
template : "./templates/angular/src/app/app.html.ejs",
|
|
48
|
+
name : "app.html",
|
|
47
49
|
destination : env.metadata.paths.rootMagicGenFolder,
|
|
48
50
|
type :GeneratedFileTypes.HTML,
|
|
49
51
|
data : {
|
|
@@ -57,11 +59,11 @@ function updateAngularJsonWithMagicStyle(options:MagicOptionScheme): Rule {
|
|
|
57
59
|
let isDirty = false;
|
|
58
60
|
|
|
59
61
|
let fullPathmagicStylePath = env.metadata.paths.magicStylePath;
|
|
60
|
-
if (!project.architect.test.options.styles.includes(fullPathmagicStylePath)) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
62
|
+
// if (!project.architect.test.options.styles.includes(fullPathmagicStylePath)) {
|
|
63
|
+
// context.logger.info(` [>]add file ${fullPathmagicStylePath} to test`);
|
|
64
|
+
// project.architect.test.options.styles.push(fullPathmagicStylePath);
|
|
65
|
+
// isDirty = true;
|
|
66
|
+
// }
|
|
65
67
|
|
|
66
68
|
if (!project.architect.build.options.styles.includes(fullPathmagicStylePath)) {
|
|
67
69
|
context.logger.info(` [>]add file ${fullPathmagicStylePath} to build`);
|
|
@@ -69,6 +71,25 @@ function updateAngularJsonWithMagicStyle(options:MagicOptionScheme): Rule {
|
|
|
69
71
|
isDirty = true;
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
const buildOptions = project?.architect?.build?.options;
|
|
75
|
+
const testOptions = project?.architect?.test?.options;
|
|
76
|
+
|
|
77
|
+
if (buildOptions) {
|
|
78
|
+
const changed = ensurePolyfills(buildOptions, ['zone.js']);
|
|
79
|
+
if (changed) {
|
|
80
|
+
context.logger.info(` [>]add polyfill zone.js to build`);
|
|
81
|
+
isDirty = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (testOptions) {
|
|
86
|
+
const changed = ensurePolyfills(testOptions, ['zone.js', 'zone.js/testing']);
|
|
87
|
+
if (changed) {
|
|
88
|
+
context.logger.info(` [>]add polyfills zone.js, zone.js/testing to test`);
|
|
89
|
+
isDirty = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
72
93
|
if(isDirty){
|
|
73
94
|
let fullPath = env.metadata.paths.angularJsonPath;
|
|
74
95
|
host.overwrite(fullPath, JSON.stringify(env.workspace, null, 2));
|
|
@@ -78,6 +99,30 @@ function updateAngularJsonWithMagicStyle(options:MagicOptionScheme): Rule {
|
|
|
78
99
|
};
|
|
79
100
|
}
|
|
80
101
|
|
|
102
|
+
function ensurePolyfills(options: any, requiredPolyfills: string[]): boolean {
|
|
103
|
+
let polyfills: any[] = [];
|
|
104
|
+
|
|
105
|
+
if (Array.isArray(options.polyfills)) {
|
|
106
|
+
polyfills = [...options.polyfills];
|
|
107
|
+
} else if (typeof options.polyfills === 'string' && options.polyfills.trim()) {
|
|
108
|
+
polyfills = [options.polyfills];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let changed = !Array.isArray(options.polyfills);
|
|
112
|
+
for (const entry of requiredPolyfills) {
|
|
113
|
+
if (!polyfills.includes(entry)) {
|
|
114
|
+
polyfills.push(entry);
|
|
115
|
+
changed = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (changed) {
|
|
120
|
+
options.polyfills = polyfills;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return changed;
|
|
124
|
+
}
|
|
125
|
+
|
|
81
126
|
// Angular 10 , does not include .ts file for compilation
|
|
82
127
|
// So to avoid compilation error , add *.module.ts in includes section
|
|
83
128
|
function updateTsConfigAppJson (option: MagicOptionScheme): Rule{
|
|
@@ -98,6 +143,12 @@ function updateTsConfigAppJson (option: MagicOptionScheme): Rule{
|
|
|
98
143
|
if(!config['include'].includes('src/**/*module.ts'))
|
|
99
144
|
config['include'].push('src/**/*module.ts');
|
|
100
145
|
|
|
146
|
+
if (!config['compilerOptions'])
|
|
147
|
+
config['compilerOptions'] = {};
|
|
148
|
+
|
|
149
|
+
// Ensures forceConsistentCasingInFileNames is set to false inorder to avoid path casing differences while compilation
|
|
150
|
+
config['compilerOptions']['forceConsistentCasingInFileNames'] = false;
|
|
151
|
+
|
|
101
152
|
// append the comment again and write the file
|
|
102
153
|
host.overwrite(tsConfigPath, comment + "\n" + JSON.stringify(config, null , 2));
|
|
103
154
|
return host;
|
|
@@ -179,7 +230,7 @@ function addMagicModuleToAppModule(options: MagicOptionScheme) : Rule {
|
|
|
179
230
|
|
|
180
231
|
function addLazyLoadProvider(): Rule {
|
|
181
232
|
return (host: Tree) => {
|
|
182
|
-
const appmodule = env.metadata.paths.rootMagicGenFolder + '/app
|
|
233
|
+
const appmodule = env.metadata.paths.rootMagicGenFolder + '/app-module.ts';
|
|
183
234
|
|
|
184
235
|
const lazyLoaderService = 'LazyLoaderService';
|
|
185
236
|
const lazyLoaderServicePath = './magic/lazy-loader.service';
|
|
@@ -198,6 +249,8 @@ function addLazyLoadProvider(): Rule {
|
|
|
198
249
|
}
|
|
199
250
|
host.commitUpdate(providerRecorder);
|
|
200
251
|
|
|
252
|
+
sourceText = host.read(appmodule).toString('utf-8');
|
|
253
|
+
source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
201
254
|
const lazyLoaderServiceImport = insertImport(source, appmodule, lazyLoaderService, lazyLoaderServicePath, false);
|
|
202
255
|
const lazyLoaderServiceChangesRecorder = host.beginUpdate(appmodule);
|
|
203
256
|
if (lazyLoaderServiceImport instanceof InsertChange)
|
|
@@ -205,6 +258,8 @@ function addLazyLoadProvider(): Rule {
|
|
|
205
258
|
host.commitUpdate(lazyLoaderServiceChangesRecorder);
|
|
206
259
|
|
|
207
260
|
// add import for MagicLazyLoaderService
|
|
261
|
+
sourceText = host.read(appmodule).toString('utf-8');
|
|
262
|
+
source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
208
263
|
const magicLazyLoaderServiceImportChanges: InsertChange = <InsertChange>insertImport(source, appmodule, 'MagicLazyLoaderService', '@magic-xpa/angular', false);
|
|
209
264
|
const magicImportChangesRecorder = host.beginUpdate(appmodule);
|
|
210
265
|
magicImportChangesRecorder.insertLeft(magicLazyLoaderServiceImportChanges.pos, magicLazyLoaderServiceImportChanges.toAdd)
|
|
@@ -212,3 +267,87 @@ function addLazyLoadProvider(): Rule {
|
|
|
212
267
|
}
|
|
213
268
|
}
|
|
214
269
|
|
|
270
|
+
function addZoneChangeDetectionProviderRule(): Rule {
|
|
271
|
+
return (host: Tree) => {
|
|
272
|
+
// Resolve the generated root module path (src/app/app-module.ts in this project layout).
|
|
273
|
+
const appmodule = env.metadata.paths.rootMagicGenFolder + '/app-module.ts';
|
|
274
|
+
|
|
275
|
+
// Append provideZoneChangeDetection() to NgModule.providers if it does not already exist.
|
|
276
|
+
addZoneChangeDetectionProvider(host, appmodule);
|
|
277
|
+
|
|
278
|
+
// Re-parse from disk after provider update so import insertion uses fresh AST positions.
|
|
279
|
+
const sourceText = host.read(appmodule).toString('utf-8');
|
|
280
|
+
const source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
281
|
+
|
|
282
|
+
// Ensure the symbol import exists; insertImport is idempotent and avoids duplicates.
|
|
283
|
+
const zoneChangeDetectionImport = insertImport(source, appmodule, 'provideZoneChangeDetection', '@angular/core', false);
|
|
284
|
+
const zoneChangeDetectionImportChangesRecorder = host.beginUpdate(appmodule);
|
|
285
|
+
if (zoneChangeDetectionImport instanceof InsertChange)
|
|
286
|
+
zoneChangeDetectionImportChangesRecorder.insertLeft(zoneChangeDetectionImport.pos, zoneChangeDetectionImport.toAdd);
|
|
287
|
+
host.commitUpdate(zoneChangeDetectionImportChangesRecorder);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function addZoneChangeDetectionProvider(host: Tree, appmodule: string): void {
|
|
292
|
+
const zoneProvider = 'provideZoneChangeDetection()';
|
|
293
|
+
const sourceText = host.read(appmodule).toString('utf-8');
|
|
294
|
+
const source = ts.createSourceFile(appmodule, sourceText, ts.ScriptTarget.Latest, true);
|
|
295
|
+
|
|
296
|
+
// Locate the first @NgModule({...}) metadata object in app-module.ts.
|
|
297
|
+
const ngModules = getDecoratorMetadata(source, 'NgModule', '@angular/core');
|
|
298
|
+
|
|
299
|
+
if (!ngModules.length) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const ngModuleMetadata = ngModules[0] as ts.ObjectLiteralExpression;
|
|
304
|
+
// Find the `providers` property assignment inside @NgModule metadata.
|
|
305
|
+
const providersProperty = ngModuleMetadata.properties
|
|
306
|
+
.filter(ts.isPropertyAssignment)
|
|
307
|
+
.find((prop: ts.PropertyAssignment) => {
|
|
308
|
+
if (ts.isIdentifier(prop.name)) {
|
|
309
|
+
return prop.name.text === 'providers';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return ts.isStringLiteral(prop.name) && prop.name.text === 'providers';
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
if (!providersProperty || !ts.isArrayLiteralExpression(providersProperty.initializer)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const providersArray = providersProperty.initializer;
|
|
320
|
+
// Keep this operation idempotent: do nothing if provider already exists.
|
|
321
|
+
const hasZoneProvider = providersArray.elements.some((el: ts.Expression) => {
|
|
322
|
+
return el.getText(source).replace(/\s+/g, '') === zoneProvider;
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (hasZoneProvider) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
let insertPos: number;
|
|
330
|
+
let toAdd: string;
|
|
331
|
+
if (providersArray.elements.length === 0) {
|
|
332
|
+
// Empty providers: inject the item directly between [].
|
|
333
|
+
insertPos = providersArray.getEnd() - 1;
|
|
334
|
+
toAdd = zoneProvider;
|
|
335
|
+
} else {
|
|
336
|
+
// Non-empty providers: append after last provider, preserving line formatting when possible.
|
|
337
|
+
const lastProvider = providersArray.elements[providersArray.elements.length - 1];
|
|
338
|
+
insertPos = lastProvider.getEnd();
|
|
339
|
+
const lastProviderText = lastProvider.getFullText(source);
|
|
340
|
+
const newLineMatch = lastProviderText.match(/^\r?\n(\r?)\s+/);
|
|
341
|
+
if (newLineMatch) {
|
|
342
|
+
toAdd = `,${newLineMatch[0]}${zoneProvider}`;
|
|
343
|
+
} else {
|
|
344
|
+
toAdd = `, ${zoneProvider}`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Apply the computed insertion at the exact Abstract Syntax Tree-derived position.
|
|
349
|
+
const recorder = host.beginUpdate(appmodule);
|
|
350
|
+
recorder.insertLeft(insertPos, toAdd);
|
|
351
|
+
host.commitUpdate(recorder);
|
|
352
|
+
}
|
|
353
|
+
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {Routes, RouterModule} from '@angular/router';
|
|
2
|
+
import {customRoutes} from './custom.routes';
|
|
2
3
|
import { NgModule } from "@angular/core";
|
|
3
4
|
import { CommonModule } from "@angular/common";
|
|
4
5
|
|
|
5
6
|
export const routes: Routes = [
|
|
6
|
-
|
|
7
|
+
...customRoutes,
|
|
7
8
|
];
|
|
8
9
|
|
|
9
10
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Routes } from '@angular/router';
|
|
2
|
+
import { RouterContainerMagicComponent } from "@magic-xpa/angular";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom Routes
|
|
6
|
+
* =============
|
|
7
|
+
* Add your custom/manual routes in this file.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: This file is NOT affected by CLI route regeneration.
|
|
10
|
+
* The generated app.routes.ts automatically imports these routes.
|
|
11
|
+
*
|
|
12
|
+
* Custom routes are placed BEFORE generated routes in the final
|
|
13
|
+
* routes array, so they take PRIORITY when paths conflict.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* {
|
|
17
|
+
* path: 'callPublic/:name',
|
|
18
|
+
* component: RouterContainerMagicComponent,
|
|
19
|
+
* },
|
|
20
|
+
*/
|
|
21
|
+
export const customRoutes: Routes = [
|
|
22
|
+
|
|
23
|
+
];
|
|
@@ -48,16 +48,25 @@ function genRouteFile(options, routeItem) {
|
|
|
48
48
|
context.logger.info(`RouteTable is not defined !`);
|
|
49
49
|
else
|
|
50
50
|
context.logger.info(`generating ${data.routesArray.length} root routes`);
|
|
51
|
-
const
|
|
51
|
+
const routeFile = {
|
|
52
52
|
type: types_1.GeneratedFileTypes.TS,
|
|
53
53
|
template: template, // `./templates/angular/src/app.routes.ts`,
|
|
54
54
|
destination: destinationPath, // metadata.paths.rootMagicGenFolder,
|
|
55
55
|
name: 'app.routes.ts',
|
|
56
56
|
data: data
|
|
57
57
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const customRouteFile = {
|
|
59
|
+
type: types_1.GeneratedFileTypes.TS,
|
|
60
|
+
template: `./templates/angular/src/custom.routes.ts`,
|
|
61
|
+
destination: destinationPath,
|
|
62
|
+
name: 'custom.routes.ts',
|
|
63
|
+
data: {}
|
|
64
|
+
};
|
|
65
|
+
let rules = [
|
|
66
|
+
(0, generate_rule_1.generate)(routeFile, options),
|
|
67
|
+
!host.exists(`${destinationPath}/custom.routes.ts`) ? (0, generate_rule_1.generate)(customRouteFile, options) : (0, schematics_1.noop)()
|
|
68
|
+
];
|
|
69
|
+
return (0, schematics_1.chain)(rules)(host, context);
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AASA,4CAKC;AAKD,sCAeC;AAMD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AASA,4CAKC;AAKD,sCAeC;AAMD,oCA8CC;AAtFD,2DAAqG;AACrG,4FAAkF;AAClF,uCAAiE;AACjE,sEAA8D;AAC9D,4CAAyC;AAGzC,8CAA4C;AAE5C,SAAgB,gBAAgB,CAAC,OAA0B;IACzD,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,4CAAiB,EAAE,OAAO,CAAC;QAC3B,aAAa,CAAM,OAAO,CAAC;KAC5B,CAAC,CAAC;AACL,CAAC;AAED,mGAAmG;AACnG,8CAA8C;AAC9C,mGAAmG;AACnG,SAAgB,aAAa,CAAC,OAA0B;IACtD,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAE/C,MAAM,QAAQ,GAAI,SAAG,CAAC,QAAQ,CAAC;QAC/B,IAAI,UAAU,GAAkB,QAAQ,CAAC,WAAW,CAAC;QACrD,IAAI,KAAK,GAAU,EAAE,CAAC;QAEtB,OAAO,CAAC,MAAM,CAAC,IAAI,C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C,IAAI,EAAU,0BAAkB,CAAC,EAAE;YACnC,QAAQ,EAAM,QAAQ,EAAoC,2CAA2C;YACrG,WAAW,EAAG,eAAe,EAA6B,qCAAqC;YAC/F,IAAI,EAAU,eAAe;YAC7B,IAAI,EAAU,IAAI;SACnB,CAAC;QAEF,MAAM,eAAe,GAAmB;YACtC,IAAI,EAAU,0BAAkB,CAAC,EAAE;YACnC,QAAQ,EAAM,0CAA0C;YACxD,WAAW,EAAG,eAAe;YAC7B,IAAI,EAAU,kBAAkB;YAChC,IAAI,EAAU,EAAE;SACjB,CAAC;QAEF,IAAI,KAAK,GAAW;YAClB,IAAA,wBAAQ,EAAC,SAAS,EAAE,OAAO,CAAC;YAC5B,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,eAAe,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAA,wBAAQ,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE;SAClG,CAAC;QAEF,OAAO,IAAA,kBAAK,EAAC,KAAK,CAAC,CAAC,IAAI,EAAC,OAAO,CAAC,CAAC;IACpC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { chain, forEach, Rule, SchematicContext, Tree, url, noop } from \"@angular-devkit/schematics\";\r\nimport { initMagicMetadata } from \"../magic-utils/rules/init-magic-metadata.rule\";\r\nimport { GeneratedFileTypes, TemplateConfig } from \"../../types\";\r\nimport { generate } from \"../magic-utils/rules/generate.rule\";\r\nimport { env } from \"../magic-utils/env\";\r\nimport { MagicOptionScheme } from \"../magic-utils/rules/magic-option.scheme\";\r\nimport { RouteTable } from \"../../types/interfaces/app\";\r\nimport { LogLn } from \"../magic-utils/Util\";\r\n\r\nexport function mgGenerateRoutes(options: MagicOptionScheme): Rule {\r\n return chain([\r\n initMagicMetadata (options),\r\n genRoutesFile (options)\r\n ]);\r\n}\r\n\r\n//-------------------------------------------------------------------------------------------------\r\n// generate all the modules in env.modulesGen\r\n//-------------------------------------------------------------------------------------------------\r\nexport function genRoutesFile(options: MagicOptionScheme): Rule {\r\n return (tree: Tree, context: SchematicContext) => {\r\n\r\n const metadata = env.metadata;\r\n let routeTable: RouteTable[] = metadata.routesTable;\r\n let rules:Rule[] = [];\r\n\r\n context.logger.info(`routes length: ${routeTable.length}`);\r\n\r\n for (let routeItem of routeTable){\r\n rules.push(genRouteFile(options, routeItem));\r\n }\r\n\r\n return chain(rules)(tree,context);\r\n };\r\n}\r\n\r\n\r\n\r\n\r\n\r\nexport function genRouteFile(options: MagicOptionScheme, routeItem : RouteTable ) : Rule {\r\n return (host: Tree, context: SchematicContext) => {\r\n const metadata = env.metadata;\r\n let createRootRoute:boolean = routeItem.module_name =='' ? true: false;\r\n LogLn(`genRouteFile : [${routeItem.module_name}] createRootRoute = ${createRootRoute}`)\r\n\r\n const data: any = {\r\n routesArray: routeItem.routesArray,\r\n createRootRoute:createRootRoute\r\n };\r\n\r\n let template : string = `./templates/angular/src/app.routes.ts`;\r\n let destinationPath:string = metadata.paths.rootMagicGenFolder;\r\n if (routeItem.module_name != '')\r\n {\r\n destinationPath = metadata.paths.magicGenFolderPath + `/${routeItem.module_name}`;\r\n }\r\n\r\n if (data.routesArray == undefined)\r\n context.logger.info(`RouteTable is not defined !`);\r\n else\r\n context.logger.info(`generating ${data.routesArray.length} root routes`);\r\n\r\n const routeFile: TemplateConfig = {\r\n type : GeneratedFileTypes.TS,\r\n template : template, // `./templates/angular/src/app.routes.ts`,\r\n destination : destinationPath, // metadata.paths.rootMagicGenFolder,\r\n name : 'app.routes.ts',\r\n data : data\r\n };\r\n\r\n const customRouteFile: TemplateConfig = {\r\n type : GeneratedFileTypes.TS,\r\n template : `./templates/angular/src/custom.routes.ts`,\r\n destination : destinationPath,\r\n name : 'custom.routes.ts',\r\n data : {}\r\n };\r\n\r\n let rules: Rule[] = [\r\n generate(routeFile, options),\r\n !host.exists(`${destinationPath}/custom.routes.ts`) ? generate(customRouteFile, options) : noop()\r\n ];\r\n\r\n return chain(rules)(host,context);\r\n }\r\n}\r\n\r\n\r\n\r\n\r\n\r\n"]}
|