@magic-xpa/cli 4.801.0-dev481.392 → 4.801.0-dev481.430

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