@magic-xpa/cli 4.1000.0 → 4.1100.0-dev000.0

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 (307) hide show
  1. package/README.md +28 -28
  2. package/index.d.ts +1 -1
  3. package/index.js +4 -4
  4. package/index.js.map +1 -1
  5. package/index.ts +1 -1
  6. package/package.json +2 -2
  7. package/src/collection.json +75 -75
  8. package/src/public_api.d.ts +3 -3
  9. package/src/public_api.js +6 -6
  10. package/src/public_api.js.map +1 -1
  11. package/src/public_api.ts +5 -5
  12. package/src/schematics/magic-utils/Util.d.ts +6 -6
  13. package/src/schematics/magic-utils/Util.js +26 -26
  14. package/src/schematics/magic-utils/Util.js.map +1 -1
  15. package/src/schematics/magic-utils/config.d.ts +12 -12
  16. package/src/schematics/magic-utils/config.js +56 -56
  17. package/src/schematics/magic-utils/config.js.map +1 -1
  18. package/src/schematics/magic-utils/config.ts +68 -68
  19. package/src/schematics/magic-utils/env.d.ts +23 -23
  20. package/src/schematics/magic-utils/env.js +39 -39
  21. package/src/schematics/magic-utils/env.js.map +1 -1
  22. package/src/schematics/magic-utils/env.ts +50 -50
  23. package/src/schematics/magic-utils/manifest.d.ts +11 -11
  24. package/src/schematics/magic-utils/manifest.js +40 -40
  25. package/src/schematics/magic-utils/manifest.js.map +1 -1
  26. package/src/schematics/magic-utils/manifest.ts +46 -46
  27. package/src/schematics/magic-utils/metadata.class.d.ts +51 -51
  28. package/src/schematics/magic-utils/metadata.class.js +124 -124
  29. package/src/schematics/magic-utils/metadata.class.js.map +1 -1
  30. package/src/schematics/magic-utils/metadata.class.ts +159 -159
  31. package/src/schematics/magic-utils/process-json.d.ts +2 -2
  32. package/src/schematics/magic-utils/process-json.js +157 -158
  33. package/src/schematics/magic-utils/process-json.js.map +1 -1
  34. package/src/schematics/magic-utils/rules/build-control.rule.d.ts +5 -5
  35. package/src/schematics/magic-utils/rules/build-control.rule.js +73 -74
  36. package/src/schematics/magic-utils/rules/build-control.rule.js.map +1 -1
  37. package/src/schematics/magic-utils/rules/build-view.rule.d.ts +3 -3
  38. package/src/schematics/magic-utils/rules/build-view.rule.js +82 -80
  39. package/src/schematics/magic-utils/rules/build-view.rule.js.map +1 -1
  40. package/src/schematics/magic-utils/rules/build-view.rule.ts +4 -0
  41. package/src/schematics/magic-utils/rules/component-list.rule.d.ts +3 -3
  42. package/src/schematics/magic-utils/rules/component-list.rule.js +316 -317
  43. package/src/schematics/magic-utils/rules/component-list.rule.js.map +1 -1
  44. package/src/schematics/magic-utils/rules/generate.rule.d.ts +5 -5
  45. package/src/schematics/magic-utils/rules/generate.rule.js +53 -54
  46. package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
  47. package/src/schematics/magic-utils/rules/generate.rule.ts +61 -61
  48. package/src/schematics/magic-utils/rules/init-add-modules.rule.d.ts +12 -12
  49. package/src/schematics/magic-utils/rules/init-add-modules.rule.js +295 -296
  50. package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
  51. package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +360 -360
  52. package/src/schematics/magic-utils/rules/init-gen-components.rule.d.ts +4 -4
  53. package/src/schematics/magic-utils/rules/init-gen-components.rule.js +65 -66
  54. package/src/schematics/magic-utils/rules/init-gen-components.rule.js.map +1 -1
  55. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.d.ts +3 -3
  56. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js +17 -18
  57. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
  58. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.ts +19 -19
  59. package/src/schematics/magic-utils/rules/load-views-gen.rule.d.ts +3 -3
  60. package/src/schematics/magic-utils/rules/load-views-gen.rule.js +28 -29
  61. package/src/schematics/magic-utils/rules/load-views-gen.rule.js.map +1 -1
  62. package/src/schematics/magic-utils/rules/magic-option.scheme.d.ts +22 -21
  63. package/src/schematics/magic-utils/rules/magic-option.scheme.js +2 -2
  64. package/src/schematics/magic-utils/rules/magic-option.scheme.js.map +1 -1
  65. package/src/schematics/magic-utils/rules/magic-option.scheme.ts +24 -23
  66. package/src/schematics/magic-utils/utils.d.ts +12 -12
  67. package/src/schematics/magic-utils/utils.js +116 -117
  68. package/src/schematics/magic-utils/utils.js.map +1 -1
  69. package/src/schematics/magic-utils/utils.ts +134 -134
  70. package/src/schematics/mg-Install-prerequisites/index.d.ts +3 -3
  71. package/src/schematics/mg-Install-prerequisites/index.js +24 -25
  72. package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
  73. package/src/schematics/mg-Install-prerequisites/index.ts +30 -30
  74. package/src/schematics/mg-Install-prerequisites/schema.json +14 -14
  75. package/src/schematics/mg-add/files/src/app/app.component.html +17 -17
  76. package/src/schematics/mg-add/files/src/app/app.routes.ts +14 -14
  77. package/src/schematics/mg-add/files/src/app/magic/component-list.g.ts +9 -9
  78. package/src/schematics/mg-add/files/src/app/magic/lazy-loader.service.ts +2 -1
  79. package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +19 -19
  80. package/src/schematics/mg-add/files/src/magic-styles.css +131 -131
  81. package/src/schematics/mg-add/index.d.ts +3 -3
  82. package/src/schematics/mg-add/index.js +150 -151
  83. package/src/schematics/mg-add/index.js.map +1 -1
  84. package/src/schematics/mg-add/schema.json +29 -29
  85. package/src/schematics/mg-add/utils/add-declaration-to-root-module.d.ts +2 -2
  86. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js +10 -11
  87. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js.map +1 -1
  88. package/src/schematics/mg-add/utils/add-declaration-to-root-module.ts +12 -12
  89. package/src/schematics/mg-add/webModule/app.routes.ts +14 -14
  90. package/src/schematics/mg-add-tasks/index.d.ts +3 -3
  91. package/src/schematics/mg-add-tasks/index.js +29 -30
  92. package/src/schematics/mg-add-tasks/index.js.map +1 -1
  93. package/src/schematics/mg-add-tasks/index.ts +53 -53
  94. package/src/schematics/mg-add-tasks/schema.json +41 -41
  95. package/src/schematics/mg-delete-files/index.d.ts +3 -3
  96. package/src/schematics/mg-delete-files/index.js +12 -13
  97. package/src/schematics/mg-delete-files/index.js.map +1 -1
  98. package/src/schematics/mg-delete-files/index.ts +12 -12
  99. package/src/schematics/mg-delete-files/schema.json +14 -14
  100. package/src/schematics/mg-gen-module/index.d.ts +3 -3
  101. package/src/schematics/mg-gen-module/index.js +14 -15
  102. package/src/schematics/mg-gen-module/index.js.map +1 -1
  103. package/src/schematics/mg-gen-module/index.ts +14 -14
  104. package/src/schematics/mg-gen-module/schema.json +24 -24
  105. package/src/schematics/mg-generate/index.d.ts +3 -3
  106. package/src/schematics/mg-generate/index.js +12 -13
  107. package/src/schematics/mg-generate/index.js.map +1 -1
  108. package/src/schematics/mg-generate/index.ts +12 -12
  109. package/src/schematics/mg-generate/schema.json +34 -34
  110. package/src/schematics/mg-generate-component/index.d.ts +3 -3
  111. package/src/schematics/mg-generate-component/index.js +34 -35
  112. package/src/schematics/mg-generate-component/index.js.map +1 -1
  113. package/src/schematics/mg-generate-component/schema.json +6 -0
  114. package/src/schematics/mg-install/index.d.ts +3 -3
  115. package/src/schematics/mg-install/index.js +29 -30
  116. package/src/schematics/mg-install/index.js.map +1 -1
  117. package/src/schematics/mg-install/index.ts +37 -37
  118. package/src/schematics/mg-install/schema.json +24 -24
  119. package/src/schematics/mg-routes/index.d.ts +6 -6
  120. package/src/schematics/mg-routes/index.js +62 -63
  121. package/src/schematics/mg-routes/index.js.map +1 -1
  122. package/src/schematics/mg-routes/schema.json +14 -14
  123. package/src/schematics/mg-single-control/index.d.ts +3 -3
  124. package/src/schematics/mg-single-control/index.js +28 -29
  125. package/src/schematics/mg-single-control/index.js.map +1 -1
  126. package/src/schematics/mg-single-control/schema.json +24 -24
  127. package/src/schematics/utils/ast.d.ts +21 -21
  128. package/src/schematics/utils/ast.js +90 -91
  129. package/src/schematics/utils/ast.js.map +1 -1
  130. package/src/schematics/utils/ast.ts +103 -103
  131. package/src/schematics/utils/devkit-utils/README.md +1 -1
  132. package/src/schematics/utils/devkit-utils/ast-utils.d.ts +87 -87
  133. package/src/schematics/utils/devkit-utils/ast-utils.js +489 -490
  134. package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
  135. package/src/schematics/utils/devkit-utils/ast-utils.ts +570 -570
  136. package/src/schematics/utils/devkit-utils/ast-utils_old.d.ts +68 -68
  137. package/src/schematics/utils/devkit-utils/ast-utils_old.js +419 -420
  138. package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
  139. package/src/schematics/utils/devkit-utils/ast-utils_old.ts +478 -478
  140. package/src/schematics/utils/devkit-utils/change.d.ts +66 -66
  141. package/src/schematics/utils/devkit-utils/change.js +94 -94
  142. package/src/schematics/utils/devkit-utils/change.js.map +1 -1
  143. package/src/schematics/utils/devkit-utils/change.ts +127 -127
  144. package/src/schematics/utils/devkit-utils/component.d.ts +2 -2
  145. package/src/schematics/utils/devkit-utils/component.js +96 -97
  146. package/src/schematics/utils/devkit-utils/component.js.map +1 -1
  147. package/src/schematics/utils/devkit-utils/component.ts +136 -136
  148. package/src/schematics/utils/devkit-utils/config.d.ts +78 -78
  149. package/src/schematics/utils/devkit-utils/config.js +52 -52
  150. package/src/schematics/utils/devkit-utils/config.js.map +1 -1
  151. package/src/schematics/utils/devkit-utils/config.ts +120 -120
  152. package/src/schematics/utils/devkit-utils/find-module.d.ts +28 -28
  153. package/src/schematics/utils/devkit-utils/find-module.js +92 -93
  154. package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
  155. package/src/schematics/utils/devkit-utils/find-module.ts +108 -108
  156. package/src/schematics/utils/devkit-utils/ng-ast-utils.d.ts +5 -5
  157. package/src/schematics/utils/devkit-utils/ng-ast-utils.js +73 -74
  158. package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
  159. package/src/schematics/utils/devkit-utils/ng-ast-utils.ts +84 -84
  160. package/src/schematics/utils/devkit-utils/parse-name.d.ts +13 -13
  161. package/src/schematics/utils/devkit-utils/parse-name.js +19 -20
  162. package/src/schematics/utils/devkit-utils/parse-name.js.map +1 -1
  163. package/src/schematics/utils/devkit-utils/parse-name.ts +24 -24
  164. package/src/schematics/utils/devkit-utils/route-utils.d.ts +20 -20
  165. package/src/schematics/utils/devkit-utils/route-utils.js +133 -134
  166. package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
  167. package/src/schematics/utils/devkit-utils/route-utils.ts +180 -180
  168. package/src/schematics/utils/devkit-utils/validation.d.ts +1 -1
  169. package/src/schematics/utils/devkit-utils/validation.js +18 -19
  170. package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
  171. package/src/schematics/utils/devkit-utils/validation.ts +16 -16
  172. package/src/schematics/utils/html.d.ts +18 -18
  173. package/src/schematics/utils/html.js +59 -60
  174. package/src/schematics/utils/html.js.map +1 -1
  175. package/src/schematics/utils/html.ts +63 -63
  176. package/src/schematics/utils/lib-versions.d.ts +3 -3
  177. package/src/schematics/utils/lib-versions.js +6 -6
  178. package/src/schematics/utils/lib-versions.js.map +1 -1
  179. package/src/schematics/utils/lib-versions.ts +3 -3
  180. package/src/schematics/utils/package.d.ts +5 -5
  181. package/src/schematics/utils/package.js +20 -21
  182. package/src/schematics/utils/package.js.map +1 -1
  183. package/src/schematics/utils/package.ts +22 -22
  184. package/src/schematics/utils/testing.d.ts +5 -5
  185. package/src/schematics/utils/testing.js +26 -27
  186. package/src/schematics/utils/testing.js.map +1 -1
  187. package/src/schematics/utils/testing.ts +25 -25
  188. package/src/types/enums/Enums.d.ts +1646 -1646
  189. package/src/types/enums/Enums.js +1862 -1862
  190. package/src/types/enums/Enums.js.map +1 -1
  191. package/src/types/enums/Enums.ts +2063 -2063
  192. package/src/types/enums/generated-file-types.enum.d.ts +6 -6
  193. package/src/types/enums/generated-file-types.enum.js +10 -10
  194. package/src/types/enums/generated-file-types.enum.js.map +1 -1
  195. package/src/types/enums/generated-file-types.enum.ts +6 -6
  196. package/src/types/enums/horizontal-alignments.enum.d.ts +5 -5
  197. package/src/types/enums/horizontal-alignments.enum.js +9 -9
  198. package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
  199. package/src/types/enums/horizontal-alignments.enum.ts +6 -6
  200. package/src/types/enums/themes.enum.d.ts +6 -6
  201. package/src/types/enums/themes.enum.js +10 -10
  202. package/src/types/enums/themes.enum.js.map +1 -1
  203. package/src/types/enums/themes.enum.ts +6 -6
  204. package/src/types/index.d.ts +7 -7
  205. package/src/types/index.js +10 -10
  206. package/src/types/index.js.map +1 -1
  207. package/src/types/index.ts +8 -8
  208. package/src/types/interfaces/app.d.ts +53 -53
  209. package/src/types/interfaces/app.js +9 -9
  210. package/src/types/interfaces/app.js.map +1 -1
  211. package/src/types/interfaces/app.ts +89 -89
  212. package/src/types/interfaces/control.d.ts +82 -82
  213. package/src/types/interfaces/control.js +2 -2
  214. package/src/types/interfaces/control.js.map +1 -1
  215. package/src/types/interfaces/control.ts +106 -106
  216. package/src/types/interfaces/env.interface.d.ts +19 -19
  217. package/src/types/interfaces/env.interface.js +10 -10
  218. package/src/types/interfaces/template.config.d.ts +8 -8
  219. package/src/types/interfaces/template.config.js +2 -2
  220. package/src/types/interfaces/template.config.js.map +1 -1
  221. package/src/types/interfaces/template.config.ts +11 -11
  222. package/templates/angular/src/app/app.component.html.ejs +17 -17
  223. package/templates/angular/src/app/cmp-array.ejs +3 -3
  224. package/templates/angular/src/app/cmp-hash.ejs +3 -3
  225. package/templates/angular/src/app/component-list.g.ts +21 -21
  226. package/templates/angular/src/app.component.ts +14 -14
  227. package/templates/angular/src/app.module.ts +70 -70
  228. package/templates/angular/src/app.routes.ts +73 -73
  229. package/templates/angular/src/styles/app.css +5 -5
  230. package/templates/attributes/button_attributes.ejs +2 -2
  231. package/templates/attributes/common/base/class.ejs +6 -6
  232. package/templates/attributes/common/base/control_type.ejs +53 -53
  233. package/templates/attributes/common/base/enabled.ejs +9 -9
  234. package/templates/attributes/common/base/imageFileName.ejs +3 -3
  235. package/templates/attributes/common/base/no_control_class.ejs +3 -3
  236. package/templates/attributes/common/base/rtol.ejs +3 -3
  237. package/templates/attributes/common/base/tabindex.ejs +11 -11
  238. package/templates/attributes/common/base/testingId.ejs +8 -8
  239. package/templates/attributes/common/base/tooltip.ejs +7 -7
  240. package/templates/attributes/common/base/visible.ejs +6 -6
  241. package/templates/attributes/common/base/wallpaper.ejs +3 -3
  242. package/templates/attributes/common/base_attributes.ejs +10 -10
  243. package/templates/attributes/common/container_attributes.ejs +6 -6
  244. package/templates/attributes/common/control_attributes.ejs +3 -3
  245. package/templates/attributes/common/format.ejs +5 -5
  246. package/templates/attributes/common/input/hint.ejs +13 -13
  247. package/templates/attributes/common/input/multiline_edit.ejs +3 -3
  248. package/templates/attributes/common/input/must_input.ejs +8 -8
  249. package/templates/attributes/common/input/password_edit.ejs +7 -7
  250. package/templates/attributes/common/input/row_editing_input_attributes.ejs +6 -6
  251. package/templates/attributes/common/input/validation.ejs +5 -5
  252. package/templates/attributes/common/input_attributes.ejs +4 -4
  253. package/templates/attributes/common/no_control_base_attributes.ejs +4 -4
  254. package/templates/attributes/common/row_editing_button_attributes.ejs +10 -10
  255. package/templates/component/view.component.html +14 -14
  256. package/templates/component/view.component.ts +123 -122
  257. package/templates/themes/basicHTML/Code/theme.module.ts +10 -10
  258. package/templates/themes/basicHTML/checkbox.ejs +1 -1
  259. package/templates/themes/basicHTML/combobox.ejs +37 -37
  260. package/templates/themes/basicHTML/edit.ejs +169 -168
  261. package/templates/themes/basicHTML/form.ejs +4 -4
  262. package/templates/themes/basicHTML/group.ejs +4 -4
  263. package/templates/themes/basicHTML/image.ejs +6 -6
  264. package/templates/themes/basicHTML/label.ejs +11 -11
  265. package/templates/themes/basicHTML/listbox.ejs +21 -21
  266. package/templates/themes/basicHTML/push-button.ejs +28 -28
  267. package/templates/themes/basicHTML/radio.ejs +20 -20
  268. package/templates/themes/basicHTML/subform.ejs +6 -6
  269. package/templates/themes/basicHTML/tab.ejs +31 -31
  270. package/templates/themes/basicHTML/tabpage.ejs +5 -5
  271. package/templates/themes/basicHiddenHTML/Code/theme.module.ts +10 -10
  272. package/templates/themes/basicHiddenHTML/combobox.ejs +5 -5
  273. package/templates/themes/basicHiddenHTML/form.ejs +3 -3
  274. package/templates/themes/basicHiddenHTML/group.ejs +2 -2
  275. package/templates/themes/basicHiddenHTML/image.ejs +4 -4
  276. package/templates/themes/basicHiddenHTML/label.ejs +1 -1
  277. package/templates/themes/basicHiddenHTML/listbox.ejs +8 -8
  278. package/templates/themes/basicHiddenHTML/push-button.ejs +26 -26
  279. package/templates/themes/basicHiddenHTML/radio.ejs +17 -17
  280. package/templates/themes/basicHiddenHTML/tab.ejs +13 -13
  281. package/templates/themes/basicHiddenHTML/table.ejs +18 -18
  282. package/templates/themes/basicHiddenHTML/tabpage.ejs +2 -2
  283. package/templates/themes/container.ejs +26 -26
  284. package/templates/themes/control.ejs +52 -52
  285. package/templates/themes/editTypeSelector.ejs +1 -1
  286. package/templates/themes/material/Code/theme.module.ts +68 -68
  287. package/templates/themes/material/base_attributes_date.ejs +8 -8
  288. package/templates/themes/material/checkbox.ejs +1 -1
  289. package/templates/themes/material/combobox.ejs +43 -43
  290. package/templates/themes/material/edit.ejs +204 -204
  291. package/templates/themes/material/group.ejs +3 -3
  292. package/templates/themes/material/listbox.ejs +22 -23
  293. package/templates/themes/material/push-button.ejs +28 -28
  294. package/templates/themes/material/radio.ejs +22 -22
  295. package/templates/themes/material/subform.ejs +8 -8
  296. package/templates/themes/material/tab.ejs +19 -19
  297. package/templates/themes/router_outlet.ejs +5 -5
  298. package/templates/themes/table/HTMLTable/columnHeader.ejs +3 -1
  299. package/templates/themes/table/HTMLTable/table.ejs +37 -37
  300. package/templates/themes/table/grid/additionalComponentCode.ejs +26 -26
  301. package/templates/themes/table/grid/additionalIncludes.ejs +1 -1
  302. package/templates/themes/table/grid/column.ejs +3 -1
  303. package/templates/themes/table/grid/table.ejs +37 -37
  304. package/templates/themes/table/repeatable/column.ejs +11 -11
  305. package/templates/themes/table/repeatable/table.ejs +28 -28
  306. package/templates/themes/tableTypeSelector.ejs +21 -21
  307. package/tsconfig.json +36 -36
@@ -1,94 +1,93 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildRelativePath = exports.findModule = exports.findModuleFromOptions = void 0;
4
- /**
5
- * @license
6
- * Copyright Google Inc. All Rights Reserved.
7
- *
8
- * Use of this source code is governed by an MIT-style license that can be
9
- * found in the LICENSE file at https://angular.io/license
10
- */
11
- const core_1 = require("@angular-devkit/core");
12
- /**
13
- * Find the module referred by a set of options passed to the schematics.
14
- */
15
- function findModuleFromOptions(host, options) {
16
- if (options.hasOwnProperty('skipImport') && options.skipImport) {
17
- return undefined;
18
- }
19
- if (!options.module) {
20
- const pathToCheck = (options.path || '')
21
- + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name));
22
- return (0, core_1.normalize)(findModule(host, pathToCheck));
23
- }
24
- else {
25
- const modulePath = (0, core_1.normalize)('/' + (options.path) + '/' + options.module);
26
- const moduleBaseName = (0, core_1.normalize)(modulePath).split('/').pop();
27
- if (host.exists(modulePath)) {
28
- return (0, core_1.normalize)(modulePath);
29
- }
30
- else if (host.exists(modulePath + '.ts')) {
31
- return (0, core_1.normalize)(modulePath + '.ts');
32
- }
33
- else if (host.exists(modulePath + '.module.ts')) {
34
- return (0, core_1.normalize)(modulePath + '.module.ts');
35
- }
36
- else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
37
- return (0, core_1.normalize)(modulePath + '/' + moduleBaseName + '.module.ts');
38
- }
39
- else {
40
- throw new Error('Specified module does not exist');
41
- }
42
- }
43
- }
44
- exports.findModuleFromOptions = findModuleFromOptions;
45
- /**
46
- * Function to find the "closest" module to a generated file's path.
47
- */
48
- function findModule(host, generateDir) {
49
- let dir = host.getDir('/' + generateDir);
50
- const moduleRe = /\.module\.ts$/;
51
- const routingModuleRe = /-routing\.module\.ts/;
52
- while (dir) {
53
- const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
54
- if (matches.length == 1) {
55
- return (0, core_1.join)(dir.path, matches[0]);
56
- }
57
- else if (matches.length > 1) {
58
- throw new Error('More than one module matches. Use skip-import option to skip importing '
59
- + 'the component into the closest module.');
60
- }
61
- dir = dir.parent;
62
- }
63
- throw new Error('Could not find an NgModule. Use the skip-import '
64
- + 'option to skip importing in NgModule.');
65
- }
66
- exports.findModule = findModule;
67
- /**
68
- * Build a relative path from one file path to another file path.
69
- */
70
- function buildRelativePath(from, to) {
71
- from = (0, core_1.normalize)(from);
72
- to = (0, core_1.normalize)(to);
73
- // Convert to arrays.
74
- const fromParts = from.split('/');
75
- const toParts = to.split('/');
76
- // Remove file names (preserving destination)
77
- fromParts.pop();
78
- const toFileName = toParts.pop();
79
- const relativePath = (0, core_1.relative)((0, core_1.normalize)(fromParts.join('/')), (0, core_1.normalize)(toParts.join('/')));
80
- let pathPrefix = '';
81
- // Set the path prefix for same dir or child dir, parent dir starts with `..`
82
- if (!relativePath) {
83
- pathPrefix = '.';
84
- }
85
- else if (!relativePath.startsWith('.')) {
86
- pathPrefix = `./`;
87
- }
88
- if (pathPrefix && !pathPrefix.endsWith('/')) {
89
- pathPrefix += '/';
90
- }
91
- return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
92
- }
93
- exports.buildRelativePath = buildRelativePath;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findModuleFromOptions = findModuleFromOptions;
4
+ exports.findModule = findModule;
5
+ exports.buildRelativePath = buildRelativePath;
6
+ /**
7
+ * @license
8
+ * Copyright Google Inc. All Rights Reserved.
9
+ *
10
+ * Use of this source code is governed by an MIT-style license that can be
11
+ * found in the LICENSE file at https://angular.io/license
12
+ */
13
+ const core_1 = require("@angular-devkit/core");
14
+ /**
15
+ * Find the module referred by a set of options passed to the schematics.
16
+ */
17
+ function findModuleFromOptions(host, options) {
18
+ if (options.hasOwnProperty('skipImport') && options.skipImport) {
19
+ return undefined;
20
+ }
21
+ if (!options.module) {
22
+ const pathToCheck = (options.path || '')
23
+ + (options.flat ? '' : '/' + core_1.strings.dasherize(options.name));
24
+ return (0, core_1.normalize)(findModule(host, pathToCheck));
25
+ }
26
+ else {
27
+ const modulePath = (0, core_1.normalize)('/' + (options.path) + '/' + options.module);
28
+ const moduleBaseName = (0, core_1.normalize)(modulePath).split('/').pop();
29
+ if (host.exists(modulePath)) {
30
+ return (0, core_1.normalize)(modulePath);
31
+ }
32
+ else if (host.exists(modulePath + '.ts')) {
33
+ return (0, core_1.normalize)(modulePath + '.ts');
34
+ }
35
+ else if (host.exists(modulePath + '.module.ts')) {
36
+ return (0, core_1.normalize)(modulePath + '.module.ts');
37
+ }
38
+ else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
39
+ return (0, core_1.normalize)(modulePath + '/' + moduleBaseName + '.module.ts');
40
+ }
41
+ else {
42
+ throw new Error('Specified module does not exist');
43
+ }
44
+ }
45
+ }
46
+ /**
47
+ * Function to find the "closest" module to a generated file's path.
48
+ */
49
+ function findModule(host, generateDir) {
50
+ let dir = host.getDir('/' + generateDir);
51
+ const moduleRe = /\.module\.ts$/;
52
+ const routingModuleRe = /-routing\.module\.ts/;
53
+ while (dir) {
54
+ const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
55
+ if (matches.length == 1) {
56
+ return (0, core_1.join)(dir.path, matches[0]);
57
+ }
58
+ else if (matches.length > 1) {
59
+ throw new Error('More than one module matches. Use skip-import option to skip importing '
60
+ + 'the component into the closest module.');
61
+ }
62
+ dir = dir.parent;
63
+ }
64
+ throw new Error('Could not find an NgModule. Use the skip-import '
65
+ + 'option to skip importing in NgModule.');
66
+ }
67
+ /**
68
+ * Build a relative path from one file path to another file path.
69
+ */
70
+ function buildRelativePath(from, to) {
71
+ from = (0, core_1.normalize)(from);
72
+ to = (0, core_1.normalize)(to);
73
+ // Convert to arrays.
74
+ const fromParts = from.split('/');
75
+ const toParts = to.split('/');
76
+ // Remove file names (preserving destination)
77
+ fromParts.pop();
78
+ const toFileName = toParts.pop();
79
+ const relativePath = (0, core_1.relative)((0, core_1.normalize)(fromParts.join('/')), (0, core_1.normalize)(toParts.join('/')));
80
+ let pathPrefix = '';
81
+ // Set the path prefix for same dir or child dir, parent dir starts with `..`
82
+ if (!relativePath) {
83
+ pathPrefix = '.';
84
+ }
85
+ else if (!relativePath.startsWith('.')) {
86
+ pathPrefix = `./`;
87
+ }
88
+ if (pathPrefix && !pathPrefix.endsWith('/')) {
89
+ pathPrefix += '/';
90
+ }
91
+ return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
92
+ }
94
93
  //# sourceMappingURL=find-module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-module.js","sourceRoot":"","sources":["find-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+CAAgF;AAahF;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAAU,EAAE,OAAsB;IACtE,IAAI,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE;QAC9D,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;cACpB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAEhF,OAAO,IAAA,gBAAS,EAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;KACjD;SAAM;QACL,MAAM,UAAU,GAAG,IAAA,gBAAS,EAC1B,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,cAAc,GAAG,IAAA,g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,UAAU,IAAI,GAAG,CAAC;KACnB;IAED,OAAO,UAAU,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC;AAC5E,CAAC;AA1BD,8CA0BC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { Path, join, normalize, relative, strings } from '@angular-devkit/core';\nimport { DirEntry, Tree } from '@angular-devkit/schematics';\n\n\nexport interface ModuleOptions {\n module?: string;\n name: string;\n flat?: boolean;\n path?: string;\n skipImport?: boolean;\n}\n\n\n/**\n * Find the module referred by a set of options passed to the schematics.\n */\nexport function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined {\n if (options.hasOwnProperty('skipImport') && options.skipImport) {\n return undefined;\n }\n\n if (!options.module) {\n const pathToCheck = (options.path || '')\n + (options.flat ? '' : '/' + strings.dasherize(options.name));\n\n return normalize(findModule(host, pathToCheck));\n } else {\n const modulePath = normalize(\n '/' + (options.path) + '/' + options.module);\n const moduleBaseName = normalize(modulePath).split('/').pop();\n\n if (host.exists(modulePath)) {\n return normalize(modulePath);\n } else if (host.exists(modulePath + '.ts')) {\n return normalize(modulePath + '.ts');\n } else if (host.exists(modulePath + '.module.ts')) {\n return normalize(modulePath + '.module.ts');\n } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {\n return normalize(modulePath + '/' + moduleBaseName + '.module.ts');\n } else {\n throw new Error('Specified module does not exist');\n }\n }\n}\n\n/**\n * Function to find the \"closest\" module to a generated file's path.\n */\nexport function findModule(host: Tree, generateDir: string): Path {\n let dir: DirEntry | null = host.getDir('/' + generateDir);\n\n const moduleRe = /\\.module\\.ts$/;\n const routingModuleRe = /-routing\\.module\\.ts/;\n\n while (dir) {\n const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));\n\n if (matches.length == 1) {\n return join(dir.path, matches[0]);\n } else if (matches.length > 1) {\n throw new Error('More than one module matches. Use skip-import option to skip importing '\n + 'the component into the closest module.');\n }\n\n dir = dir.parent;\n }\n\n throw new Error('Could not find an NgModule. Use the skip-import '\n + 'option to skip importing in NgModule.');\n}\n\n/**\n * Build a relative path from one file path to another file path.\n */\nexport function buildRelativePath(from: string, to: string): string {\n from = normalize(from);\n to = normalize(to);\n\n // Convert to arrays.\n const fromParts = from.split('/');\n const toParts = to.split('/');\n\n // Remove file names (preserving destination)\n fromParts.pop();\n const toFileName = toParts.pop();\n\n const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));\n let pathPrefix = '';\n\n // Set the path prefix for same dir or child dir, parent dir starts with `..`\n if (!relativePath) {\n pathPrefix = '.';\n } else if (!relativePath.startsWith('.')) {\n pathPrefix = `./`;\n }\n if (pathPrefix && !pathPrefix.endsWith('/')) {\n pathPrefix += '/';\n }\n\n return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;\n}\n"]}
1
+ {"version":3,"file":"find-module.js","sourceRoot":"","sources":["find-module.ts"],"names":[],"mappings":";;AAuBA,sDA2BC;AAKD,gCAqBC;AAKD,8CA0BC;AA3GD;;;;;;GAMG;AACH,+CAAgF;AAahF;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAAU,EAAE,OAAsB;IACtE,IAAI,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAC/D,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;cACpB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAEhF,OAAO,IA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,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5F,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,6EAA6E;IAC7E,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,UAAU,GAAG,GAAG,CAAC;IACnB,CAAC;SAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5C,UAAU,IAAI,GAAG,CAAC;IACpB,CAAC;IAED,OAAO,UAAU,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC;AAC5E,CAAC","sourcesContent":["/**\r\n * @license\r\n * Copyright Google Inc. All Rights Reserved.\r\n *\r\n * Use of this source code is governed by an MIT-style license that can be\r\n * found in the LICENSE file at https://angular.io/license\r\n */\r\nimport { Path, join, normalize, relative, strings } from '@angular-devkit/core';\r\nimport { DirEntry, Tree } from '@angular-devkit/schematics';\r\n\r\n\r\nexport interface ModuleOptions {\r\n module?: string;\r\n name: string;\r\n flat?: boolean;\r\n path?: string;\r\n skipImport?: boolean;\r\n}\r\n\r\n\r\n/**\r\n * Find the module referred by a set of options passed to the schematics.\r\n */\r\nexport function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined {\r\n if (options.hasOwnProperty('skipImport') && options.skipImport) {\r\n return undefined;\r\n }\r\n\r\n if (!options.module) {\r\n const pathToCheck = (options.path || '')\r\n + (options.flat ? '' : '/' + strings.dasherize(options.name));\r\n\r\n return normalize(findModule(host, pathToCheck));\r\n } else {\r\n const modulePath = normalize(\r\n '/' + (options.path) + '/' + options.module);\r\n const moduleBaseName = normalize(modulePath).split('/').pop();\r\n\r\n if (host.exists(modulePath)) {\r\n return normalize(modulePath);\r\n } else if (host.exists(modulePath + '.ts')) {\r\n return normalize(modulePath + '.ts');\r\n } else if (host.exists(modulePath + '.module.ts')) {\r\n return normalize(modulePath + '.module.ts');\r\n } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {\r\n return normalize(modulePath + '/' + moduleBaseName + '.module.ts');\r\n } else {\r\n throw new Error('Specified module does not exist');\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Function to find the \"closest\" module to a generated file's path.\r\n */\r\nexport function findModule(host: Tree, generateDir: string): Path {\r\n let dir: DirEntry | null = host.getDir('/' + generateDir);\r\n\r\n const moduleRe = /\\.module\\.ts$/;\r\n const routingModuleRe = /-routing\\.module\\.ts/;\r\n\r\n while (dir) {\r\n const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));\r\n\r\n if (matches.length == 1) {\r\n return join(dir.path, matches[0]);\r\n } else if (matches.length > 1) {\r\n throw new Error('More than one module matches. Use skip-import option to skip importing '\r\n + 'the component into the closest module.');\r\n }\r\n\r\n dir = dir.parent;\r\n }\r\n\r\n throw new Error('Could not find an NgModule. Use the skip-import '\r\n + 'option to skip importing in NgModule.');\r\n}\r\n\r\n/**\r\n * Build a relative path from one file path to another file path.\r\n */\r\nexport function buildRelativePath(from: string, to: string): string {\r\n from = normalize(from);\r\n to = normalize(to);\r\n\r\n // Convert to arrays.\r\n const fromParts = from.split('/');\r\n const toParts = to.split('/');\r\n\r\n // Remove file names (preserving destination)\r\n fromParts.pop();\r\n const toFileName = toParts.pop();\r\n\r\n const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));\r\n let pathPrefix = '';\r\n\r\n // Set the path prefix for same dir or child dir, parent dir starts with `..`\r\n if (!relativePath) {\r\n pathPrefix = '.';\r\n } else if (!relativePath.startsWith('.')) {\r\n pathPrefix = `./`;\r\n }\r\n if (pathPrefix && !pathPrefix.endsWith('/')) {\r\n pathPrefix += '/';\r\n }\r\n\r\n return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;\r\n}\r\n"]}
@@ -1,108 +1,108 @@
1
- /**
2
- * @license
3
- * Copyright Google Inc. All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- import { Path, join, normalize, relative, strings } from '@angular-devkit/core';
9
- import { DirEntry, Tree } from '@angular-devkit/schematics';
10
-
11
-
12
- export interface ModuleOptions {
13
- module?: string;
14
- name: string;
15
- flat?: boolean;
16
- path?: string;
17
- skipImport?: boolean;
18
- }
19
-
20
-
21
- /**
22
- * Find the module referred by a set of options passed to the schematics.
23
- */
24
- export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined {
25
- if (options.hasOwnProperty('skipImport') && options.skipImport) {
26
- return undefined;
27
- }
28
-
29
- if (!options.module) {
30
- const pathToCheck = (options.path || '')
31
- + (options.flat ? '' : '/' + strings.dasherize(options.name));
32
-
33
- return normalize(findModule(host, pathToCheck));
34
- } else {
35
- const modulePath = normalize(
36
- '/' + (options.path) + '/' + options.module);
37
- const moduleBaseName = normalize(modulePath).split('/').pop();
38
-
39
- if (host.exists(modulePath)) {
40
- return normalize(modulePath);
41
- } else if (host.exists(modulePath + '.ts')) {
42
- return normalize(modulePath + '.ts');
43
- } else if (host.exists(modulePath + '.module.ts')) {
44
- return normalize(modulePath + '.module.ts');
45
- } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
46
- return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
47
- } else {
48
- throw new Error('Specified module does not exist');
49
- }
50
- }
51
- }
52
-
53
- /**
54
- * Function to find the "closest" module to a generated file's path.
55
- */
56
- export function findModule(host: Tree, generateDir: string): Path {
57
- let dir: DirEntry | null = host.getDir('/' + generateDir);
58
-
59
- const moduleRe = /\.module\.ts$/;
60
- const routingModuleRe = /-routing\.module\.ts/;
61
-
62
- while (dir) {
63
- const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
64
-
65
- if (matches.length == 1) {
66
- return join(dir.path, matches[0]);
67
- } else if (matches.length > 1) {
68
- throw new Error('More than one module matches. Use skip-import option to skip importing '
69
- + 'the component into the closest module.');
70
- }
71
-
72
- dir = dir.parent;
73
- }
74
-
75
- throw new Error('Could not find an NgModule. Use the skip-import '
76
- + 'option to skip importing in NgModule.');
77
- }
78
-
79
- /**
80
- * Build a relative path from one file path to another file path.
81
- */
82
- export function buildRelativePath(from: string, to: string): string {
83
- from = normalize(from);
84
- to = normalize(to);
85
-
86
- // Convert to arrays.
87
- const fromParts = from.split('/');
88
- const toParts = to.split('/');
89
-
90
- // Remove file names (preserving destination)
91
- fromParts.pop();
92
- const toFileName = toParts.pop();
93
-
94
- const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));
95
- let pathPrefix = '';
96
-
97
- // Set the path prefix for same dir or child dir, parent dir starts with `..`
98
- if (!relativePath) {
99
- pathPrefix = '.';
100
- } else if (!relativePath.startsWith('.')) {
101
- pathPrefix = `./`;
102
- }
103
- if (pathPrefix && !pathPrefix.endsWith('/')) {
104
- pathPrefix += '/';
105
- }
106
-
107
- return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
108
- }
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Path, join, normalize, relative, strings } from '@angular-devkit/core';
9
+ import { DirEntry, Tree } from '@angular-devkit/schematics';
10
+
11
+
12
+ export interface ModuleOptions {
13
+ module?: string;
14
+ name: string;
15
+ flat?: boolean;
16
+ path?: string;
17
+ skipImport?: boolean;
18
+ }
19
+
20
+
21
+ /**
22
+ * Find the module referred by a set of options passed to the schematics.
23
+ */
24
+ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined {
25
+ if (options.hasOwnProperty('skipImport') && options.skipImport) {
26
+ return undefined;
27
+ }
28
+
29
+ if (!options.module) {
30
+ const pathToCheck = (options.path || '')
31
+ + (options.flat ? '' : '/' + strings.dasherize(options.name));
32
+
33
+ return normalize(findModule(host, pathToCheck));
34
+ } else {
35
+ const modulePath = normalize(
36
+ '/' + (options.path) + '/' + options.module);
37
+ const moduleBaseName = normalize(modulePath).split('/').pop();
38
+
39
+ if (host.exists(modulePath)) {
40
+ return normalize(modulePath);
41
+ } else if (host.exists(modulePath + '.ts')) {
42
+ return normalize(modulePath + '.ts');
43
+ } else if (host.exists(modulePath + '.module.ts')) {
44
+ return normalize(modulePath + '.module.ts');
45
+ } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
46
+ return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
47
+ } else {
48
+ throw new Error('Specified module does not exist');
49
+ }
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Function to find the "closest" module to a generated file's path.
55
+ */
56
+ export function findModule(host: Tree, generateDir: string): Path {
57
+ let dir: DirEntry | null = host.getDir('/' + generateDir);
58
+
59
+ const moduleRe = /\.module\.ts$/;
60
+ const routingModuleRe = /-routing\.module\.ts/;
61
+
62
+ while (dir) {
63
+ const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
64
+
65
+ if (matches.length == 1) {
66
+ return join(dir.path, matches[0]);
67
+ } else if (matches.length > 1) {
68
+ throw new Error('More than one module matches. Use skip-import option to skip importing '
69
+ + 'the component into the closest module.');
70
+ }
71
+
72
+ dir = dir.parent;
73
+ }
74
+
75
+ throw new Error('Could not find an NgModule. Use the skip-import '
76
+ + 'option to skip importing in NgModule.');
77
+ }
78
+
79
+ /**
80
+ * Build a relative path from one file path to another file path.
81
+ */
82
+ export function buildRelativePath(from: string, to: string): string {
83
+ from = normalize(from);
84
+ to = normalize(to);
85
+
86
+ // Convert to arrays.
87
+ const fromParts = from.split('/');
88
+ const toParts = to.split('/');
89
+
90
+ // Remove file names (preserving destination)
91
+ fromParts.pop();
92
+ const toFileName = toParts.pop();
93
+
94
+ const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));
95
+ let pathPrefix = '';
96
+
97
+ // Set the path prefix for same dir or child dir, parent dir starts with `..`
98
+ if (!relativePath) {
99
+ pathPrefix = '.';
100
+ } else if (!relativePath.startsWith('.')) {
101
+ pathPrefix = `./`;
102
+ }
103
+ if (pathPrefix && !pathPrefix.endsWith('/')) {
104
+ pathPrefix += '/';
105
+ }
106
+
107
+ return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
108
+ }
@@ -1,5 +1,5 @@
1
- import { Tree } from '@angular-devkit/schematics';
2
- import * as ts from 'typescript';
3
- export declare function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallExpression | null;
4
- export declare function findBootstrapModulePath(host: Tree, mainPath: string): string;
5
- export declare function getAppModulePath(host: Tree, mainPath: string): string;
1
+ import { Tree } from '@angular-devkit/schematics';
2
+ import * as ts from 'typescript';
3
+ export declare function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallExpression | null;
4
+ export declare function findBootstrapModulePath(host: Tree, mainPath: string): string;
5
+ export declare function getAppModulePath(host: Tree, mainPath: string): string;
@@ -1,75 +1,74 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAppModulePath = exports.findBootstrapModulePath = exports.findBootstrapModuleCall = void 0;
4
- /**
5
- * @license
6
- * Copyright Google Inc. All Rights Reserved.
7
- *
8
- * Use of this source code is governed by an MIT-style license that can be
9
- * found in the LICENSE file at https://angular.io/license
10
- */
11
- const core_1 = require("@angular-devkit/core");
12
- const schematics_1 = require("@angular-devkit/schematics");
13
- const path_1 = require("path");
14
- const ts = require("typescript");
15
- const ast_utils_1 = require("./ast-utils");
16
- function findBootstrapModuleCall(host, mainPath) {
17
- const mainBuffer = host.read(mainPath);
18
- if (!mainBuffer) {
19
- throw new schematics_1.SchematicsException(`Main file (${mainPath}) not found`);
20
- }
21
- const mainText = mainBuffer.toString('utf-8');
22
- const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
23
- const allNodes = (0, ast_utils_1.getSourceNodes)(source);
24
- let bootstrapCall = null;
25
- for (const node of allNodes) {
26
- let bootstrapCallNode = null;
27
- bootstrapCallNode = (0, ast_utils_1.findNode)(node, ts.SyntaxKind.Identifier, 'bootstrapModule');
28
- // Walk up the parent until CallExpression is found.
29
- while (bootstrapCallNode && bootstrapCallNode.parent
30
- && bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) {
31
- bootstrapCallNode = bootstrapCallNode.parent;
32
- }
33
- if (bootstrapCallNode !== null &&
34
- bootstrapCallNode.parent !== undefined &&
35
- bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression) {
36
- bootstrapCall = bootstrapCallNode.parent;
37
- break;
38
- }
39
- }
40
- return bootstrapCall;
41
- }
42
- exports.findBootstrapModuleCall = findBootstrapModuleCall;
43
- function findBootstrapModulePath(host, mainPath) {
44
- const bootstrapCall = findBootstrapModuleCall(host, mainPath);
45
- if (!bootstrapCall) {
46
- throw new schematics_1.SchematicsException('Bootstrap call not found');
47
- }
48
- const bootstrapModule = bootstrapCall.arguments[0];
49
- const mainBuffer = host.read(mainPath);
50
- if (!mainBuffer) {
51
- throw new schematics_1.SchematicsException(`Client app main file (${mainPath}) not found`);
52
- }
53
- const mainText = mainBuffer.toString('utf-8');
54
- const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
55
- const allNodes = (0, ast_utils_1.getSourceNodes)(source);
56
- const bootstrapModuleRelativePath = allNodes
57
- .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
58
- .filter(imp => {
59
- return (0, ast_utils_1.findNode)(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
60
- })
61
- .map((imp) => {
62
- const modulePathStringLiteral = imp.moduleSpecifier;
63
- return modulePathStringLiteral.text;
64
- })[0];
65
- return bootstrapModuleRelativePath;
66
- }
67
- exports.findBootstrapModulePath = findBootstrapModulePath;
68
- function getAppModulePath(host, mainPath) {
69
- const moduleRelativePath = findBootstrapModulePath(host, mainPath);
70
- const mainDir = (0, path_1.dirname)(mainPath);
71
- const modulePath = (0, core_1.normalize)(`/${mainDir}/${moduleRelativePath}.ts`);
72
- return modulePath;
73
- }
74
- exports.getAppModulePath = getAppModulePath;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findBootstrapModuleCall = findBootstrapModuleCall;
4
+ exports.findBootstrapModulePath = findBootstrapModulePath;
5
+ exports.getAppModulePath = getAppModulePath;
6
+ /**
7
+ * @license
8
+ * Copyright Google Inc. All Rights Reserved.
9
+ *
10
+ * Use of this source code is governed by an MIT-style license that can be
11
+ * found in the LICENSE file at https://angular.io/license
12
+ */
13
+ const core_1 = require("@angular-devkit/core");
14
+ const schematics_1 = require("@angular-devkit/schematics");
15
+ const path_1 = require("path");
16
+ const ts = require("typescript");
17
+ const ast_utils_1 = require("./ast-utils");
18
+ function findBootstrapModuleCall(host, mainPath) {
19
+ const mainBuffer = host.read(mainPath);
20
+ if (!mainBuffer) {
21
+ throw new schematics_1.SchematicsException(`Main file (${mainPath}) not found`);
22
+ }
23
+ const mainText = mainBuffer.toString('utf-8');
24
+ const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
25
+ const allNodes = (0, ast_utils_1.getSourceNodes)(source);
26
+ let bootstrapCall = null;
27
+ for (const node of allNodes) {
28
+ let bootstrapCallNode = null;
29
+ bootstrapCallNode = (0, ast_utils_1.findNode)(node, ts.SyntaxKind.Identifier, 'bootstrapModule');
30
+ // Walk up the parent until CallExpression is found.
31
+ while (bootstrapCallNode && bootstrapCallNode.parent
32
+ && bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) {
33
+ bootstrapCallNode = bootstrapCallNode.parent;
34
+ }
35
+ if (bootstrapCallNode !== null &&
36
+ bootstrapCallNode.parent !== undefined &&
37
+ bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression) {
38
+ bootstrapCall = bootstrapCallNode.parent;
39
+ break;
40
+ }
41
+ }
42
+ return bootstrapCall;
43
+ }
44
+ function findBootstrapModulePath(host, mainPath) {
45
+ const bootstrapCall = findBootstrapModuleCall(host, mainPath);
46
+ if (!bootstrapCall) {
47
+ throw new schematics_1.SchematicsException('Bootstrap call not found');
48
+ }
49
+ const bootstrapModule = bootstrapCall.arguments[0];
50
+ const mainBuffer = host.read(mainPath);
51
+ if (!mainBuffer) {
52
+ throw new schematics_1.SchematicsException(`Client app main file (${mainPath}) not found`);
53
+ }
54
+ const mainText = mainBuffer.toString('utf-8');
55
+ const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
56
+ const allNodes = (0, ast_utils_1.getSourceNodes)(source);
57
+ const bootstrapModuleRelativePath = allNodes
58
+ .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
59
+ .filter(imp => {
60
+ return (0, ast_utils_1.findNode)(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
61
+ })
62
+ .map((imp) => {
63
+ const modulePathStringLiteral = imp.moduleSpecifier;
64
+ return modulePathStringLiteral.text;
65
+ })[0];
66
+ return bootstrapModuleRelativePath;
67
+ }
68
+ function getAppModulePath(host, mainPath) {
69
+ const moduleRelativePath = findBootstrapModulePath(host, mainPath);
70
+ const mainDir = (0, path_1.dirname)(mainPath);
71
+ const modulePath = (0, core_1.normalize)(`/${mainDir}/${moduleRelativePath}.ts`);
72
+ return modulePath;
73
+ }
75
74
  //# sourceMappingURL=ng-ast-utils.js.map