@magic-xpa/cli 4.1100.0-dev4110.2 → 4.1100.0-dev4110.202

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 (157) 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/lazy-loader.service.ts +2 -1
  58. package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +19 -19
  59. package/src/schematics/mg-add/files/src/magic-styles.css +2 -2
  60. package/src/schematics/mg-add/index.d.ts +3 -3
  61. package/src/schematics/mg-add/index.js +151 -151
  62. package/src/schematics/mg-add/index.js.map +1 -1
  63. package/src/schematics/mg-add/utils/add-declaration-to-root-module.d.ts +2 -2
  64. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js +11 -11
  65. package/src/schematics/mg-add-tasks/index.d.ts +3 -3
  66. package/src/schematics/mg-add-tasks/index.js +30 -30
  67. package/src/schematics/mg-delete-files/index.d.ts +3 -3
  68. package/src/schematics/mg-delete-files/index.js +13 -13
  69. package/src/schematics/mg-gen-module/index.d.ts +3 -3
  70. package/src/schematics/mg-gen-module/index.js +15 -15
  71. package/src/schematics/mg-generate/index.d.ts +3 -3
  72. package/src/schematics/mg-generate/index.js +13 -13
  73. package/src/schematics/mg-generate-component/index.d.ts +3 -3
  74. package/src/schematics/mg-generate-component/index.js +35 -35
  75. package/src/schematics/mg-generate-component/index.js.map +1 -1
  76. package/src/schematics/mg-generate-component/schema.json +6 -0
  77. package/src/schematics/mg-install/index.d.ts +3 -3
  78. package/src/schematics/mg-install/index.js +30 -30
  79. package/src/schematics/mg-install/index.js.map +1 -1
  80. package/src/schematics/mg-routes/index.d.ts +6 -6
  81. package/src/schematics/mg-routes/index.js +63 -63
  82. package/src/schematics/mg-routes/index.js.map +1 -1
  83. package/src/schematics/mg-single-control/index.d.ts +3 -3
  84. package/src/schematics/mg-single-control/index.js +29 -29
  85. package/src/schematics/utils/ast.d.ts +21 -21
  86. package/src/schematics/utils/ast.js +91 -91
  87. package/src/schematics/utils/ast.js.map +1 -1
  88. package/src/schematics/utils/ast.ts +1 -1
  89. package/src/schematics/utils/devkit-utils/ast-utils.d.ts +87 -87
  90. package/src/schematics/utils/devkit-utils/ast-utils.js +490 -490
  91. package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
  92. package/src/schematics/utils/devkit-utils/ast-utils_old.d.ts +68 -68
  93. package/src/schematics/utils/devkit-utils/ast-utils_old.js +420 -420
  94. package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
  95. package/src/schematics/utils/devkit-utils/change.d.ts +66 -66
  96. package/src/schematics/utils/devkit-utils/change.js +94 -94
  97. package/src/schematics/utils/devkit-utils/change.js.map +1 -1
  98. package/src/schematics/utils/devkit-utils/component.d.ts +2 -2
  99. package/src/schematics/utils/devkit-utils/component.js +97 -97
  100. package/src/schematics/utils/devkit-utils/component.js.map +1 -1
  101. package/src/schematics/utils/devkit-utils/config.d.ts +78 -78
  102. package/src/schematics/utils/devkit-utils/config.js +52 -52
  103. package/src/schematics/utils/devkit-utils/config.js.map +1 -1
  104. package/src/schematics/utils/devkit-utils/find-module.d.ts +28 -28
  105. package/src/schematics/utils/devkit-utils/find-module.js +93 -93
  106. package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
  107. package/src/schematics/utils/devkit-utils/ng-ast-utils.d.ts +5 -5
  108. package/src/schematics/utils/devkit-utils/ng-ast-utils.js +74 -74
  109. package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
  110. package/src/schematics/utils/devkit-utils/parse-name.d.ts +13 -13
  111. package/src/schematics/utils/devkit-utils/parse-name.js +20 -20
  112. package/src/schematics/utils/devkit-utils/route-utils.d.ts +20 -20
  113. package/src/schematics/utils/devkit-utils/route-utils.js +134 -134
  114. package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
  115. package/src/schematics/utils/devkit-utils/validation.d.ts +1 -1
  116. package/src/schematics/utils/devkit-utils/validation.js +18 -18
  117. package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
  118. package/src/schematics/utils/html.d.ts +18 -18
  119. package/src/schematics/utils/html.js +60 -60
  120. package/src/schematics/utils/html.js.map +1 -1
  121. package/src/schematics/utils/lib-versions.d.ts +3 -3
  122. package/src/schematics/utils/lib-versions.js +6 -6
  123. package/src/schematics/utils/package.d.ts +5 -5
  124. package/src/schematics/utils/package.js +21 -21
  125. package/src/schematics/utils/package.js.map +1 -1
  126. package/src/schematics/utils/testing.d.ts +5 -5
  127. package/src/schematics/utils/testing.js +27 -27
  128. package/src/schematics/utils/testing.js.map +1 -1
  129. package/src/schematics/utils/testing.ts +2 -2
  130. package/src/types/enums/Enums.d.ts +1646 -1646
  131. package/src/types/enums/Enums.js +1862 -1862
  132. package/src/types/enums/Enums.js.map +1 -1
  133. package/src/types/enums/generated-file-types.enum.d.ts +6 -6
  134. package/src/types/enums/generated-file-types.enum.js +10 -10
  135. package/src/types/enums/generated-file-types.enum.js.map +1 -1
  136. package/src/types/enums/horizontal-alignments.enum.d.ts +5 -5
  137. package/src/types/enums/horizontal-alignments.enum.js +9 -9
  138. package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
  139. package/src/types/enums/themes.enum.d.ts +6 -6
  140. package/src/types/enums/themes.enum.js +10 -10
  141. package/src/types/enums/themes.enum.js.map +1 -1
  142. package/src/types/index.d.ts +7 -7
  143. package/src/types/index.js +10 -10
  144. package/src/types/interfaces/app.d.ts +53 -53
  145. package/src/types/interfaces/app.js +9 -9
  146. package/src/types/interfaces/control.d.ts +82 -82
  147. package/src/types/interfaces/control.js +2 -2
  148. package/src/types/interfaces/env.interface.d.ts +19 -19
  149. package/src/types/interfaces/env.interface.js +10 -10
  150. package/src/types/interfaces/template.config.d.ts +8 -8
  151. package/src/types/interfaces/template.config.js +2 -2
  152. package/templates/themes/basicHTML/checkbox.ejs +1 -1
  153. package/templates/themes/basicHTML/edit.ejs +2 -1
  154. package/templates/themes/basicHTML/label.ejs +1 -1
  155. package/templates/themes/material/checkbox.ejs +1 -1
  156. package/templates/themes/table/HTMLTable/columnHeader.ejs +3 -1
  157. package/templates/themes/table/grid/column.ejs +3 -1
@@ -1,297 +1,297 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addRouteFileToModuleFile = exports.createRoute = exports.checkAndCreateRouteForModule = exports.generateWebModules = exports.generateWebModule = exports.checkAndCreateModule = exports.getDestinationModulePathByWebModuleName = exports.updateWebModuleFileWithNewClassName = exports.overwriteWebModuleFileName = exports.initGenModules = void 0;
4
- const schematics_1 = require("@angular-devkit/schematics");
5
- const env_1 = require("../env");
6
- const Util_1 = require("../Util");
7
- const ast_1 = require("../../utils/ast");
8
- const env_interface_1 = require("../../../types/interfaces/env.interface");
9
- //-------------------------------------------------------------------------------------------------
10
- // init generate module into env.modulesGen
11
- //-------------------------------------------------------------------------------------------------
12
- function initGenModules(options, generateViaCLI = false) {
13
- return (tree, context) => {
14
- let metadata = env_1.env.metadata;
15
- let programList = env_1.env.programList;
16
- env_1.env.modulesGen = [];
17
- let web_modules = metadata.config.web_modules;
18
- if (generateViaCLI) {
19
- let programListString = JSON.stringify(programList.programListContents);
20
- // Validate whether the component is valid
21
- if (programListString.includes(options.component)) {
22
- let moduleInfo = new env_interface_1.ModuleInfo(options.module, options.loadOnDemand);
23
- env_1.env.modulesGen.push(moduleInfo);
24
- }
25
- else {
26
- (0, Util_1.LogLn)(`Invalid component ${options.component} to generate.`);
27
- }
28
- }
29
- else {
30
- // Generate only one module from --module=xxxx
31
- if (options.module) {
32
- let moduleInfo = new env_interface_1.ModuleInfo(options.module, options.loadOnDemand);
33
- env_1.env.modulesGen.push(moduleInfo);
34
- }
35
- else {
36
- // Generate list of components from config.json, properties web_modules.module_name
37
- for (let modulePath of web_modules) {
38
- //LogLn(` Web Module name: [${modulePath.module_name}] IsLoadOnDemand? [${modulePath.load_on_demand}]`);
39
- let moduleInfo = new env_interface_1.ModuleInfo(modulePath.module_name, modulePath.load_on_demand);
40
- env_1.env.modulesGen.push(moduleInfo);
41
- }
42
- }
43
- }
44
- if (!generateViaCLI)
45
- (0, Util_1.LogLn)(` Number of modules to be check for generate: ${web_modules.length}`);
46
- return tree;
47
- };
48
- }
49
- exports.initGenModules = initGenModules;
50
- //-------------------------------------------------------------------------------------------------
51
- // overwrite the web module file name with the new content
52
- //-------------------------------------------------------------------------------------------------
53
- function overwriteWebModuleFileName(options, moduleNameFileName, content) {
54
- return (tree, _context) => {
55
- if (!tree.exists(moduleNameFileName)) {
56
- (0, Util_1.LogLn)(` [>Error] File cannot be overwrite, The file is not exist !!! : ${moduleNameFileName}`);
57
- }
58
- tree.overwrite(moduleNameFileName, content);
59
- return tree;
60
- };
61
- }
62
- exports.overwriteWebModuleFileName = overwriteWebModuleFileName;
63
- //-------------------------------------------------------------------------------------------------
64
- // update the the web module file name with the new class name
65
- //-------------------------------------------------------------------------------------------------
66
- function updateWebModuleFileWithNewClassName(options, webModuleName) {
67
- return (tree, context) => {
68
- let rules = [];
69
- const origModuleFileName = getWebModuleFullFileName(webModuleName);
70
- // create new class name for "web Module Name"
71
- let newClassModuleName = getWebModuleClass(webModuleName);
72
- //read the exist module file name
73
- const text = tree.read(origModuleFileName);
74
- if (text === null) {
75
- throw new schematics_1.SchematicsException(`File ${origModuleFileName} does not exist.`);
76
- }
77
- let sourceText = text.toString('utf-8');
78
- if (sourceText !== "") {
79
- let newsourceText = sourceText.replace(`MagicGenLibModule`, newClassModuleName);
80
- rules.push(overwriteWebModuleFileName(options, origModuleFileName, newsourceText));
81
- }
82
- return (0, schematics_1.chain)(rules)(tree, context);
83
- };
84
- }
85
- exports.updateWebModuleFileWithNewClassName = updateWebModuleFileWithNewClassName;
86
- //-------------------------------------------------------------------------------------------------
87
- // copy the two default files into the web module path
88
- //-------------------------------------------------------------------------------------------------
89
- function copyDefaultMagicFilesToWebModule(options, webModuleName) {
90
- return (tree, context) => {
91
- const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
92
- return (0, schematics_1.chain)([
93
- (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
94
- (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./../mg-add/files/src/app/magic/`), [
95
- (0, schematics_1.move)(webModulePath)
96
- ]), schematics_1.MergeStrategy.AllowCreationConflict)
97
- ]))
98
- ])(tree, context);
99
- };
100
- }
101
- //-------------------------------------------------------------------------------------------------
102
- // delete LazyLoadService for non root modules
103
- //-------------------------------------------------------------------------------------------------
104
- function deleteLazyLoadService(webModuleName) {
105
- return (tree) => {
106
- const lazyLoaderServicePath = getDestinationModulePathByWebModuleName(webModuleName) + '/lazy-loader.service.ts';
107
- if (webModuleName != '') {
108
- if (!tree.exists(lazyLoaderServicePath)) {
109
- (0, Util_1.LogLn)(` [>Error] File cannot be overwrite, The file is not exist !!! :lazyLoaderServicePath`);
110
- }
111
- tree.delete(lazyLoaderServicePath);
112
- return tree;
113
- }
114
- };
115
- }
116
- //-------------------------------------------------------------------------------------------------
117
- // get destination path according to the send webModuleName
118
- //-------------------------------------------------------------------------------------------------
119
- function getDestinationModulePathByWebModuleName(webModuleName) {
120
- const newDestModulePath = `${env_1.env.metadata.paths.rootMagicGenFolder}/${env_1.GEN_FOLDER}/${webModuleName}`;
121
- return newDestModulePath;
122
- }
123
- exports.getDestinationModulePathByWebModuleName = getDestinationModulePathByWebModuleName;
124
- //-------------------------------------------------------------------------------------------------
125
- // get web module full file name according to the send webModuleName
126
- //-------------------------------------------------------------------------------------------------
127
- function getWebModuleFullFileName(webModuleName) {
128
- // calc the path of new the module
129
- const newDestModulePath = getDestinationModulePathByWebModuleName(webModuleName);
130
- return `${newDestModulePath}/magic.gen.lib.module.ts`;
131
- }
132
- //-------------------------------------------------------------------------------------------------
133
- // get web module class according to the send webModuleName
134
- //-------------------------------------------------------------------------------------------------
135
- function getWebModuleClass(webModuleName) {
136
- return `Magic` + webModuleName + `Module`;
137
- }
138
- //-------------------------------------------------------------------------------------------------
139
- // add magic module to app module
140
- //-------------------------------------------------------------------------------------------------
141
- function addMagicModuleToAppModule(options, modulePath, moduleName, srcModuleName) {
142
- return (tree, context) => {
143
- const project = env_1.env.project;
144
- (0, Util_1.LogLn)(` [>] add New Web Module :[${moduleName}] `);
145
- (0, Util_1.LogLn)(` [>] from :[${srcModuleName}]`);
146
- (0, Util_1.LogLn)(` [>] To App Module :[${modulePath}]`);
147
- (0, ast_1.addModuleImportToModule)(tree, modulePath, // for now we will update env.metadata.paths.magicGenLibModule
148
- moduleName, // 'MagicXXXModule',
149
- srcModuleName);
150
- return tree;
151
- };
152
- }
153
- //-------------------------------------------------------------------------------------------------
154
- // create module
155
- //-------------------------------------------------------------------------------------------------
156
- function checkAndCreateModule(options, webModuleName, loadOnDemand) {
157
- return (tree, context) => {
158
- let rules = [];
159
- const webModuleFullFileName = getWebModuleFullFileName(webModuleName);
160
- // only if not exist create the new 2 files magic.gen.lib.module.ts & component-list.g.ts
161
- if (!tree.exists(webModuleFullFileName)) {
162
- rules.push(copyDefaultMagicFilesToWebModule(options, webModuleName));
163
- rules.push(updateWebModuleFileWithNewClassName(tree, webModuleName));
164
- rules.push(deleteLazyLoadService(webModuleName));
165
- // for NON load on demand we need to update magic root module
166
- if (!loadOnDemand) {
167
- const newDestModulePath = `./${webModuleName}/magic.gen.lib.module`;
168
- const webModuleClass = getWebModuleClass(webModuleName);
169
- rules.push(addMagicModuleToAppModule(options, env_1.env.metadata.paths.magicGenLibModule, webModuleClass, newDestModulePath));
170
- }
171
- return (0, schematics_1.chain)(rules)(tree, context);
172
- }
173
- ;
174
- };
175
- }
176
- exports.checkAndCreateModule = checkAndCreateModule;
177
- //-------------------------------------------------------------------------------------------------
178
- // check if module is exist, only if not exist create the web module
179
- //-------------------------------------------------------------------------------------------------
180
- function generateWebModule(options, webModuleName, loadOnDemand) {
181
- return (tree, context) => {
182
- let rules = [];
183
- (0, Util_1.LogLn)(` [>]Handling Web Module named: [${webModuleName}] isLoadOnDemand: [${loadOnDemand}]`);
184
- rules.push(checkAndCreateModule(options, webModuleName, loadOnDemand));
185
- rules.push(checkAndCreateRouteForModule(options, webModuleName, loadOnDemand));
186
- return (0, schematics_1.chain)(rules)(tree, context);
187
- };
188
- }
189
- exports.generateWebModule = generateWebModule;
190
- //-------------------------------------------------------------------------------------------------
191
- // generate all the modules in env.modulesGen
192
- //-------------------------------------------------------------------------------------------------
193
- function generateWebModules(options, generateViaCLI = false) {
194
- return (tree, context) => {
195
- let rules = [];
196
- for (let webModuleInfo of env_1.env.modulesGen) {
197
- if (webModuleInfo.moduleName !== undefined && webModuleInfo.moduleName !== "") {
198
- if (generateViaCLI) {
199
- if (webModuleInfo.moduleName === options.module) {
200
- rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
201
- }
202
- }
203
- else {
204
- rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
205
- }
206
- }
207
- }
208
- return (0, schematics_1.chain)(rules)(tree, context);
209
- };
210
- }
211
- exports.generateWebModules = generateWebModules;
212
- //-------------------------------------------------------------------------------------------------
213
- // check if module is exist, only if not exist create the web module
214
- //-------------------------------------------------------------------------------------------------
215
- function checkAndCreateRouteForModule(options, webModuleName, loadOnDemand) {
216
- return (tree, context) => {
217
- let rules = [];
218
- if (loadOnDemand) {
219
- const newDestRoutePathForModule = env_1.env.metadata.paths.getRoutePathForWebModule(webModuleName);
220
- // only if file not exist then copy the default route
221
- if (!tree.exists(newDestRoutePathForModule)) {
222
- rules.push(createRoute(options, webModuleName));
223
- }
224
- else {
225
- // if file exist then only update the magic.gen.lib.module.ts
226
- rules.push(addRouteFileToModuleFile(options, webModuleName));
227
- }
228
- }
229
- return (0, schematics_1.chain)(rules)(tree, context);
230
- };
231
- }
232
- exports.checkAndCreateRouteForModule = checkAndCreateRouteForModule;
233
- //-------------------------------------------------------------------------------------------------
234
- // create route for module
235
- //-------------------------------------------------------------------------------------------------
236
- function createRoute(options, webModuleName) {
237
- return (tree, context) => {
238
- let rules = [];
239
- rules.push(copyDefaultRouteMagicFilesToWebModule(options, webModuleName));
240
- // --------------------------------------------------------
241
- // // generate the route for module /////
242
- // let routeItem : RouteTable = new RouteTable();
243
- // routeItem.module_name = webModuleName;
244
- //
245
- // let route:Route = new Route();
246
- // route.ModuleName = webModuleName;
247
- // route.OutletName="";
248
- // route.RouteName="";
249
- // route.children=null;
250
- //
251
- // routeItem.routesArray = [route];
252
- // rules.push(genRouteFile(options, routeItem ));
253
- // --------------------------------------------------------
254
- // update the new MagicRoutingModule in file magic.gen.lib.module.ts of the module
255
- rules.push(addRouteFileToModuleFile(options, webModuleName));
256
- return (0, schematics_1.chain)(rules)(tree, context);
257
- };
258
- }
259
- exports.createRoute = createRoute;
260
- //-------------------------------------------------------------------------------------------------
261
- // create route for module
262
- //-------------------------------------------------------------------------------------------------
263
- function addRouteFileToModuleFile(options, webModuleName) {
264
- return (tree, context) => {
265
- let rules = [];
266
- const modulePath = getWebModuleFullFileName(webModuleName); // get the magic.gen.lib.module.ts according to the module name
267
- const moduleName = `MagicRoutingModule`; //for now it will be the same for all modules ... getWebModuleClass(webModuleName);
268
- const srcModuleName = `./app.routes`;
269
- rules.push(addMagicModuleToAppModule(options, modulePath, moduleName, srcModuleName));
270
- return (0, schematics_1.chain)(rules)(tree, context);
271
- };
272
- }
273
- exports.addRouteFileToModuleFile = addRouteFileToModuleFile;
274
- //-------------------------------------------------------------------------------------------------
275
- // copy the two default files into the web module path
276
- //-------------------------------------------------------------------------------------------------
277
- function copyDefaultRouteMagicFilesToWebModule(options, webModuleName) {
278
- return (tree, context) => {
279
- const routeFileForWebModulePath = env_1.env.metadata.paths.getRoutePathForWebModule(webModuleName);
280
- if (tree.exists(routeFileForWebModulePath)) {
281
- let rules = [];
282
- return (0, schematics_1.chain)(rules)(tree, context);
283
- }
284
- else {
285
- const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
286
- (0, Util_1.LogLn)(`[ >] copy default Route file to webModule [${webModuleName}]`);
287
- return (0, schematics_1.chain)([
288
- (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
289
- (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./../mg-add/webModule/`), [
290
- (0, schematics_1.move)(webModulePath)
291
- ]), schematics_1.MergeStrategy.AllowCreationConflict)
292
- ]))
293
- ])(tree, context);
294
- }
295
- };
296
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addRouteFileToModuleFile = exports.createRoute = exports.checkAndCreateRouteForModule = exports.generateWebModules = exports.generateWebModule = exports.checkAndCreateModule = exports.getDestinationModulePathByWebModuleName = exports.updateWebModuleFileWithNewClassName = exports.overwriteWebModuleFileName = exports.initGenModules = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ const env_1 = require("../env");
6
+ const Util_1 = require("../Util");
7
+ const ast_1 = require("../../utils/ast");
8
+ const env_interface_1 = require("../../../types/interfaces/env.interface");
9
+ //-------------------------------------------------------------------------------------------------
10
+ // init generate module into env.modulesGen
11
+ //-------------------------------------------------------------------------------------------------
12
+ function initGenModules(options, generateViaCLI = false) {
13
+ return (tree, context) => {
14
+ let metadata = env_1.env.metadata;
15
+ let programList = env_1.env.programList;
16
+ env_1.env.modulesGen = [];
17
+ let web_modules = metadata.config.web_modules;
18
+ if (generateViaCLI) {
19
+ let programListString = JSON.stringify(programList.programListContents);
20
+ // Validate whether the component is valid
21
+ if (programListString.includes(options.component)) {
22
+ let moduleInfo = new env_interface_1.ModuleInfo(options.module, options.loadOnDemand);
23
+ env_1.env.modulesGen.push(moduleInfo);
24
+ }
25
+ else {
26
+ (0, Util_1.LogLn)(`Invalid component ${options.component} to generate.`);
27
+ }
28
+ }
29
+ else {
30
+ // Generate only one module from --module=xxxx
31
+ if (options.module) {
32
+ let moduleInfo = new env_interface_1.ModuleInfo(options.module, options.loadOnDemand);
33
+ env_1.env.modulesGen.push(moduleInfo);
34
+ }
35
+ else {
36
+ // Generate list of components from config.json, properties web_modules.module_name
37
+ for (let modulePath of web_modules) {
38
+ //LogLn(` Web Module name: [${modulePath.module_name}] IsLoadOnDemand? [${modulePath.load_on_demand}]`);
39
+ let moduleInfo = new env_interface_1.ModuleInfo(modulePath.module_name, modulePath.load_on_demand);
40
+ env_1.env.modulesGen.push(moduleInfo);
41
+ }
42
+ }
43
+ }
44
+ if (!generateViaCLI)
45
+ (0, Util_1.LogLn)(` Number of modules to be check for generate: ${web_modules.length}`);
46
+ return tree;
47
+ };
48
+ }
49
+ exports.initGenModules = initGenModules;
50
+ //-------------------------------------------------------------------------------------------------
51
+ // overwrite the web module file name with the new content
52
+ //-------------------------------------------------------------------------------------------------
53
+ function overwriteWebModuleFileName(options, moduleNameFileName, content) {
54
+ return (tree, _context) => {
55
+ if (!tree.exists(moduleNameFileName)) {
56
+ (0, Util_1.LogLn)(` [>Error] File cannot be overwrite, The file is not exist !!! : ${moduleNameFileName}`);
57
+ }
58
+ tree.overwrite(moduleNameFileName, content);
59
+ return tree;
60
+ };
61
+ }
62
+ exports.overwriteWebModuleFileName = overwriteWebModuleFileName;
63
+ //-------------------------------------------------------------------------------------------------
64
+ // update the the web module file name with the new class name
65
+ //-------------------------------------------------------------------------------------------------
66
+ function updateWebModuleFileWithNewClassName(options, webModuleName) {
67
+ return (tree, context) => {
68
+ let rules = [];
69
+ const origModuleFileName = getWebModuleFullFileName(webModuleName);
70
+ // create new class name for "web Module Name"
71
+ let newClassModuleName = getWebModuleClass(webModuleName);
72
+ //read the exist module file name
73
+ const text = tree.read(origModuleFileName);
74
+ if (text === null) {
75
+ throw new schematics_1.SchematicsException(`File ${origModuleFileName} does not exist.`);
76
+ }
77
+ let sourceText = text.toString('utf-8');
78
+ if (sourceText !== "") {
79
+ let newsourceText = sourceText.replace(`MagicGenLibModule`, newClassModuleName);
80
+ rules.push(overwriteWebModuleFileName(options, origModuleFileName, newsourceText));
81
+ }
82
+ return (0, schematics_1.chain)(rules)(tree, context);
83
+ };
84
+ }
85
+ exports.updateWebModuleFileWithNewClassName = updateWebModuleFileWithNewClassName;
86
+ //-------------------------------------------------------------------------------------------------
87
+ // copy the two default files into the web module path
88
+ //-------------------------------------------------------------------------------------------------
89
+ function copyDefaultMagicFilesToWebModule(options, webModuleName) {
90
+ return (tree, context) => {
91
+ const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
92
+ return (0, schematics_1.chain)([
93
+ (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
94
+ (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./../mg-add/files/src/app/magic/`), [
95
+ (0, schematics_1.move)(webModulePath)
96
+ ]), schematics_1.MergeStrategy.AllowCreationConflict)
97
+ ]))
98
+ ])(tree, context);
99
+ };
100
+ }
101
+ //-------------------------------------------------------------------------------------------------
102
+ // delete LazyLoadService for non root modules
103
+ //-------------------------------------------------------------------------------------------------
104
+ function deleteLazyLoadService(webModuleName) {
105
+ return (tree) => {
106
+ const lazyLoaderServicePath = getDestinationModulePathByWebModuleName(webModuleName) + '/lazy-loader.service.ts';
107
+ if (webModuleName != '') {
108
+ if (!tree.exists(lazyLoaderServicePath)) {
109
+ (0, Util_1.LogLn)(` [>Error] File cannot be overwrite, The file is not exist !!! :lazyLoaderServicePath`);
110
+ }
111
+ tree.delete(lazyLoaderServicePath);
112
+ return tree;
113
+ }
114
+ };
115
+ }
116
+ //-------------------------------------------------------------------------------------------------
117
+ // get destination path according to the send webModuleName
118
+ //-------------------------------------------------------------------------------------------------
119
+ function getDestinationModulePathByWebModuleName(webModuleName) {
120
+ const newDestModulePath = `${env_1.env.metadata.paths.rootMagicGenFolder}/${env_1.GEN_FOLDER}/${webModuleName}`;
121
+ return newDestModulePath;
122
+ }
123
+ exports.getDestinationModulePathByWebModuleName = getDestinationModulePathByWebModuleName;
124
+ //-------------------------------------------------------------------------------------------------
125
+ // get web module full file name according to the send webModuleName
126
+ //-------------------------------------------------------------------------------------------------
127
+ function getWebModuleFullFileName(webModuleName) {
128
+ // calc the path of new the module
129
+ const newDestModulePath = getDestinationModulePathByWebModuleName(webModuleName);
130
+ return `${newDestModulePath}/magic.gen.lib.module.ts`;
131
+ }
132
+ //-------------------------------------------------------------------------------------------------
133
+ // get web module class according to the send webModuleName
134
+ //-------------------------------------------------------------------------------------------------
135
+ function getWebModuleClass(webModuleName) {
136
+ return `Magic` + webModuleName + `Module`;
137
+ }
138
+ //-------------------------------------------------------------------------------------------------
139
+ // add magic module to app module
140
+ //-------------------------------------------------------------------------------------------------
141
+ function addMagicModuleToAppModule(options, modulePath, moduleName, srcModuleName) {
142
+ return (tree, context) => {
143
+ const project = env_1.env.project;
144
+ (0, Util_1.LogLn)(` [>] add New Web Module :[${moduleName}] `);
145
+ (0, Util_1.LogLn)(` [>] from :[${srcModuleName}]`);
146
+ (0, Util_1.LogLn)(` [>] To App Module :[${modulePath}]`);
147
+ (0, ast_1.addModuleImportToModule)(tree, modulePath, // for now we will update env.metadata.paths.magicGenLibModule
148
+ moduleName, // 'MagicXXXModule',
149
+ srcModuleName);
150
+ return tree;
151
+ };
152
+ }
153
+ //-------------------------------------------------------------------------------------------------
154
+ // create module
155
+ //-------------------------------------------------------------------------------------------------
156
+ function checkAndCreateModule(options, webModuleName, loadOnDemand) {
157
+ return (tree, context) => {
158
+ let rules = [];
159
+ const webModuleFullFileName = getWebModuleFullFileName(webModuleName);
160
+ // only if not exist create the new 2 files magic.gen.lib.module.ts & component-list.g.ts
161
+ if (!tree.exists(webModuleFullFileName)) {
162
+ rules.push(copyDefaultMagicFilesToWebModule(options, webModuleName));
163
+ rules.push(updateWebModuleFileWithNewClassName(tree, webModuleName));
164
+ rules.push(deleteLazyLoadService(webModuleName));
165
+ // for NON load on demand we need to update magic root module
166
+ if (!loadOnDemand) {
167
+ const newDestModulePath = `./${webModuleName}/magic.gen.lib.module`;
168
+ const webModuleClass = getWebModuleClass(webModuleName);
169
+ rules.push(addMagicModuleToAppModule(options, env_1.env.metadata.paths.magicGenLibModule, webModuleClass, newDestModulePath));
170
+ }
171
+ return (0, schematics_1.chain)(rules)(tree, context);
172
+ }
173
+ ;
174
+ };
175
+ }
176
+ exports.checkAndCreateModule = checkAndCreateModule;
177
+ //-------------------------------------------------------------------------------------------------
178
+ // check if module is exist, only if not exist create the web module
179
+ //-------------------------------------------------------------------------------------------------
180
+ function generateWebModule(options, webModuleName, loadOnDemand) {
181
+ return (tree, context) => {
182
+ let rules = [];
183
+ (0, Util_1.LogLn)(` [>]Handling Web Module named: [${webModuleName}] isLoadOnDemand: [${loadOnDemand}]`);
184
+ rules.push(checkAndCreateModule(options, webModuleName, loadOnDemand));
185
+ rules.push(checkAndCreateRouteForModule(options, webModuleName, loadOnDemand));
186
+ return (0, schematics_1.chain)(rules)(tree, context);
187
+ };
188
+ }
189
+ exports.generateWebModule = generateWebModule;
190
+ //-------------------------------------------------------------------------------------------------
191
+ // generate all the modules in env.modulesGen
192
+ //-------------------------------------------------------------------------------------------------
193
+ function generateWebModules(options, generateViaCLI = false) {
194
+ return (tree, context) => {
195
+ let rules = [];
196
+ for (let webModuleInfo of env_1.env.modulesGen) {
197
+ if (webModuleInfo.moduleName !== undefined && webModuleInfo.moduleName !== "") {
198
+ if (generateViaCLI) {
199
+ if (webModuleInfo.moduleName === options.module) {
200
+ rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
201
+ }
202
+ }
203
+ else {
204
+ rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
205
+ }
206
+ }
207
+ }
208
+ return (0, schematics_1.chain)(rules)(tree, context);
209
+ };
210
+ }
211
+ exports.generateWebModules = generateWebModules;
212
+ //-------------------------------------------------------------------------------------------------
213
+ // check if module is exist, only if not exist create the web module
214
+ //-------------------------------------------------------------------------------------------------
215
+ function checkAndCreateRouteForModule(options, webModuleName, loadOnDemand) {
216
+ return (tree, context) => {
217
+ let rules = [];
218
+ if (loadOnDemand) {
219
+ const newDestRoutePathForModule = env_1.env.metadata.paths.getRoutePathForWebModule(webModuleName);
220
+ // only if file not exist then copy the default route
221
+ if (!tree.exists(newDestRoutePathForModule)) {
222
+ rules.push(createRoute(options, webModuleName));
223
+ }
224
+ else {
225
+ // if file exist then only update the magic.gen.lib.module.ts
226
+ rules.push(addRouteFileToModuleFile(options, webModuleName));
227
+ }
228
+ }
229
+ return (0, schematics_1.chain)(rules)(tree, context);
230
+ };
231
+ }
232
+ exports.checkAndCreateRouteForModule = checkAndCreateRouteForModule;
233
+ //-------------------------------------------------------------------------------------------------
234
+ // create route for module
235
+ //-------------------------------------------------------------------------------------------------
236
+ function createRoute(options, webModuleName) {
237
+ return (tree, context) => {
238
+ let rules = [];
239
+ rules.push(copyDefaultRouteMagicFilesToWebModule(options, webModuleName));
240
+ // --------------------------------------------------------
241
+ // // generate the route for module /////
242
+ // let routeItem : RouteTable = new RouteTable();
243
+ // routeItem.module_name = webModuleName;
244
+ //
245
+ // let route:Route = new Route();
246
+ // route.ModuleName = webModuleName;
247
+ // route.OutletName="";
248
+ // route.RouteName="";
249
+ // route.children=null;
250
+ //
251
+ // routeItem.routesArray = [route];
252
+ // rules.push(genRouteFile(options, routeItem ));
253
+ // --------------------------------------------------------
254
+ // update the new MagicRoutingModule in file magic.gen.lib.module.ts of the module
255
+ rules.push(addRouteFileToModuleFile(options, webModuleName));
256
+ return (0, schematics_1.chain)(rules)(tree, context);
257
+ };
258
+ }
259
+ exports.createRoute = createRoute;
260
+ //-------------------------------------------------------------------------------------------------
261
+ // create route for module
262
+ //-------------------------------------------------------------------------------------------------
263
+ function addRouteFileToModuleFile(options, webModuleName) {
264
+ return (tree, context) => {
265
+ let rules = [];
266
+ const modulePath = getWebModuleFullFileName(webModuleName); // get the magic.gen.lib.module.ts according to the module name
267
+ const moduleName = `MagicRoutingModule`; //for now it will be the same for all modules ... getWebModuleClass(webModuleName);
268
+ const srcModuleName = `./app.routes`;
269
+ rules.push(addMagicModuleToAppModule(options, modulePath, moduleName, srcModuleName));
270
+ return (0, schematics_1.chain)(rules)(tree, context);
271
+ };
272
+ }
273
+ exports.addRouteFileToModuleFile = addRouteFileToModuleFile;
274
+ //-------------------------------------------------------------------------------------------------
275
+ // copy the two default files into the web module path
276
+ //-------------------------------------------------------------------------------------------------
277
+ function copyDefaultRouteMagicFilesToWebModule(options, webModuleName) {
278
+ return (tree, context) => {
279
+ const routeFileForWebModulePath = env_1.env.metadata.paths.getRoutePathForWebModule(webModuleName);
280
+ if (tree.exists(routeFileForWebModulePath)) {
281
+ let rules = [];
282
+ return (0, schematics_1.chain)(rules)(tree, context);
283
+ }
284
+ else {
285
+ const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
286
+ (0, Util_1.LogLn)(`[ >] copy default Route file to webModule [${webModuleName}]`);
287
+ return (0, schematics_1.chain)([
288
+ (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
289
+ (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./../mg-add/webModule/`), [
290
+ (0, schematics_1.move)(webModulePath)
291
+ ]), schematics_1.MergeStrategy.AllowCreationConflict)
292
+ ]))
293
+ ])(tree, context);
294
+ }
295
+ };
296
+ }
297
297
  //# sourceMappingURL=init-add-modules.rule.js.map