@magic-xpa/cli 4.1100.0-dev4110.19 → 4.1100.0-dev4110.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +4 -4
  3. package/package.json +2 -2
  4. package/src/public_api.d.ts +3 -3
  5. package/src/public_api.js +6 -6
  6. package/src/schematics/magic-utils/Util.d.ts +6 -6
  7. package/src/schematics/magic-utils/Util.js +26 -26
  8. package/src/schematics/magic-utils/config.d.ts +12 -12
  9. package/src/schematics/magic-utils/config.js +56 -56
  10. package/src/schematics/magic-utils/env.d.ts +23 -23
  11. package/src/schematics/magic-utils/env.js +39 -39
  12. package/src/schematics/magic-utils/env.js.map +1 -1
  13. package/src/schematics/magic-utils/env.ts +5 -5
  14. package/src/schematics/magic-utils/manifest.d.ts +11 -11
  15. package/src/schematics/magic-utils/manifest.js +40 -40
  16. package/src/schematics/magic-utils/manifest.js.map +1 -1
  17. package/src/schematics/magic-utils/metadata.class.d.ts +51 -51
  18. package/src/schematics/magic-utils/metadata.class.js +124 -124
  19. package/src/schematics/magic-utils/metadata.class.js.map +1 -1
  20. package/src/schematics/magic-utils/process-json.d.ts +2 -2
  21. package/src/schematics/magic-utils/process-json.js +158 -158
  22. package/src/schematics/magic-utils/process-json.js.map +1 -1
  23. package/src/schematics/magic-utils/rules/build-control.rule.d.ts +5 -5
  24. package/src/schematics/magic-utils/rules/build-control.rule.js +74 -74
  25. package/src/schematics/magic-utils/rules/build-control.rule.js.map +1 -1
  26. package/src/schematics/magic-utils/rules/build-view.rule.d.ts +3 -3
  27. package/src/schematics/magic-utils/rules/build-view.rule.js +83 -80
  28. package/src/schematics/magic-utils/rules/build-view.rule.js.map +1 -1
  29. package/src/schematics/magic-utils/rules/build-view.rule.ts +4 -0
  30. package/src/schematics/magic-utils/rules/component-list.rule.d.ts +3 -3
  31. package/src/schematics/magic-utils/rules/component-list.rule.js +317 -317
  32. package/src/schematics/magic-utils/rules/component-list.rule.js.map +1 -1
  33. package/src/schematics/magic-utils/rules/generate.rule.d.ts +5 -5
  34. package/src/schematics/magic-utils/rules/generate.rule.js +54 -54
  35. package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
  36. package/src/schematics/magic-utils/rules/init-add-modules.rule.d.ts +12 -12
  37. package/src/schematics/magic-utils/rules/init-add-modules.rule.js +296 -296
  38. package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
  39. package/src/schematics/magic-utils/rules/init-gen-components.rule.d.ts +4 -4
  40. package/src/schematics/magic-utils/rules/init-gen-components.rule.js +66 -66
  41. package/src/schematics/magic-utils/rules/init-gen-components.rule.js.map +1 -1
  42. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.d.ts +3 -3
  43. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js +18 -18
  44. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
  45. package/src/schematics/magic-utils/rules/load-views-gen.rule.d.ts +3 -3
  46. package/src/schematics/magic-utils/rules/load-views-gen.rule.js +29 -29
  47. package/src/schematics/magic-utils/rules/magic-option.scheme.d.ts +22 -21
  48. package/src/schematics/magic-utils/rules/magic-option.scheme.js +2 -2
  49. package/src/schematics/magic-utils/rules/magic-option.scheme.js.map +1 -1
  50. package/src/schematics/magic-utils/rules/magic-option.scheme.ts +1 -0
  51. package/src/schematics/magic-utils/utils.d.ts +12 -12
  52. package/src/schematics/magic-utils/utils.js +117 -117
  53. package/src/schematics/magic-utils/utils.js.map +1 -1
  54. package/src/schematics/mg-Install-prerequisites/index.d.ts +3 -3
  55. package/src/schematics/mg-Install-prerequisites/index.js +25 -25
  56. package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
  57. package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +19 -19
  58. package/src/schematics/mg-add/files/src/magic-styles.css +1 -1
  59. package/src/schematics/mg-add/index.d.ts +3 -3
  60. package/src/schematics/mg-add/index.js +151 -151
  61. package/src/schematics/mg-add/index.js.map +1 -1
  62. package/src/schematics/mg-add/utils/add-declaration-to-root-module.d.ts +2 -2
  63. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js +11 -11
  64. package/src/schematics/mg-add-tasks/index.d.ts +3 -3
  65. package/src/schematics/mg-add-tasks/index.js +30 -30
  66. package/src/schematics/mg-delete-files/index.d.ts +3 -3
  67. package/src/schematics/mg-delete-files/index.js +13 -13
  68. package/src/schematics/mg-gen-module/index.d.ts +3 -3
  69. package/src/schematics/mg-gen-module/index.js +15 -15
  70. package/src/schematics/mg-generate/index.d.ts +3 -3
  71. package/src/schematics/mg-generate/index.js +13 -13
  72. package/src/schematics/mg-generate-component/index.d.ts +3 -3
  73. package/src/schematics/mg-generate-component/index.js +35 -35
  74. package/src/schematics/mg-generate-component/index.js.map +1 -1
  75. package/src/schematics/mg-generate-component/schema.json +6 -0
  76. package/src/schematics/mg-install/index.d.ts +3 -3
  77. package/src/schematics/mg-install/index.js +30 -30
  78. package/src/schematics/mg-install/index.js.map +1 -1
  79. package/src/schematics/mg-routes/index.d.ts +6 -6
  80. package/src/schematics/mg-routes/index.js +63 -63
  81. package/src/schematics/mg-routes/index.js.map +1 -1
  82. package/src/schematics/mg-single-control/index.d.ts +3 -3
  83. package/src/schematics/mg-single-control/index.js +29 -29
  84. package/src/schematics/utils/ast.d.ts +21 -21
  85. package/src/schematics/utils/ast.js +91 -91
  86. package/src/schematics/utils/ast.js.map +1 -1
  87. package/src/schematics/utils/ast.ts +1 -1
  88. package/src/schematics/utils/devkit-utils/ast-utils.d.ts +87 -87
  89. package/src/schematics/utils/devkit-utils/ast-utils.js +490 -490
  90. package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
  91. package/src/schematics/utils/devkit-utils/ast-utils_old.d.ts +68 -68
  92. package/src/schematics/utils/devkit-utils/ast-utils_old.js +420 -420
  93. package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
  94. package/src/schematics/utils/devkit-utils/change.d.ts +66 -66
  95. package/src/schematics/utils/devkit-utils/change.js +94 -94
  96. package/src/schematics/utils/devkit-utils/change.js.map +1 -1
  97. package/src/schematics/utils/devkit-utils/component.d.ts +2 -2
  98. package/src/schematics/utils/devkit-utils/component.js +97 -97
  99. package/src/schematics/utils/devkit-utils/component.js.map +1 -1
  100. package/src/schematics/utils/devkit-utils/config.d.ts +78 -78
  101. package/src/schematics/utils/devkit-utils/config.js +52 -52
  102. package/src/schematics/utils/devkit-utils/config.js.map +1 -1
  103. package/src/schematics/utils/devkit-utils/find-module.d.ts +28 -28
  104. package/src/schematics/utils/devkit-utils/find-module.js +93 -93
  105. package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
  106. package/src/schematics/utils/devkit-utils/ng-ast-utils.d.ts +5 -5
  107. package/src/schematics/utils/devkit-utils/ng-ast-utils.js +74 -74
  108. package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
  109. package/src/schematics/utils/devkit-utils/parse-name.d.ts +13 -13
  110. package/src/schematics/utils/devkit-utils/parse-name.js +20 -20
  111. package/src/schematics/utils/devkit-utils/route-utils.d.ts +20 -20
  112. package/src/schematics/utils/devkit-utils/route-utils.js +134 -134
  113. package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
  114. package/src/schematics/utils/devkit-utils/validation.d.ts +1 -1
  115. package/src/schematics/utils/devkit-utils/validation.js +18 -18
  116. package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
  117. package/src/schematics/utils/html.d.ts +18 -18
  118. package/src/schematics/utils/html.js +60 -60
  119. package/src/schematics/utils/html.js.map +1 -1
  120. package/src/schematics/utils/lib-versions.d.ts +3 -3
  121. package/src/schematics/utils/lib-versions.js +6 -6
  122. package/src/schematics/utils/package.d.ts +5 -5
  123. package/src/schematics/utils/package.js +21 -21
  124. package/src/schematics/utils/package.js.map +1 -1
  125. package/src/schematics/utils/testing.d.ts +5 -5
  126. package/src/schematics/utils/testing.js +27 -27
  127. package/src/schematics/utils/testing.js.map +1 -1
  128. package/src/schematics/utils/testing.ts +2 -2
  129. package/src/types/enums/Enums.d.ts +1646 -1646
  130. package/src/types/enums/Enums.js +1862 -1862
  131. package/src/types/enums/Enums.js.map +1 -1
  132. package/src/types/enums/generated-file-types.enum.d.ts +6 -6
  133. package/src/types/enums/generated-file-types.enum.js +10 -10
  134. package/src/types/enums/generated-file-types.enum.js.map +1 -1
  135. package/src/types/enums/horizontal-alignments.enum.d.ts +5 -5
  136. package/src/types/enums/horizontal-alignments.enum.js +9 -9
  137. package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
  138. package/src/types/enums/themes.enum.d.ts +6 -6
  139. package/src/types/enums/themes.enum.js +10 -10
  140. package/src/types/enums/themes.enum.js.map +1 -1
  141. package/src/types/index.d.ts +7 -7
  142. package/src/types/index.js +10 -10
  143. package/src/types/interfaces/app.d.ts +53 -53
  144. package/src/types/interfaces/app.js +9 -9
  145. package/src/types/interfaces/control.d.ts +82 -82
  146. package/src/types/interfaces/control.js +2 -2
  147. package/src/types/interfaces/env.interface.d.ts +19 -19
  148. package/src/types/interfaces/env.interface.js +10 -10
  149. package/src/types/interfaces/template.config.d.ts +8 -8
  150. package/src/types/interfaces/template.config.js +2 -2
  151. package/templates/themes/basicHTML/edit.ejs +2 -1
@@ -1,326 +1,326 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentlistGen = void 0;
4
- const ts = require("typescript");
5
- const EJS = require("ejs");
6
- const schematics_1 = require("@angular-devkit/schematics");
7
- const env_1 = require("../env");
8
- const types_1 = require("../../../types");
9
- const generate_rule_1 = require("./generate.rule");
10
- const ast_1 = require("../../utils/ast");
11
- const route_utils_1 = require("../../utils/devkit-utils/route-utils");
12
- const ast_utils_1 = require("../../utils/devkit-utils/ast-utils");
13
- const Util_1 = require("../Util");
14
- const util_1 = require("util");
15
- let existCmpListSet;
16
- let newCmpListSet = new Set();
17
- let toAddImports = true;
18
- let orgPreventLog = env_1.env.prevent_log;
19
- function componentlistGen(options, module_name, loadOnDemand) {
20
- return (host, context) => {
21
- (0, Util_1.LogLn)(`[>] Step 4: components-list.`);
22
- return (0, schematics_1.chain)([
23
- addNewCmpsToCmpListOrGenAll(options, module_name),
24
- addCmpsImportsToCmpList(options, module_name),
25
- createLazyModuleMap(options, module_name),
26
- addLazyLoadComponentList(options, module_name, loadOnDemand),
27
- addLazyModuleToMagicGen(options),
28
- addImportForLazyModule(options)
29
- ])(host, context);
30
- };
31
- }
32
- exports.componentlistGen = componentlistGen;
33
- // create the lazy load map if it does not exist
34
- function createLazyModuleMap(options, module_name) {
35
- return (host, context) => {
36
- const cmpListPath = env_1.env.metadata.paths.componentListPath("");
37
- env_1.env.prevent_log = false;
38
- const source = host.read(cmpListPath).toString("utf-8");
39
- const LazyModuleArrayStart = 'export const ' + env_1.GEN_LAZY_LOAD_MODULES_ARRAY + ' = {';
40
- const LazyMOduleArrayEnd = '};';
41
- // create lazy load component array if it does not exist
42
- if (source.indexOf(LazyModuleArrayStart) < 0) {
43
- (0, Util_1.LogLn)(`[>] Creating LazyLoadModulesMap `);
44
- // add the code of creating map in file
45
- host.overwrite(cmpListPath, source + "\r\n" + LazyModuleArrayStart + LazyMOduleArrayEnd);
46
- }
47
- };
48
- }
49
- // add the lazy load components
50
- function addLazyLoadComponentList(options, module_name, loadOnDemand) {
51
- return (host, context) => {
52
- if (loadOnDemand) {
53
- let lazyLoadedComponents = new Array();
54
- const cmpListPath = env_1.env.metadata.paths.componentListPath("");
55
- const source = host.read(cmpListPath);
56
- if (source) {
57
- let cmpListSource = (0, ast_1.getSourceFile)(host, cmpListPath);
58
- let cmpListTs = getLazyLoadCompoenentsInfo(cmpListSource, env_1.GEN_LAZY_LOAD_MODULES_ARRAY);
59
- let sourceStep1 = host.read(cmpListPath).toString("utf-8");
60
- env_1.env.app.views.forEach(view => {
61
- if ((0, util_1.isNullOrUndefined)(cmpListTs.components) || !(cmpListTs.components.includes(view.props.component_uniquename))) {
62
- lazyLoadedComponents.push(view); // if component does not exist add it to list
63
- (0, Util_1.LogLn)(`[>] Add ${view.props.component_uniquename} component to LazyLoadModulesMap`);
64
- }
65
- });
66
- // add components to map
67
- if (lazyLoadedComponents.length > 0) {
68
- let sourceStep2 = addComponentsToLazyLoad(sourceStep1, cmpListTs, lazyLoadedComponents, module_name);
69
- host.overwrite(cmpListPath, sourceStep2);
70
- }
71
- }
72
- env_1.env.prevent_log = orgPreventLog;
73
- }
74
- return host;
75
- };
76
- }
77
- function addImportForLazyModule(options) {
78
- return (tree, context) => {
79
- let genLibPath = env_1.env.metadata.paths.rootMagicGenFolder + '/magic/magic.gen.lib.module.ts';
80
- const recorder = tree.beginUpdate(genLibPath);
81
- let genLibSource = (0, ast_1.getSourceFile)(tree, genLibPath);
82
- const importChange = (0, route_utils_1.insertImport)(genLibSource, genLibPath, env_1.GEN_LAZY_LOAD_MODULES_ARRAY, './component-list.g');
83
- if (importChange.toAdd) {
84
- recorder.insertLeft(importChange.pos, importChange.toAdd);
85
- }
86
- tree.commitUpdate(recorder);
87
- };
88
- }
89
- // add the lazy load module to magic.gen.lib
90
- function addLazyModuleToMagicGen(options) {
91
- return (tree, context) => {
92
- let origModuleFileName = env_1.env.metadata.paths.rootMagicGenFolder + '/magic/magic.gen.lib.module.ts';
93
- if (!tree.exists(origModuleFileName)) {
94
- (0, Util_1.LogLn)(` [>Error] File cannot be overwrite, The file is not exist !!! : ${origModuleFileName}`);
95
- }
96
- const text = tree.read(origModuleFileName);
97
- if (text === null) {
98
- throw new schematics_1.SchematicsException(`File ${origModuleFileName} does not exist.`);
99
- }
100
- let sourceText = text.toString('utf-8');
101
- const lazyModuleStatement = '\r\n componentList.lazyLoadModulesMap = ' + env_1.GEN_LAZY_LOAD_MODULES_ARRAY + ';';
102
- if (sourceText !== "" && sourceText.indexOf(lazyModuleStatement) == -1) {
103
- let genLibSource = (0, ast_1.getSourceFile)(tree, origModuleFileName);
104
- let newLazyModuleText = sourceText.replace(lazyModuleStatement, '').trim();
105
- const constNode = (0, ast_utils_1.findNodes)(genLibSource, ts.SyntaxKind.Constructor)[0];
106
- let lastStatementEnd = constNode.body.statements.end;
107
- const prefix = sourceText.substring(0, lastStatementEnd);
108
- const suffix = sourceText.substring(lastStatementEnd);
109
- tree.overwrite(origModuleFileName, `${prefix} ${lazyModuleStatement} ${suffix}`);
110
- }
111
- return tree;
112
- };
113
- }
114
- /*
115
- * Add new component to component-list.g file (Array and Hash).
116
- * If the file not exist new file will create by componentListGenIfNotExist function.
117
- * */
118
- function addNewCmpsToCmpListOrGenAll(options, module_name) {
119
- return (host, context) => {
120
- const metadata = env_1.env.metadata;
121
- const cmpsToGen = env_1.env.app.views;
122
- const cmpListPath = env_1.env.metadata.paths.componentListPath(module_name);
123
- const source = host.read(cmpListPath);
124
- if (source) {
125
- let cmpToGenNum = 0;
126
- let sourceStep1 = source.toString("utf-8");
127
- let cmpListSource = (0, ast_1.getSourceFile)(host, cmpListPath);
128
- let cmpListTs = getComponentsArrayInfo(cmpListSource, env_1.GEN_COMPONENTS_ARRAY);
129
- existCmpListSet = new Set(cmpListTs.components);
130
- newCmpListSet = new Set();
131
- // merge between components in the file and new component to gen
132
- cmpsToGen.forEach(newCmpGen => {
133
- if (!existCmpListSet.has(newCmpGen.props.component_uniquename)) {
134
- newCmpListSet.add(newCmpGen.props.component_uniquename);
135
- }
136
- });
137
- const newCmpListArray = Array.from(newCmpListSet);
138
- if (newCmpListArray && newCmpListArray.length > 0) {
139
- let sourceStep2 = addComponentsToArray(sourceStep1, cmpListTs, newCmpListArray);
140
- let cmpListHashTs = getComponentsHashInfo(cmpListSource, env_1.GEN_COMPONENTS_HASH);
141
- let sourceStep3 = addComponentsToHash(sourceStep2, cmpListHashTs, newCmpListArray);
142
- (0, Util_1.LogLn)(` Total old components: ${existCmpListSet.size}, added components: ${newCmpListSet.size}. `);
143
- host.overwrite(cmpListPath, sourceStep3);
144
- }
145
- }
146
- else {
147
- // If component-list.g.ts doesn't exist.
148
- toAddImports = false; // We generate the entire file with imports.
149
- return componentListGenIfNotExist(options)(host, context);
150
- }
151
- return host;
152
- };
153
- }
154
- /*
155
- * Create new component-list.g file.
156
- * */
157
- function componentListGenIfNotExist(options) {
158
- return (host, context) => {
159
- console.log("creating component-list");
160
- const metadata = env_1.env.metadata;
161
- const cmpList = new Set();
162
- const data = {
163
- app: env_1.env.app,
164
- cmpList: env_1.env.app.views
165
- };
166
- const componentFile = {
167
- template: `./templates/angular/src/app/component-list.g.ts`,
168
- name: 'component-list.g.ts',
169
- destination: metadata.paths.magicGenFolderPath,
170
- type: types_1.GeneratedFileTypes.TS,
171
- data: data
172
- };
173
- return (0, schematics_1.chain)([
174
- (0, generate_rule_1.generate)(componentFile, options)
175
- ])(host, context);
176
- };
177
- }
178
- /*
179
- * Add new imports to component-list.g file.
180
- * */
181
- function addCmpsImportsToCmpList(options, module_name) {
182
- return (host, context) => {
183
- if (toAddImports) {
184
- const cmpsToGen = env_1.env.app.views;
185
- let cmpListSource = (0, ast_1.getSourceFile)(host, env_1.env.metadata.paths.componentListPath(module_name));
186
- const recorder = host.beginUpdate(env_1.env.metadata.paths.componentListPath(module_name));
187
- cmpsToGen.forEach(cmp => {
188
- let name = cmp.props.id;
189
- let uniqueName = cmp.props.component_uniquename;
190
- let cmpPath = cmp.props.component_path;
191
- if (newCmpListSet.has(uniqueName)) {
192
- const importsChange = (0, route_utils_1.insertImport2)(cmpListSource, env_1.env.metadata.paths.componentListPath(module_name), name, uniqueName, `./${cmpPath}${name}.component`);
193
- if (importsChange.toAdd) {
194
- recorder.insertLeft(importsChange.pos, importsChange.toAdd);
195
- }
196
- }
197
- });
198
- host.commitUpdate(recorder);
199
- }
200
- return host;
201
- };
202
- }
203
- function getComponentsHashInfo(source, variable) {
204
- const rootNode = source;
205
- const cmpListVars = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.VariableDeclaration);
206
- let endPos = -1;
207
- let isEmpty = true;
208
- let magicGenCmpsInfo = cmpListVars.filter((node) => node.name.escapedText === variable);
209
- if (magicGenCmpsInfo && magicGenCmpsInfo.length > 0) {
210
- const firstPunctuation = (0, ast_utils_1.findNodes)(magicGenCmpsInfo[0], ts.SyntaxKind.FirstPunctuation);
211
- if (!(firstPunctuation && firstPunctuation.length > 0)) {
212
- throw new Error('magicGenCmpsHash variable has no open bracket ( { )');
213
- }
214
- endPos = firstPunctuation[0].end;
215
- const propertyAssignment = (0, ast_utils_1.findNodes)(firstPunctuation[0].parent, ts.SyntaxKind.PropertyAssignment);
216
- if (propertyAssignment && propertyAssignment.length > 0) {
217
- isEmpty = false;
218
- }
219
- }
220
- return {
221
- components: null,
222
- endPos,
223
- isEmpty
224
- };
225
- }
226
- function getComponentsArrayInfo(source, variable) {
227
- const rootNode = source;
228
- const cmpListVars = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.VariableDeclaration);
229
- let endPos = -1;
230
- let cmpListArray;
231
- let isEmpty = true;
232
- let magicGenCmpsInfo = cmpListVars.filter((node) => node.name.escapedText === variable);
233
- if (magicGenCmpsInfo && magicGenCmpsInfo.length > 0) {
234
- const openBracketToken = (0, ast_utils_1.findNodes)(magicGenCmpsInfo[0], ts.SyntaxKind.OpenBracketToken);
235
- if (!(openBracketToken && openBracketToken.length > 0)) {
236
- throw new Error('magicGenComponents variable has no open bracket ([)');
237
- }
238
- endPos = openBracketToken[0].end;
239
- const identifiers = (0, ast_utils_1.findNodes)(openBracketToken[0].parent, ts.SyntaxKind.Identifier);
240
- // Array with items
241
- if (identifiers && identifiers.length > 0) {
242
- isEmpty = false;
243
- //endPos = identifiers[identifiers.length - 1].end;
244
- cmpListArray = identifiers.map((i) => i.escapedText);
245
- }
246
- // Array with no items
247
- // else{
248
- // endPos = openBracketToken[0].end;
249
- // }
250
- }
251
- return {
252
- components: cmpListArray,
253
- endPos,
254
- isEmpty
255
- };
256
- }
257
- function getLazyLoadCompoenentsInfo(source, variable) {
258
- const cmpListVars = (0, ast_utils_1.findNodes)(source, ts.SyntaxKind.VariableDeclaration);
259
- let endPos = -1;
260
- let cmpListArray;
261
- let isEmpty = true;
262
- let magicGenCmpsInfo = cmpListVars.filter((node) => node.name.escapedText === variable);
263
- if (magicGenCmpsInfo && magicGenCmpsInfo.length > 0) {
264
- const openBracketToken = (0, ast_utils_1.findNodes)(magicGenCmpsInfo[0], ts.SyntaxKind.FirstPunctuation);
265
- if (!(openBracketToken && openBracketToken.length > 0)) {
266
- throw new Error('FirstPunctuation variable has no open bracket ([)');
267
- }
268
- endPos = openBracketToken[0].end;
269
- const identifiers = (0, ast_utils_1.findNodes)(openBracketToken[0].parent, ts.SyntaxKind.PropertyAssignment);
270
- const identifiers1 = (0, ast_utils_1.findNodes)(openBracketToken[0].parent, ts.SyntaxKind.Identifier);
271
- // Array with items
272
- if (identifiers && identifiers.length > 0) {
273
- isEmpty = false;
274
- cmpListArray = identifiers.map((i) => i.name.escapedText).filter(id => id !== "moduleName" && id !== "modulePath");
275
- }
276
- }
277
- return {
278
- components: cmpListArray,
279
- endPos,
280
- isEmpty
281
- };
282
- }
283
- function addComponentsToArray(source, info, cmpsToAdd) {
284
- const prefix = source.substring(0, info.endPos);
285
- const suffix = source.substring(info.endPos);
286
- let toAdd = `${cmpsToAdd}`;
287
- toAdd = `${toAdd.replace(/,/g, ",\n\t")}`;
288
- return info.isEmpty ?
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.componentlistGen = void 0;
4
+ const ts = require("typescript");
5
+ const EJS = require("ejs");
6
+ const schematics_1 = require("@angular-devkit/schematics");
7
+ const env_1 = require("../env");
8
+ const types_1 = require("../../../types");
9
+ const generate_rule_1 = require("./generate.rule");
10
+ const ast_1 = require("../../utils/ast");
11
+ const route_utils_1 = require("../../utils/devkit-utils/route-utils");
12
+ const ast_utils_1 = require("../../utils/devkit-utils/ast-utils");
13
+ const Util_1 = require("../Util");
14
+ const util_1 = require("util");
15
+ let existCmpListSet;
16
+ let newCmpListSet = new Set();
17
+ let toAddImports = true;
18
+ let orgPreventLog = env_1.env.prevent_log;
19
+ function componentlistGen(options, module_name, loadOnDemand) {
20
+ return (host, context) => {
21
+ (0, Util_1.LogLn)(`[>] Step 4: components-list.`);
22
+ return (0, schematics_1.chain)([
23
+ addNewCmpsToCmpListOrGenAll(options, module_name),
24
+ addCmpsImportsToCmpList(options, module_name),
25
+ createLazyModuleMap(options, module_name),
26
+ addLazyLoadComponentList(options, module_name, loadOnDemand),
27
+ addLazyModuleToMagicGen(options),
28
+ addImportForLazyModule(options)
29
+ ])(host, context);
30
+ };
31
+ }
32
+ exports.componentlistGen = componentlistGen;
33
+ // create the lazy load map if it does not exist
34
+ function createLazyModuleMap(options, module_name) {
35
+ return (host, context) => {
36
+ const cmpListPath = env_1.env.metadata.paths.componentListPath("");
37
+ env_1.env.prevent_log = false;
38
+ const source = host.read(cmpListPath).toString("utf-8");
39
+ const LazyModuleArrayStart = 'export const ' + env_1.GEN_LAZY_LOAD_MODULES_ARRAY + ' = {';
40
+ const LazyMOduleArrayEnd = '};';
41
+ // create lazy load component array if it does not exist
42
+ if (source.indexOf(LazyModuleArrayStart) < 0) {
43
+ (0, Util_1.LogLn)(`[>] Creating LazyLoadModulesMap `);
44
+ // add the code of creating map in file
45
+ host.overwrite(cmpListPath, source + "\r\n" + LazyModuleArrayStart + LazyMOduleArrayEnd);
46
+ }
47
+ };
48
+ }
49
+ // add the lazy load components
50
+ function addLazyLoadComponentList(options, module_name, loadOnDemand) {
51
+ return (host, context) => {
52
+ if (loadOnDemand) {
53
+ let lazyLoadedComponents = new Array();
54
+ const cmpListPath = env_1.env.metadata.paths.componentListPath("");
55
+ const source = host.read(cmpListPath);
56
+ if (source) {
57
+ let cmpListSource = (0, ast_1.getSourceFile)(host, cmpListPath);
58
+ let cmpListTs = getLazyLoadCompoenentsInfo(cmpListSource, env_1.GEN_LAZY_LOAD_MODULES_ARRAY);
59
+ let sourceStep1 = host.read(cmpListPath).toString("utf-8");
60
+ env_1.env.app.views.forEach(view => {
61
+ if ((0, util_1.isNullOrUndefined)(cmpListTs.components) || !(cmpListTs.components.includes(view.props.component_uniquename))) {
62
+ lazyLoadedComponents.push(view); // if component does not exist add it to list
63
+ (0, Util_1.LogLn)(`[>] Add ${view.props.component_uniquename} component to LazyLoadModulesMap`);
64
+ }
65
+ });
66
+ // add components to map
67
+ if (lazyLoadedComponents.length > 0) {
68
+ let sourceStep2 = addComponentsToLazyLoad(sourceStep1, cmpListTs, lazyLoadedComponents, module_name);
69
+ host.overwrite(cmpListPath, sourceStep2);
70
+ }
71
+ }
72
+ env_1.env.prevent_log = orgPreventLog;
73
+ }
74
+ return host;
75
+ };
76
+ }
77
+ function addImportForLazyModule(options) {
78
+ return (tree, context) => {
79
+ let genLibPath = env_1.env.metadata.paths.rootMagicGenFolder + '/magic/magic.gen.lib.module.ts';
80
+ const recorder = tree.beginUpdate(genLibPath);
81
+ let genLibSource = (0, ast_1.getSourceFile)(tree, genLibPath);
82
+ const importChange = (0, route_utils_1.insertImport)(genLibSource, genLibPath, env_1.GEN_LAZY_LOAD_MODULES_ARRAY, './component-list.g');
83
+ if (importChange.toAdd) {
84
+ recorder.insertLeft(importChange.pos, importChange.toAdd);
85
+ }
86
+ tree.commitUpdate(recorder);
87
+ };
88
+ }
89
+ // add the lazy load module to magic.gen.lib
90
+ function addLazyModuleToMagicGen(options) {
91
+ return (tree, context) => {
92
+ let origModuleFileName = env_1.env.metadata.paths.rootMagicGenFolder + '/magic/magic.gen.lib.module.ts';
93
+ if (!tree.exists(origModuleFileName)) {
94
+ (0, Util_1.LogLn)(` [>Error] File cannot be overwrite, The file is not exist !!! : ${origModuleFileName}`);
95
+ }
96
+ const text = tree.read(origModuleFileName);
97
+ if (text === null) {
98
+ throw new schematics_1.SchematicsException(`File ${origModuleFileName} does not exist.`);
99
+ }
100
+ let sourceText = text.toString('utf-8');
101
+ const lazyModuleStatement = '\r\n componentList.lazyLoadModulesMap = ' + env_1.GEN_LAZY_LOAD_MODULES_ARRAY + ';';
102
+ if (sourceText !== "" && sourceText.indexOf(lazyModuleStatement) == -1) {
103
+ let genLibSource = (0, ast_1.getSourceFile)(tree, origModuleFileName);
104
+ let newLazyModuleText = sourceText.replace(lazyModuleStatement, '').trim();
105
+ const constNode = (0, ast_utils_1.findNodes)(genLibSource, ts.SyntaxKind.Constructor)[0];
106
+ let lastStatementEnd = constNode.body.statements.end;
107
+ const prefix = sourceText.substring(0, lastStatementEnd);
108
+ const suffix = sourceText.substring(lastStatementEnd);
109
+ tree.overwrite(origModuleFileName, `${prefix} ${lazyModuleStatement} ${suffix}`);
110
+ }
111
+ return tree;
112
+ };
113
+ }
114
+ /*
115
+ * Add new component to component-list.g file (Array and Hash).
116
+ * If the file not exist new file will create by componentListGenIfNotExist function.
117
+ * */
118
+ function addNewCmpsToCmpListOrGenAll(options, module_name) {
119
+ return (host, context) => {
120
+ const metadata = env_1.env.metadata;
121
+ const cmpsToGen = env_1.env.app.views;
122
+ const cmpListPath = env_1.env.metadata.paths.componentListPath(module_name);
123
+ const source = host.read(cmpListPath);
124
+ if (source) {
125
+ let cmpToGenNum = 0;
126
+ let sourceStep1 = source.toString("utf-8");
127
+ let cmpListSource = (0, ast_1.getSourceFile)(host, cmpListPath);
128
+ let cmpListTs = getComponentsArrayInfo(cmpListSource, env_1.GEN_COMPONENTS_ARRAY);
129
+ existCmpListSet = new Set(cmpListTs.components);
130
+ newCmpListSet = new Set();
131
+ // merge between components in the file and new component to gen
132
+ cmpsToGen.forEach(newCmpGen => {
133
+ if (!existCmpListSet.has(newCmpGen.props.component_uniquename)) {
134
+ newCmpListSet.add(newCmpGen.props.component_uniquename);
135
+ }
136
+ });
137
+ const newCmpListArray = Array.from(newCmpListSet);
138
+ if (newCmpListArray && newCmpListArray.length > 0) {
139
+ let sourceStep2 = addComponentsToArray(sourceStep1, cmpListTs, newCmpListArray);
140
+ let cmpListHashTs = getComponentsHashInfo(cmpListSource, env_1.GEN_COMPONENTS_HASH);
141
+ let sourceStep3 = addComponentsToHash(sourceStep2, cmpListHashTs, newCmpListArray);
142
+ (0, Util_1.LogLn)(` Total old components: ${existCmpListSet.size}, added components: ${newCmpListSet.size}. `);
143
+ host.overwrite(cmpListPath, sourceStep3);
144
+ }
145
+ }
146
+ else {
147
+ // If component-list.g.ts doesn't exist.
148
+ toAddImports = false; // We generate the entire file with imports.
149
+ return componentListGenIfNotExist(options)(host, context);
150
+ }
151
+ return host;
152
+ };
153
+ }
154
+ /*
155
+ * Create new component-list.g file.
156
+ * */
157
+ function componentListGenIfNotExist(options) {
158
+ return (host, context) => {
159
+ console.log("creating component-list");
160
+ const metadata = env_1.env.metadata;
161
+ const cmpList = new Set();
162
+ const data = {
163
+ app: env_1.env.app,
164
+ cmpList: env_1.env.app.views
165
+ };
166
+ const componentFile = {
167
+ template: `./templates/angular/src/app/component-list.g.ts`,
168
+ name: 'component-list.g.ts',
169
+ destination: metadata.paths.magicGenFolderPath,
170
+ type: types_1.GeneratedFileTypes.TS,
171
+ data: data
172
+ };
173
+ return (0, schematics_1.chain)([
174
+ (0, generate_rule_1.generate)(componentFile, options)
175
+ ])(host, context);
176
+ };
177
+ }
178
+ /*
179
+ * Add new imports to component-list.g file.
180
+ * */
181
+ function addCmpsImportsToCmpList(options, module_name) {
182
+ return (host, context) => {
183
+ if (toAddImports) {
184
+ const cmpsToGen = env_1.env.app.views;
185
+ let cmpListSource = (0, ast_1.getSourceFile)(host, env_1.env.metadata.paths.componentListPath(module_name));
186
+ const recorder = host.beginUpdate(env_1.env.metadata.paths.componentListPath(module_name));
187
+ cmpsToGen.forEach(cmp => {
188
+ let name = cmp.props.id;
189
+ let uniqueName = cmp.props.component_uniquename;
190
+ let cmpPath = cmp.props.component_path;
191
+ if (newCmpListSet.has(uniqueName)) {
192
+ const importsChange = (0, route_utils_1.insertImport2)(cmpListSource, env_1.env.metadata.paths.componentListPath(module_name), name, uniqueName, `./${cmpPath}${name}.component`);
193
+ if (importsChange.toAdd) {
194
+ recorder.insertLeft(importsChange.pos, importsChange.toAdd);
195
+ }
196
+ }
197
+ });
198
+ host.commitUpdate(recorder);
199
+ }
200
+ return host;
201
+ };
202
+ }
203
+ function getComponentsHashInfo(source, variable) {
204
+ const rootNode = source;
205
+ const cmpListVars = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.VariableDeclaration);
206
+ let endPos = -1;
207
+ let isEmpty = true;
208
+ let magicGenCmpsInfo = cmpListVars.filter((node) => node.name.escapedText === variable);
209
+ if (magicGenCmpsInfo && magicGenCmpsInfo.length > 0) {
210
+ const firstPunctuation = (0, ast_utils_1.findNodes)(magicGenCmpsInfo[0], ts.SyntaxKind.FirstPunctuation);
211
+ if (!(firstPunctuation && firstPunctuation.length > 0)) {
212
+ throw new Error('magicGenCmpsHash variable has no open bracket ( { )');
213
+ }
214
+ endPos = firstPunctuation[0].end;
215
+ const propertyAssignment = (0, ast_utils_1.findNodes)(firstPunctuation[0].parent, ts.SyntaxKind.PropertyAssignment);
216
+ if (propertyAssignment && propertyAssignment.length > 0) {
217
+ isEmpty = false;
218
+ }
219
+ }
220
+ return {
221
+ components: null,
222
+ endPos,
223
+ isEmpty
224
+ };
225
+ }
226
+ function getComponentsArrayInfo(source, variable) {
227
+ const rootNode = source;
228
+ const cmpListVars = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.VariableDeclaration);
229
+ let endPos = -1;
230
+ let cmpListArray;
231
+ let isEmpty = true;
232
+ let magicGenCmpsInfo = cmpListVars.filter((node) => node.name.escapedText === variable);
233
+ if (magicGenCmpsInfo && magicGenCmpsInfo.length > 0) {
234
+ const openBracketToken = (0, ast_utils_1.findNodes)(magicGenCmpsInfo[0], ts.SyntaxKind.OpenBracketToken);
235
+ if (!(openBracketToken && openBracketToken.length > 0)) {
236
+ throw new Error('magicGenComponents variable has no open bracket ([)');
237
+ }
238
+ endPos = openBracketToken[0].end;
239
+ const identifiers = (0, ast_utils_1.findNodes)(openBracketToken[0].parent, ts.SyntaxKind.Identifier);
240
+ // Array with items
241
+ if (identifiers && identifiers.length > 0) {
242
+ isEmpty = false;
243
+ //endPos = identifiers[identifiers.length - 1].end;
244
+ cmpListArray = identifiers.map((i) => i.escapedText);
245
+ }
246
+ // Array with no items
247
+ // else{
248
+ // endPos = openBracketToken[0].end;
249
+ // }
250
+ }
251
+ return {
252
+ components: cmpListArray,
253
+ endPos,
254
+ isEmpty
255
+ };
256
+ }
257
+ function getLazyLoadCompoenentsInfo(source, variable) {
258
+ const cmpListVars = (0, ast_utils_1.findNodes)(source, ts.SyntaxKind.VariableDeclaration);
259
+ let endPos = -1;
260
+ let cmpListArray;
261
+ let isEmpty = true;
262
+ let magicGenCmpsInfo = cmpListVars.filter((node) => node.name.escapedText === variable);
263
+ if (magicGenCmpsInfo && magicGenCmpsInfo.length > 0) {
264
+ const openBracketToken = (0, ast_utils_1.findNodes)(magicGenCmpsInfo[0], ts.SyntaxKind.FirstPunctuation);
265
+ if (!(openBracketToken && openBracketToken.length > 0)) {
266
+ throw new Error('FirstPunctuation variable has no open bracket ([)');
267
+ }
268
+ endPos = openBracketToken[0].end;
269
+ const identifiers = (0, ast_utils_1.findNodes)(openBracketToken[0].parent, ts.SyntaxKind.PropertyAssignment);
270
+ const identifiers1 = (0, ast_utils_1.findNodes)(openBracketToken[0].parent, ts.SyntaxKind.Identifier);
271
+ // Array with items
272
+ if (identifiers && identifiers.length > 0) {
273
+ isEmpty = false;
274
+ cmpListArray = identifiers.map((i) => i.name.escapedText).filter(id => id !== "moduleName" && id !== "modulePath");
275
+ }
276
+ }
277
+ return {
278
+ components: cmpListArray,
279
+ endPos,
280
+ isEmpty
281
+ };
282
+ }
283
+ function addComponentsToArray(source, info, cmpsToAdd) {
284
+ const prefix = source.substring(0, info.endPos);
285
+ const suffix = source.substring(info.endPos);
286
+ let toAdd = `${cmpsToAdd}`;
287
+ toAdd = `${toAdd.replace(/,/g, ",\n\t")}`;
288
+ return info.isEmpty ?
289
289
  `${prefix}
290
- \t${toAdd} ${suffix}` :
290
+ \t${toAdd} ${suffix}` :
291
291
  `${prefix}
292
- \t${toAdd},${suffix}`;
293
- }
294
- function addComponentsToHash(source, info, cmpsToAdd) {
295
- const prefix = source.substring(0, info.endPos);
296
- const suffix = source.substring(info.endPos);
292
+ \t${toAdd},${suffix}`;
293
+ }
294
+ function addComponentsToHash(source, info, cmpsToAdd) {
295
+ const prefix = source.substring(0, info.endPos);
296
+ const suffix = source.substring(info.endPos);
297
297
  const cmpHashStr = EJS.render(`
298
298
  <% components.forEach(componentUniqueName => { %>
299
299
  <%= componentUniqueName %>:<%- componentUniqueName %>,
300
- <%})%>`, { components: cmpsToAdd });
301
- let toAdd = `${cmpHashStr.replace(/\n/g, '').replace(/,/g, ",\n")}`;
302
- // update source
303
- return `${prefix} ${toAdd} ${suffix}`;
304
- /*return info.isEmpty ?
305
- `${prefix} ${delLastComma(cmpHashStr)} ${suffix}` :
306
- `${prefix} ${delLastComma(cmpHashStr)}, ${suffix}` ;*/
307
- }
308
- // add the lazy loaded components to map
309
- function addComponentsToLazyLoad(source, info, cmpsToAdd, module_name) {
310
- const prefix = source.substring(0, info.endPos);
311
- const suffix = source.substring(info.endPos);
312
- // get the module path
313
- let currentModulePath = env_1.env.metadata.paths.magicGenLibModulePath(module_name);
300
+ <%})%>`, { components: cmpsToAdd });
301
+ let toAdd = `${cmpHashStr.replace(/\n/g, '').replace(/,/g, ",\n")}`;
302
+ // update source
303
+ return `${prefix} ${toAdd} ${suffix}`;
304
+ /*return info.isEmpty ?
305
+ `${prefix} ${delLastComma(cmpHashStr)} ${suffix}` :
306
+ `${prefix} ${delLastComma(cmpHashStr)}, ${suffix}` ;*/
307
+ }
308
+ // add the lazy loaded components to map
309
+ function addComponentsToLazyLoad(source, info, cmpsToAdd, module_name) {
310
+ const prefix = source.substring(0, info.endPos);
311
+ const suffix = source.substring(info.endPos);
312
+ // get the module path
313
+ let currentModulePath = env_1.env.metadata.paths.magicGenLibModulePath(module_name);
314
314
  const cmpHashStr = EJS.render(`
315
315
  <%{components.forEach(view =>{-%>
316
316
  <%=view.props.component_uniquename %> : { moduleName : 'Magic<%=moduleName%>Module'},
317
- <%})}-%>`, { components: cmpsToAdd, moduleName: module_name, modulePath: currentModulePath });
318
- let toAdd = `${cmpHashStr.replace(/\n/g, '').replace(/,/g, ",\n")}`;
319
- // update source
320
- return `${prefix} ${toAdd} ${suffix}`;
321
- }
322
- function delLastComma(source) {
323
- let index = source.lastIndexOf(',');
324
- return source.substring(0, index);
325
- }
317
+ <%})}-%>`, { components: cmpsToAdd, moduleName: module_name, modulePath: currentModulePath });
318
+ let toAdd = `${cmpHashStr.replace(/\n/g, '').replace(/,/g, ",\n")}`;
319
+ // update source
320
+ return `${prefix} ${toAdd} ${suffix}`;
321
+ }
322
+ function delLastComma(source) {
323
+ let index = source.lastIndexOf(',');
324
+ return source.substring(0, index);
325
+ }
326
326
  //# sourceMappingURL=component-list.rule.js.map