@magic-xpa/cli 4.1201.0-dev4121.306 → 4.1201.0-dev4121.307

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 (183) hide show
  1. package/README.md +28 -28
  2. package/index.js.map +1 -1
  3. package/index.ts +1 -1
  4. package/package.json +1 -1
  5. package/src/collection.json +75 -75
  6. package/src/public_api.js.map +1 -1
  7. package/src/public_api.ts +5 -5
  8. package/src/schematics/magic-utils/config.js.map +1 -1
  9. package/src/schematics/magic-utils/config.ts +68 -68
  10. package/src/schematics/magic-utils/env.js.map +1 -1
  11. package/src/schematics/magic-utils/env.ts +50 -50
  12. package/src/schematics/magic-utils/manifest.js.map +1 -1
  13. package/src/schematics/magic-utils/manifest.ts +46 -46
  14. package/src/schematics/magic-utils/metadata.class.js.map +1 -1
  15. package/src/schematics/magic-utils/metadata.class.ts +159 -159
  16. package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
  17. package/src/schematics/magic-utils/rules/generate.rule.ts +61 -61
  18. package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
  19. package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +360 -360
  20. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
  21. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.ts +19 -19
  22. package/src/schematics/magic-utils/rules/magic-option.scheme.js.map +1 -1
  23. package/src/schematics/magic-utils/rules/magic-option.scheme.ts +24 -24
  24. package/src/schematics/magic-utils/utils.js.map +1 -1
  25. package/src/schematics/magic-utils/utils.ts +134 -134
  26. package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
  27. package/src/schematics/mg-Install-prerequisites/index.ts +30 -30
  28. package/src/schematics/mg-Install-prerequisites/schema.json +14 -14
  29. package/src/schematics/mg-add/files/src/app/app.component.html +17 -17
  30. package/src/schematics/mg-add/files/src/app/app.routes.ts +14 -14
  31. package/src/schematics/mg-add/files/src/app/magic/component-list.g.ts +9 -9
  32. package/src/schematics/mg-add/files/src/magic-styles.css +131 -131
  33. package/src/schematics/mg-add/schema.json +29 -29
  34. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js.map +1 -1
  35. package/src/schematics/mg-add/utils/add-declaration-to-root-module.ts +12 -12
  36. package/src/schematics/mg-add/webModule/app.routes.ts +14 -14
  37. package/src/schematics/mg-add-tasks/index.js.map +1 -1
  38. package/src/schematics/mg-add-tasks/index.ts +53 -53
  39. package/src/schematics/mg-add-tasks/schema.json +41 -41
  40. package/src/schematics/mg-delete-files/index.js.map +1 -1
  41. package/src/schematics/mg-delete-files/index.ts +12 -12
  42. package/src/schematics/mg-delete-files/schema.json +14 -14
  43. package/src/schematics/mg-gen-module/index.js.map +1 -1
  44. package/src/schematics/mg-gen-module/index.ts +14 -14
  45. package/src/schematics/mg-gen-module/schema.json +24 -24
  46. package/src/schematics/mg-generate/index.js.map +1 -1
  47. package/src/schematics/mg-generate/index.ts +12 -12
  48. package/src/schematics/mg-generate/schema.json +34 -34
  49. package/src/schematics/mg-install/index.js.map +1 -1
  50. package/src/schematics/mg-install/index.ts +37 -37
  51. package/src/schematics/mg-install/schema.json +24 -24
  52. package/src/schematics/mg-routes/schema.json +14 -14
  53. package/src/schematics/mg-single-control/schema.json +24 -24
  54. package/src/schematics/utils/ast.js.map +1 -1
  55. package/src/schematics/utils/ast.ts +103 -103
  56. package/src/schematics/utils/devkit-utils/README.md +1 -1
  57. package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
  58. package/src/schematics/utils/devkit-utils/ast-utils.ts +570 -570
  59. package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
  60. package/src/schematics/utils/devkit-utils/ast-utils_old.ts +478 -478
  61. package/src/schematics/utils/devkit-utils/change.js.map +1 -1
  62. package/src/schematics/utils/devkit-utils/change.ts +127 -127
  63. package/src/schematics/utils/devkit-utils/component.js.map +1 -1
  64. package/src/schematics/utils/devkit-utils/component.ts +136 -136
  65. package/src/schematics/utils/devkit-utils/config.js.map +1 -1
  66. package/src/schematics/utils/devkit-utils/config.ts +120 -120
  67. package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
  68. package/src/schematics/utils/devkit-utils/find-module.ts +108 -108
  69. package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
  70. package/src/schematics/utils/devkit-utils/ng-ast-utils.ts +84 -84
  71. package/src/schematics/utils/devkit-utils/parse-name.js.map +1 -1
  72. package/src/schematics/utils/devkit-utils/parse-name.ts +24 -24
  73. package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
  74. package/src/schematics/utils/devkit-utils/route-utils.ts +180 -180
  75. package/src/schematics/utils/devkit-utils/validation.js +1 -1
  76. package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
  77. package/src/schematics/utils/devkit-utils/validation.ts +16 -16
  78. package/src/schematics/utils/html.js.map +1 -1
  79. package/src/schematics/utils/html.ts +63 -63
  80. package/src/schematics/utils/lib-versions.js.map +1 -1
  81. package/src/schematics/utils/lib-versions.ts +3 -3
  82. package/src/schematics/utils/package.js.map +1 -1
  83. package/src/schematics/utils/package.ts +22 -22
  84. package/src/schematics/utils/testing.js.map +1 -1
  85. package/src/schematics/utils/testing.ts +25 -25
  86. package/src/types/enums/Enums.js.map +1 -1
  87. package/src/types/enums/Enums.ts +2063 -2063
  88. package/src/types/enums/generated-file-types.enum.js.map +1 -1
  89. package/src/types/enums/generated-file-types.enum.ts +6 -6
  90. package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
  91. package/src/types/enums/horizontal-alignments.enum.ts +6 -6
  92. package/src/types/enums/themes.enum.js.map +1 -1
  93. package/src/types/enums/themes.enum.ts +6 -6
  94. package/src/types/index.js.map +1 -1
  95. package/src/types/index.ts +8 -8
  96. package/src/types/interfaces/app.js.map +1 -1
  97. package/src/types/interfaces/app.ts +89 -89
  98. package/src/types/interfaces/control.js.map +1 -1
  99. package/src/types/interfaces/control.ts +106 -106
  100. package/src/types/interfaces/template.config.js.map +1 -1
  101. package/src/types/interfaces/template.config.ts +11 -11
  102. package/templates/angular/src/app/app.component.html.ejs +17 -17
  103. package/templates/angular/src/app/cmp-array.ejs +3 -3
  104. package/templates/angular/src/app/cmp-hash.ejs +3 -3
  105. package/templates/angular/src/app/component-list.g.ts +21 -21
  106. package/templates/angular/src/app.component.ts +16 -16
  107. package/templates/angular/src/app.module.ts +70 -70
  108. package/templates/angular/src/app.routes.ts +73 -73
  109. package/templates/angular/src/styles/app.css +5 -5
  110. package/templates/attributes/button_attributes.ejs +2 -2
  111. package/templates/attributes/common/base/class.ejs +6 -6
  112. package/templates/attributes/common/base/control_type.ejs +53 -53
  113. package/templates/attributes/common/base/enabled.ejs +9 -9
  114. package/templates/attributes/common/base/imageFileName.ejs +3 -3
  115. package/templates/attributes/common/base/no_control_class.ejs +3 -3
  116. package/templates/attributes/common/base/rtol.ejs +3 -3
  117. package/templates/attributes/common/base/tabindex.ejs +11 -11
  118. package/templates/attributes/common/base/testingId.ejs +8 -8
  119. package/templates/attributes/common/base/tooltip.ejs +7 -7
  120. package/templates/attributes/common/base/visible.ejs +6 -6
  121. package/templates/attributes/common/base/wallpaper.ejs +3 -3
  122. package/templates/attributes/common/base_attributes.ejs +10 -10
  123. package/templates/attributes/common/container_attributes.ejs +6 -6
  124. package/templates/attributes/common/control_attributes.ejs +3 -3
  125. package/templates/attributes/common/format.ejs +5 -5
  126. package/templates/attributes/common/input/hint.ejs +13 -13
  127. package/templates/attributes/common/input/multiline_edit.ejs +3 -3
  128. package/templates/attributes/common/input/must_input.ejs +8 -8
  129. package/templates/attributes/common/input/password_edit.ejs +7 -7
  130. package/templates/attributes/common/input/row_editing_input_attributes.ejs +6 -6
  131. package/templates/attributes/common/input/validation.ejs +5 -5
  132. package/templates/attributes/common/input_attributes.ejs +4 -4
  133. package/templates/attributes/common/no_control_base_attributes.ejs +4 -4
  134. package/templates/attributes/common/row_editing_button_attributes.ejs +10 -10
  135. package/templates/component/view.component.html +14 -14
  136. package/templates/component/view.component.ts +136 -136
  137. package/templates/themes/basicHTML/Code/theme.module.ts +10 -10
  138. package/templates/themes/basicHTML/combobox.ejs +37 -37
  139. package/templates/themes/basicHTML/edit.ejs +169 -169
  140. package/templates/themes/basicHTML/form.ejs +4 -4
  141. package/templates/themes/basicHTML/group.ejs +4 -4
  142. package/templates/themes/basicHTML/image.ejs +6 -6
  143. package/templates/themes/basicHTML/label.ejs +11 -11
  144. package/templates/themes/basicHTML/listbox.ejs +21 -21
  145. package/templates/themes/basicHTML/push-button.ejs +28 -28
  146. package/templates/themes/basicHTML/radio.ejs +20 -20
  147. package/templates/themes/basicHTML/subform.ejs +6 -6
  148. package/templates/themes/basicHTML/tab.ejs +31 -31
  149. package/templates/themes/basicHTML/tabpage.ejs +5 -5
  150. package/templates/themes/basicHiddenHTML/Code/theme.module.ts +10 -10
  151. package/templates/themes/basicHiddenHTML/combobox.ejs +5 -5
  152. package/templates/themes/basicHiddenHTML/form.ejs +3 -3
  153. package/templates/themes/basicHiddenHTML/group.ejs +2 -2
  154. package/templates/themes/basicHiddenHTML/image.ejs +4 -4
  155. package/templates/themes/basicHiddenHTML/label.ejs +1 -1
  156. package/templates/themes/basicHiddenHTML/listbox.ejs +8 -8
  157. package/templates/themes/basicHiddenHTML/push-button.ejs +26 -26
  158. package/templates/themes/basicHiddenHTML/radio.ejs +17 -17
  159. package/templates/themes/basicHiddenHTML/tab.ejs +13 -13
  160. package/templates/themes/basicHiddenHTML/table.ejs +18 -18
  161. package/templates/themes/basicHiddenHTML/tabpage.ejs +2 -2
  162. package/templates/themes/container.ejs +26 -26
  163. package/templates/themes/control.ejs +52 -52
  164. package/templates/themes/editTypeSelector.ejs +1 -1
  165. package/templates/themes/material/Code/theme.module.ts +68 -68
  166. package/templates/themes/material/base_attributes_date.ejs +8 -8
  167. package/templates/themes/material/combobox.ejs +58 -58
  168. package/templates/themes/material/edit.ejs +204 -204
  169. package/templates/themes/material/group.ejs +3 -3
  170. package/templates/themes/material/listbox.ejs +22 -22
  171. package/templates/themes/material/push-button.ejs +28 -28
  172. package/templates/themes/material/radio.ejs +22 -22
  173. package/templates/themes/material/subform.ejs +8 -8
  174. package/templates/themes/material/tab.ejs +19 -19
  175. package/templates/themes/router_outlet.ejs +5 -5
  176. package/templates/themes/table/HTMLTable/table.ejs +37 -37
  177. package/templates/themes/table/grid/additionalComponentCode.ejs +26 -26
  178. package/templates/themes/table/grid/additionalIncludes.ejs +1 -1
  179. package/templates/themes/table/grid/table.ejs +37 -37
  180. package/templates/themes/table/repeatable/column.ejs +11 -11
  181. package/templates/themes/table/repeatable/table.ejs +28 -28
  182. package/templates/themes/tableTypeSelector.ejs +21 -21
  183. package/tsconfig.json +36 -36
@@ -1,360 +1,360 @@
1
- import {
2
- apply, branchAndMerge,
3
- chain,
4
- MergeStrategy, mergeWith,
5
- move,
6
- Rule,
7
- SchematicContext, SchematicsException,
8
- Tree,
9
- url
10
- } from "@angular-devkit/schematics";
11
- import { MagicOptionScheme } from "./magic-option.scheme";
12
- import {env, GEN_FOLDER, GEN_LAZY_LOAD_MODULES_ARRAY} from "../env";
13
- import { LogLn } from "../Util";
14
- import { Route, RouteTable, webModuleItem } from "../../../types/interfaces/app";
15
- import {addModuleImportToModule, getSourceFile} from "../../utils/ast";
16
- import { ModuleInfo } from "../../../types/interfaces/env.interface";
17
-
18
- import {findNodes} from "../../utils/devkit-utils/ast-utils";
19
- import * as ts from "typescript";
20
- //-------------------------------------------------------------------------------------------------
21
- // init generate module into env.modulesGen
22
- //-------------------------------------------------------------------------------------------------
23
- export function initGenModules(options: MagicOptionScheme, generateViaCLI:boolean = false): Rule {
24
- return (tree: Tree, context: SchematicContext) => {
25
- let metadata = env.metadata;
26
- let programList = env.programList;
27
- env.modulesGen = [];
28
- let web_modules:webModuleItem [] = metadata.config.web_modules;
29
-
30
- if(generateViaCLI){
31
- let programListString = JSON.stringify(programList.programListContents);
32
-
33
- // Validate whether the component is valid
34
- if(programListString.includes(options.component)){
35
- let moduleInfo: ModuleInfo = new ModuleInfo(options.module, options.loadOnDemand);
36
- env.modulesGen.push(moduleInfo)
37
- }else{
38
- LogLn(`Invalid component ${options.component} to generate.`);
39
- }
40
- }else{
41
- // Generate only one module from --module=xxxx
42
- if (options.module) {
43
- let moduleInfo : ModuleInfo = new ModuleInfo(options.module, options.loadOnDemand);
44
- env.modulesGen.push(moduleInfo)
45
- } else {
46
-
47
- // Generate list of components from config.json, properties web_modules.module_name
48
- for (let modulePath of web_modules) {
49
- //LogLn(` Web Module name: [${modulePath.module_name}] IsLoadOnDemand? [${modulePath.load_on_demand}]`);
50
- let moduleInfo : ModuleInfo = new ModuleInfo(modulePath.module_name, modulePath.load_on_demand);
51
- env.modulesGen.push(moduleInfo);
52
- }
53
- }
54
- }
55
- if(!generateViaCLI)
56
- LogLn(` Number of modules to be check for generate: ${web_modules.length}`);
57
- return tree;
58
- };
59
- }
60
-
61
- //-------------------------------------------------------------------------------------------------
62
- // overwrite the web module file name with the new content
63
- //-------------------------------------------------------------------------------------------------
64
- export function overwriteWebModuleFileName(options: any, moduleNameFileName:string, content:string): Rule {
65
- return (tree: Tree, _context: SchematicContext) => {
66
-
67
- if(!tree.exists(moduleNameFileName)){
68
- LogLn(` [>Error] File cannot be overwrite, The file is not exist !!! : ${moduleNameFileName}`);
69
- }
70
-
71
- tree.overwrite(moduleNameFileName, content);
72
- return tree;
73
- };
74
- }
75
-
76
- //-------------------------------------------------------------------------------------------------
77
- // update the the web module file name with the new class name
78
- //-------------------------------------------------------------------------------------------------
79
- export function updateWebModuleFileWithNewClassName(options: any, webModuleName:string): Rule {
80
- return (tree: Tree, context: SchematicContext) => {
81
- let rules:Rule[] = [];
82
-
83
- const origModuleFileName = getWebModuleFullFileName(webModuleName)
84
-
85
- // create new class name for "web Module Name"
86
- let newClassModuleName = getWebModuleClass(webModuleName );
87
-
88
- //read the exist module file name
89
- const text = tree.read(origModuleFileName);
90
-
91
- if (text === null) {
92
- throw new SchematicsException(`File ${origModuleFileName} does not exist.`);
93
- }
94
- let sourceText = text.toString('utf-8');
95
-
96
- if (sourceText !== "") {
97
- let newsourceText: string = sourceText.replace(`MagicGenLibModule`, newClassModuleName);
98
- rules.push(overwriteWebModuleFileName(options, origModuleFileName, newsourceText));
99
-
100
- }
101
- return chain(rules)(tree, context);
102
- };
103
- }
104
-
105
- //-------------------------------------------------------------------------------------------------
106
- // copy the two default files into the web module path
107
- //-------------------------------------------------------------------------------------------------
108
- function copyDefaultMagicFilesToWebModule(options:MagicOptionScheme, webModuleName:string): Rule {
109
- return (tree: Tree,context:SchematicContext) => {
110
- const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
111
-
112
- return chain([
113
- branchAndMerge(chain([
114
- mergeWith(
115
- apply(url(`./../mg-add/files/src/app/magic/`), [
116
-
117
- move(webModulePath)
118
- ]), MergeStrategy.AllowCreationConflict)
119
- ]))
120
- ])(tree,context);
121
- }
122
- }
123
-
124
-
125
- //-------------------------------------------------------------------------------------------------
126
- // delete LazyLoadService for non root modules
127
- //-------------------------------------------------------------------------------------------------
128
- function deleteLazyLoadService( webModuleName:string): Rule {
129
- return (tree: Tree) => {
130
- const lazyLoaderServicePath = getDestinationModulePathByWebModuleName(webModuleName) + '/lazy-loader.service.ts';
131
-
132
- if(webModuleName != '') {
133
- if (!tree.exists(lazyLoaderServicePath)) {
134
- LogLn(` [>Error] File cannot be overwrite, The file is not exist !!! :lazyLoaderServicePath`);
135
- }
136
-
137
- tree.delete(lazyLoaderServicePath);
138
- return tree;
139
- }
140
- }
141
- }
142
-
143
-
144
- //-------------------------------------------------------------------------------------------------
145
- // get destination path according to the send webModuleName
146
- //-------------------------------------------------------------------------------------------------
147
- export function getDestinationModulePathByWebModuleName(webModuleName:string):string {
148
- const newDestModulePath = `${env.metadata.paths.rootMagicGenFolder}/${GEN_FOLDER}/${webModuleName}`;
149
- return newDestModulePath;
150
- }
151
-
152
- //-------------------------------------------------------------------------------------------------
153
- // get web module full file name according to the send webModuleName
154
- //-------------------------------------------------------------------------------------------------
155
- function getWebModuleFullFileName(webModuleName:string):string {
156
- // calc the path of new the module
157
- const newDestModulePath = getDestinationModulePathByWebModuleName(webModuleName);
158
- return `${newDestModulePath}/magic.gen.lib.module.ts`;
159
- }
160
-
161
- //-------------------------------------------------------------------------------------------------
162
- // get web module class according to the send webModuleName
163
- //-------------------------------------------------------------------------------------------------
164
- function getWebModuleClass(webModuleName:string):string {
165
- return `Magic` + webModuleName + `Module`;
166
- }
167
-
168
-
169
- //-------------------------------------------------------------------------------------------------
170
- // add magic module to app module
171
- //-------------------------------------------------------------------------------------------------
172
- function addMagicModuleToAppModule(options: MagicOptionScheme, modulePath:string, moduleName:string, srcModuleName:string) : Rule {
173
- return (tree: Tree , context : SchematicContext)=>{
174
- const project = env.project;
175
-
176
- LogLn(` [>] add New Web Module :[${moduleName}] `);
177
- LogLn(` [>] from :[${srcModuleName}]`);
178
- LogLn(` [>] To App Module :[${modulePath}]`);
179
- addModuleImportToModule(
180
- tree,
181
- modulePath, // for now we will update env.metadata.paths.magicGenLibModule
182
- moduleName, // 'MagicXXXModule',
183
- srcModuleName, // `./XXX/magic.gen.lib.module`
184
- );
185
- return tree;
186
- }
187
- }
188
-
189
- //-------------------------------------------------------------------------------------------------
190
- // create module
191
- //-------------------------------------------------------------------------------------------------
192
- export function checkAndCreateModule(options: MagicOptionScheme, webModuleName:string, loadOnDemand: boolean ): Rule {
193
- return (tree: Tree, context: SchematicContext) => {
194
-
195
- let rules: Rule[] = [];
196
- const webModuleFullFileName = getWebModuleFullFileName(webModuleName);
197
- // only if not exist create the new 2 files magic.gen.lib.module.ts & component-list.g.ts
198
- if (!tree.exists(webModuleFullFileName)) {
199
- rules.push(copyDefaultMagicFilesToWebModule(options, webModuleName));
200
- rules.push(updateWebModuleFileWithNewClassName(tree, webModuleName));
201
- rules.push(deleteLazyLoadService(webModuleName));
202
- // for NON load on demand we need to update magic root module
203
- if (!loadOnDemand) {
204
- const newDestModulePath = `./${webModuleName}/magic.gen.lib.module`;
205
- const webModuleClass = getWebModuleClass(webModuleName);
206
- rules.push(addMagicModuleToAppModule(options, env.metadata.paths.magicGenLibModule, webModuleClass, newDestModulePath));
207
- }
208
- return chain(rules)(tree, context);
209
- }
210
- ;
211
- }
212
- }
213
-
214
- //-------------------------------------------------------------------------------------------------
215
- // check if module is exist, only if not exist create the web module
216
- //-------------------------------------------------------------------------------------------------
217
- export function generateWebModule(options: MagicOptionScheme, webModuleName:string, loadOnDemand:boolean ): Rule {
218
- return (tree: Tree, context: SchematicContext) => {
219
-
220
- let rules:Rule[] = [];
221
-
222
- LogLn(` [>]Handling Web Module named: [${webModuleName}] isLoadOnDemand: [${loadOnDemand}]`);
223
- rules.push(checkAndCreateModule(options, webModuleName, loadOnDemand));
224
- rules.push(checkAndCreateRouteForModule(options, webModuleName, loadOnDemand));
225
-
226
- return chain(rules)(tree,context);
227
- };
228
- }
229
-
230
-
231
- //-------------------------------------------------------------------------------------------------
232
- // generate all the modules in env.modulesGen
233
- //-------------------------------------------------------------------------------------------------
234
- export function generateWebModules(options: MagicOptionScheme, generateViaCLI:boolean = false): Rule {
235
- return (tree: Tree, context: SchematicContext) => {
236
-
237
- let rules:Rule[] = [];
238
-
239
- for (let webModuleInfo of env.modulesGen){
240
- if (webModuleInfo.moduleName !== undefined && webModuleInfo.moduleName !== "") {
241
- if (generateViaCLI) {
242
- if (webModuleInfo.moduleName === options.module) {
243
- rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
244
- }
245
- }else{
246
- rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
247
- }
248
- }
249
- }
250
-
251
- return chain(rules)(tree,context);
252
- };
253
- }
254
-
255
-
256
-
257
- //-------------------------------------------------------------------------------------------------
258
- // check if module is exist, only if not exist create the web module
259
- //-------------------------------------------------------------------------------------------------
260
- export function checkAndCreateRouteForModule(options: MagicOptionScheme, webModuleName:string, loadOnDemand :boolean): Rule {
261
- return (tree: Tree, context: SchematicContext) => {
262
-
263
- let rules:Rule[] = [];
264
-
265
- if (loadOnDemand) {
266
- const newDestRoutePathForModule = env.metadata.paths.getRoutePathForWebModule(webModuleName);
267
-
268
- // only if file not exist then copy the default route
269
- if (!tree.exists(newDestRoutePathForModule)) {
270
- rules.push(createRoute(options, webModuleName));
271
- }
272
- else{
273
- // if file exist then only update the magic.gen.lib.module.ts
274
- rules.push(addRouteFileToModuleFile(options, webModuleName));
275
- }
276
- }
277
- return chain(rules)(tree,context);
278
- };
279
- }
280
-
281
-
282
-
283
- //-------------------------------------------------------------------------------------------------
284
- // create route for module
285
- //-------------------------------------------------------------------------------------------------
286
- export function createRoute(options: MagicOptionScheme, webModuleName:string): Rule {
287
- return (tree: Tree, context: SchematicContext) => {
288
-
289
- let rules:Rule[] = [];
290
-
291
- rules.push(copyDefaultRouteMagicFilesToWebModule(options, webModuleName));
292
- // --------------------------------------------------------
293
- // // generate the route for module /////
294
- // let routeItem : RouteTable = new RouteTable();
295
- // routeItem.module_name = webModuleName;
296
- //
297
- // let route:Route = new Route();
298
- // route.ModuleName = webModuleName;
299
- // route.OutletName="";
300
- // route.RouteName="";
301
- // route.children=null;
302
- //
303
- // routeItem.routesArray = [route];
304
- // rules.push(genRouteFile(options, routeItem ));
305
- // --------------------------------------------------------
306
- // update the new MagicRoutingModule in file magic.gen.lib.module.ts of the module
307
-
308
-
309
- rules.push(addRouteFileToModuleFile(options, webModuleName));
310
-
311
- return chain(rules)(tree,context);
312
- };
313
- }
314
-
315
- //-------------------------------------------------------------------------------------------------
316
- // create route for module
317
- //-------------------------------------------------------------------------------------------------
318
- export function addRouteFileToModuleFile(options: MagicOptionScheme, webModuleName:string): Rule {
319
- return (tree: Tree, context: SchematicContext) => {
320
-
321
- let rules:Rule[] = [];
322
-
323
- const modulePath = getWebModuleFullFileName(webModuleName); // get the magic.gen.lib.module.ts according to the module name
324
- const moduleName = `MagicRoutingModule`;//for now it will be the same for all modules ... getWebModuleClass(webModuleName);
325
- const srcModuleName = `./app.routes`;
326
-
327
- rules.push(addMagicModuleToAppModule(options, modulePath, moduleName, srcModuleName));
328
-
329
- return chain(rules)(tree,context);
330
- };
331
- }
332
- //-------------------------------------------------------------------------------------------------
333
- // copy the two default files into the web module path
334
- //-------------------------------------------------------------------------------------------------
335
- function copyDefaultRouteMagicFilesToWebModule(options:MagicOptionScheme, webModuleName:string): Rule {
336
- return (tree: Tree,context:SchematicContext) => {
337
- const routeFileForWebModulePath = env.metadata.paths.getRoutePathForWebModule(webModuleName);
338
-
339
-
340
- if(tree.exists(routeFileForWebModulePath))
341
- {
342
- let rules:Rule[] = [];
343
- return chain(rules)(tree,context);
344
- }
345
- else
346
- {
347
- const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
348
- LogLn(`[ >] copy default Route file to webModule [${webModuleName}]`)
349
- return chain([
350
- branchAndMerge(chain([
351
- mergeWith(
352
- apply(url(`./../mg-add/webModule/`), [
353
-
354
- move(webModulePath)
355
- ]), MergeStrategy.AllowCreationConflict)
356
- ]))
357
- ])(tree,context);
358
- }
359
- }
360
- }
1
+ import {
2
+ apply, branchAndMerge,
3
+ chain,
4
+ MergeStrategy, mergeWith,
5
+ move,
6
+ Rule,
7
+ SchematicContext, SchematicsException,
8
+ Tree,
9
+ url
10
+ } from "@angular-devkit/schematics";
11
+ import { MagicOptionScheme } from "./magic-option.scheme";
12
+ import {env, GEN_FOLDER, GEN_LAZY_LOAD_MODULES_ARRAY} from "../env";
13
+ import { LogLn } from "../Util";
14
+ import { Route, RouteTable, webModuleItem } from "../../../types/interfaces/app";
15
+ import {addModuleImportToModule, getSourceFile} from "../../utils/ast";
16
+ import { ModuleInfo } from "../../../types/interfaces/env.interface";
17
+
18
+ import {findNodes} from "../../utils/devkit-utils/ast-utils";
19
+ import * as ts from "typescript";
20
+ //-------------------------------------------------------------------------------------------------
21
+ // init generate module into env.modulesGen
22
+ //-------------------------------------------------------------------------------------------------
23
+ export function initGenModules(options: MagicOptionScheme, generateViaCLI:boolean = false): Rule {
24
+ return (tree: Tree, context: SchematicContext) => {
25
+ let metadata = env.metadata;
26
+ let programList = env.programList;
27
+ env.modulesGen = [];
28
+ let web_modules:webModuleItem [] = metadata.config.web_modules;
29
+
30
+ if(generateViaCLI){
31
+ let programListString = JSON.stringify(programList.programListContents);
32
+
33
+ // Validate whether the component is valid
34
+ if(programListString.includes(options.component)){
35
+ let moduleInfo: ModuleInfo = new ModuleInfo(options.module, options.loadOnDemand);
36
+ env.modulesGen.push(moduleInfo)
37
+ }else{
38
+ LogLn(`Invalid component ${options.component} to generate.`);
39
+ }
40
+ }else{
41
+ // Generate only one module from --module=xxxx
42
+ if (options.module) {
43
+ let moduleInfo : ModuleInfo = new ModuleInfo(options.module, options.loadOnDemand);
44
+ env.modulesGen.push(moduleInfo)
45
+ } else {
46
+
47
+ // Generate list of components from config.json, properties web_modules.module_name
48
+ for (let modulePath of web_modules) {
49
+ //LogLn(` Web Module name: [${modulePath.module_name}] IsLoadOnDemand? [${modulePath.load_on_demand}]`);
50
+ let moduleInfo : ModuleInfo = new ModuleInfo(modulePath.module_name, modulePath.load_on_demand);
51
+ env.modulesGen.push(moduleInfo);
52
+ }
53
+ }
54
+ }
55
+ if(!generateViaCLI)
56
+ LogLn(` Number of modules to be check for generate: ${web_modules.length}`);
57
+ return tree;
58
+ };
59
+ }
60
+
61
+ //-------------------------------------------------------------------------------------------------
62
+ // overwrite the web module file name with the new content
63
+ //-------------------------------------------------------------------------------------------------
64
+ export function overwriteWebModuleFileName(options: any, moduleNameFileName:string, content:string): Rule {
65
+ return (tree: Tree, _context: SchematicContext) => {
66
+
67
+ if(!tree.exists(moduleNameFileName)){
68
+ LogLn(` [>Error] File cannot be overwrite, The file is not exist !!! : ${moduleNameFileName}`);
69
+ }
70
+
71
+ tree.overwrite(moduleNameFileName, content);
72
+ return tree;
73
+ };
74
+ }
75
+
76
+ //-------------------------------------------------------------------------------------------------
77
+ // update the the web module file name with the new class name
78
+ //-------------------------------------------------------------------------------------------------
79
+ export function updateWebModuleFileWithNewClassName(options: any, webModuleName:string): Rule {
80
+ return (tree: Tree, context: SchematicContext) => {
81
+ let rules:Rule[] = [];
82
+
83
+ const origModuleFileName = getWebModuleFullFileName(webModuleName)
84
+
85
+ // create new class name for "web Module Name"
86
+ let newClassModuleName = getWebModuleClass(webModuleName );
87
+
88
+ //read the exist module file name
89
+ const text = tree.read(origModuleFileName);
90
+
91
+ if (text === null) {
92
+ throw new SchematicsException(`File ${origModuleFileName} does not exist.`);
93
+ }
94
+ let sourceText = text.toString('utf-8');
95
+
96
+ if (sourceText !== "") {
97
+ let newsourceText: string = sourceText.replace(`MagicGenLibModule`, newClassModuleName);
98
+ rules.push(overwriteWebModuleFileName(options, origModuleFileName, newsourceText));
99
+
100
+ }
101
+ return chain(rules)(tree, context);
102
+ };
103
+ }
104
+
105
+ //-------------------------------------------------------------------------------------------------
106
+ // copy the two default files into the web module path
107
+ //-------------------------------------------------------------------------------------------------
108
+ function copyDefaultMagicFilesToWebModule(options:MagicOptionScheme, webModuleName:string): Rule {
109
+ return (tree: Tree,context:SchematicContext) => {
110
+ const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
111
+
112
+ return chain([
113
+ branchAndMerge(chain([
114
+ mergeWith(
115
+ apply(url(`./../mg-add/files/src/app/magic/`), [
116
+
117
+ move(webModulePath)
118
+ ]), MergeStrategy.AllowCreationConflict)
119
+ ]))
120
+ ])(tree,context);
121
+ }
122
+ }
123
+
124
+
125
+ //-------------------------------------------------------------------------------------------------
126
+ // delete LazyLoadService for non root modules
127
+ //-------------------------------------------------------------------------------------------------
128
+ function deleteLazyLoadService( webModuleName:string): Rule {
129
+ return (tree: Tree) => {
130
+ const lazyLoaderServicePath = getDestinationModulePathByWebModuleName(webModuleName) + '/lazy-loader.service.ts';
131
+
132
+ if(webModuleName != '') {
133
+ if (!tree.exists(lazyLoaderServicePath)) {
134
+ LogLn(` [>Error] File cannot be overwrite, The file is not exist !!! :lazyLoaderServicePath`);
135
+ }
136
+
137
+ tree.delete(lazyLoaderServicePath);
138
+ return tree;
139
+ }
140
+ }
141
+ }
142
+
143
+
144
+ //-------------------------------------------------------------------------------------------------
145
+ // get destination path according to the send webModuleName
146
+ //-------------------------------------------------------------------------------------------------
147
+ export function getDestinationModulePathByWebModuleName(webModuleName:string):string {
148
+ const newDestModulePath = `${env.metadata.paths.rootMagicGenFolder}/${GEN_FOLDER}/${webModuleName}`;
149
+ return newDestModulePath;
150
+ }
151
+
152
+ //-------------------------------------------------------------------------------------------------
153
+ // get web module full file name according to the send webModuleName
154
+ //-------------------------------------------------------------------------------------------------
155
+ function getWebModuleFullFileName(webModuleName:string):string {
156
+ // calc the path of new the module
157
+ const newDestModulePath = getDestinationModulePathByWebModuleName(webModuleName);
158
+ return `${newDestModulePath}/magic.gen.lib.module.ts`;
159
+ }
160
+
161
+ //-------------------------------------------------------------------------------------------------
162
+ // get web module class according to the send webModuleName
163
+ //-------------------------------------------------------------------------------------------------
164
+ function getWebModuleClass(webModuleName:string):string {
165
+ return `Magic` + webModuleName + `Module`;
166
+ }
167
+
168
+
169
+ //-------------------------------------------------------------------------------------------------
170
+ // add magic module to app module
171
+ //-------------------------------------------------------------------------------------------------
172
+ function addMagicModuleToAppModule(options: MagicOptionScheme, modulePath:string, moduleName:string, srcModuleName:string) : Rule {
173
+ return (tree: Tree , context : SchematicContext)=>{
174
+ const project = env.project;
175
+
176
+ LogLn(` [>] add New Web Module :[${moduleName}] `);
177
+ LogLn(` [>] from :[${srcModuleName}]`);
178
+ LogLn(` [>] To App Module :[${modulePath}]`);
179
+ addModuleImportToModule(
180
+ tree,
181
+ modulePath, // for now we will update env.metadata.paths.magicGenLibModule
182
+ moduleName, // 'MagicXXXModule',
183
+ srcModuleName, // `./XXX/magic.gen.lib.module`
184
+ );
185
+ return tree;
186
+ }
187
+ }
188
+
189
+ //-------------------------------------------------------------------------------------------------
190
+ // create module
191
+ //-------------------------------------------------------------------------------------------------
192
+ export function checkAndCreateModule(options: MagicOptionScheme, webModuleName:string, loadOnDemand: boolean ): Rule {
193
+ return (tree: Tree, context: SchematicContext) => {
194
+
195
+ let rules: Rule[] = [];
196
+ const webModuleFullFileName = getWebModuleFullFileName(webModuleName);
197
+ // only if not exist create the new 2 files magic.gen.lib.module.ts & component-list.g.ts
198
+ if (!tree.exists(webModuleFullFileName)) {
199
+ rules.push(copyDefaultMagicFilesToWebModule(options, webModuleName));
200
+ rules.push(updateWebModuleFileWithNewClassName(tree, webModuleName));
201
+ rules.push(deleteLazyLoadService(webModuleName));
202
+ // for NON load on demand we need to update magic root module
203
+ if (!loadOnDemand) {
204
+ const newDestModulePath = `./${webModuleName}/magic.gen.lib.module`;
205
+ const webModuleClass = getWebModuleClass(webModuleName);
206
+ rules.push(addMagicModuleToAppModule(options, env.metadata.paths.magicGenLibModule, webModuleClass, newDestModulePath));
207
+ }
208
+ return chain(rules)(tree, context);
209
+ }
210
+ ;
211
+ }
212
+ }
213
+
214
+ //-------------------------------------------------------------------------------------------------
215
+ // check if module is exist, only if not exist create the web module
216
+ //-------------------------------------------------------------------------------------------------
217
+ export function generateWebModule(options: MagicOptionScheme, webModuleName:string, loadOnDemand:boolean ): Rule {
218
+ return (tree: Tree, context: SchematicContext) => {
219
+
220
+ let rules:Rule[] = [];
221
+
222
+ LogLn(` [>]Handling Web Module named: [${webModuleName}] isLoadOnDemand: [${loadOnDemand}]`);
223
+ rules.push(checkAndCreateModule(options, webModuleName, loadOnDemand));
224
+ rules.push(checkAndCreateRouteForModule(options, webModuleName, loadOnDemand));
225
+
226
+ return chain(rules)(tree,context);
227
+ };
228
+ }
229
+
230
+
231
+ //-------------------------------------------------------------------------------------------------
232
+ // generate all the modules in env.modulesGen
233
+ //-------------------------------------------------------------------------------------------------
234
+ export function generateWebModules(options: MagicOptionScheme, generateViaCLI:boolean = false): Rule {
235
+ return (tree: Tree, context: SchematicContext) => {
236
+
237
+ let rules:Rule[] = [];
238
+
239
+ for (let webModuleInfo of env.modulesGen){
240
+ if (webModuleInfo.moduleName !== undefined && webModuleInfo.moduleName !== "") {
241
+ if (generateViaCLI) {
242
+ if (webModuleInfo.moduleName === options.module) {
243
+ rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
244
+ }
245
+ }else{
246
+ rules.push(generateWebModule(options, webModuleInfo.moduleName, webModuleInfo.loadOnDemand));
247
+ }
248
+ }
249
+ }
250
+
251
+ return chain(rules)(tree,context);
252
+ };
253
+ }
254
+
255
+
256
+
257
+ //-------------------------------------------------------------------------------------------------
258
+ // check if module is exist, only if not exist create the web module
259
+ //-------------------------------------------------------------------------------------------------
260
+ export function checkAndCreateRouteForModule(options: MagicOptionScheme, webModuleName:string, loadOnDemand :boolean): Rule {
261
+ return (tree: Tree, context: SchematicContext) => {
262
+
263
+ let rules:Rule[] = [];
264
+
265
+ if (loadOnDemand) {
266
+ const newDestRoutePathForModule = env.metadata.paths.getRoutePathForWebModule(webModuleName);
267
+
268
+ // only if file not exist then copy the default route
269
+ if (!tree.exists(newDestRoutePathForModule)) {
270
+ rules.push(createRoute(options, webModuleName));
271
+ }
272
+ else{
273
+ // if file exist then only update the magic.gen.lib.module.ts
274
+ rules.push(addRouteFileToModuleFile(options, webModuleName));
275
+ }
276
+ }
277
+ return chain(rules)(tree,context);
278
+ };
279
+ }
280
+
281
+
282
+
283
+ //-------------------------------------------------------------------------------------------------
284
+ // create route for module
285
+ //-------------------------------------------------------------------------------------------------
286
+ export function createRoute(options: MagicOptionScheme, webModuleName:string): Rule {
287
+ return (tree: Tree, context: SchematicContext) => {
288
+
289
+ let rules:Rule[] = [];
290
+
291
+ rules.push(copyDefaultRouteMagicFilesToWebModule(options, webModuleName));
292
+ // --------------------------------------------------------
293
+ // // generate the route for module /////
294
+ // let routeItem : RouteTable = new RouteTable();
295
+ // routeItem.module_name = webModuleName;
296
+ //
297
+ // let route:Route = new Route();
298
+ // route.ModuleName = webModuleName;
299
+ // route.OutletName="";
300
+ // route.RouteName="";
301
+ // route.children=null;
302
+ //
303
+ // routeItem.routesArray = [route];
304
+ // rules.push(genRouteFile(options, routeItem ));
305
+ // --------------------------------------------------------
306
+ // update the new MagicRoutingModule in file magic.gen.lib.module.ts of the module
307
+
308
+
309
+ rules.push(addRouteFileToModuleFile(options, webModuleName));
310
+
311
+ return chain(rules)(tree,context);
312
+ };
313
+ }
314
+
315
+ //-------------------------------------------------------------------------------------------------
316
+ // create route for module
317
+ //-------------------------------------------------------------------------------------------------
318
+ export function addRouteFileToModuleFile(options: MagicOptionScheme, webModuleName:string): Rule {
319
+ return (tree: Tree, context: SchematicContext) => {
320
+
321
+ let rules:Rule[] = [];
322
+
323
+ const modulePath = getWebModuleFullFileName(webModuleName); // get the magic.gen.lib.module.ts according to the module name
324
+ const moduleName = `MagicRoutingModule`;//for now it will be the same for all modules ... getWebModuleClass(webModuleName);
325
+ const srcModuleName = `./app.routes`;
326
+
327
+ rules.push(addMagicModuleToAppModule(options, modulePath, moduleName, srcModuleName));
328
+
329
+ return chain(rules)(tree,context);
330
+ };
331
+ }
332
+ //-------------------------------------------------------------------------------------------------
333
+ // copy the two default files into the web module path
334
+ //-------------------------------------------------------------------------------------------------
335
+ function copyDefaultRouteMagicFilesToWebModule(options:MagicOptionScheme, webModuleName:string): Rule {
336
+ return (tree: Tree,context:SchematicContext) => {
337
+ const routeFileForWebModulePath = env.metadata.paths.getRoutePathForWebModule(webModuleName);
338
+
339
+
340
+ if(tree.exists(routeFileForWebModulePath))
341
+ {
342
+ let rules:Rule[] = [];
343
+ return chain(rules)(tree,context);
344
+ }
345
+ else
346
+ {
347
+ const webModulePath = getDestinationModulePathByWebModuleName(webModuleName);
348
+ LogLn(`[ >] copy default Route file to webModule [${webModuleName}]`)
349
+ return chain([
350
+ branchAndMerge(chain([
351
+ mergeWith(
352
+ apply(url(`./../mg-add/webModule/`), [
353
+
354
+ move(webModulePath)
355
+ ]), MergeStrategy.AllowCreationConflict)
356
+ ]))
357
+ ])(tree,context);
358
+ }
359
+ }
360
+ }