@magic-xpa/cli 4.1100.0-dev4110.99 → 4.1101.0-dev4111.269

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 (305) 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 -83
  39. package/src/schematics/magic-utils/rules/build-view.rule.js.map +1 -1
  40. package/src/schematics/magic-utils/rules/component-list.rule.d.ts +3 -3
  41. package/src/schematics/magic-utils/rules/component-list.rule.js +316 -317
  42. package/src/schematics/magic-utils/rules/component-list.rule.js.map +1 -1
  43. package/src/schematics/magic-utils/rules/generate.rule.d.ts +5 -5
  44. package/src/schematics/magic-utils/rules/generate.rule.js +53 -54
  45. package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
  46. package/src/schematics/magic-utils/rules/generate.rule.ts +61 -61
  47. package/src/schematics/magic-utils/rules/init-add-modules.rule.d.ts +12 -12
  48. package/src/schematics/magic-utils/rules/init-add-modules.rule.js +295 -296
  49. package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
  50. package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +360 -360
  51. package/src/schematics/magic-utils/rules/init-gen-components.rule.d.ts +4 -4
  52. package/src/schematics/magic-utils/rules/init-gen-components.rule.js +65 -66
  53. package/src/schematics/magic-utils/rules/init-gen-components.rule.js.map +1 -1
  54. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.d.ts +3 -3
  55. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js +17 -18
  56. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
  57. package/src/schematics/magic-utils/rules/init-magic-metadata.rule.ts +19 -19
  58. package/src/schematics/magic-utils/rules/load-views-gen.rule.d.ts +3 -3
  59. package/src/schematics/magic-utils/rules/load-views-gen.rule.js +28 -29
  60. package/src/schematics/magic-utils/rules/load-views-gen.rule.js.map +1 -1
  61. package/src/schematics/magic-utils/rules/magic-option.scheme.d.ts +22 -22
  62. package/src/schematics/magic-utils/rules/magic-option.scheme.js +2 -2
  63. package/src/schematics/magic-utils/rules/magic-option.scheme.js.map +1 -1
  64. package/src/schematics/magic-utils/rules/magic-option.scheme.ts +24 -24
  65. package/src/schematics/magic-utils/utils.d.ts +12 -12
  66. package/src/schematics/magic-utils/utils.js +116 -117
  67. package/src/schematics/magic-utils/utils.js.map +1 -1
  68. package/src/schematics/magic-utils/utils.ts +134 -134
  69. package/src/schematics/mg-Install-prerequisites/index.d.ts +3 -3
  70. package/src/schematics/mg-Install-prerequisites/index.js +24 -25
  71. package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
  72. package/src/schematics/mg-Install-prerequisites/index.ts +30 -30
  73. package/src/schematics/mg-Install-prerequisites/schema.json +14 -14
  74. package/src/schematics/mg-add/files/src/app/app.component.html +17 -17
  75. package/src/schematics/mg-add/files/src/app/app.routes.ts +14 -14
  76. package/src/schematics/mg-add/files/src/app/magic/component-list.g.ts +9 -9
  77. package/src/schematics/mg-add/files/src/app/magic/lazy-loader.service.ts +2 -1
  78. package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +19 -19
  79. package/src/schematics/mg-add/files/src/magic-styles.css +131 -131
  80. package/src/schematics/mg-add/index.d.ts +3 -3
  81. package/src/schematics/mg-add/index.js +150 -151
  82. package/src/schematics/mg-add/index.js.map +1 -1
  83. package/src/schematics/mg-add/schema.json +29 -29
  84. package/src/schematics/mg-add/utils/add-declaration-to-root-module.d.ts +2 -2
  85. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js +10 -11
  86. package/src/schematics/mg-add/utils/add-declaration-to-root-module.js.map +1 -1
  87. package/src/schematics/mg-add/utils/add-declaration-to-root-module.ts +12 -12
  88. package/src/schematics/mg-add/webModule/app.routes.ts +14 -14
  89. package/src/schematics/mg-add-tasks/index.d.ts +3 -3
  90. package/src/schematics/mg-add-tasks/index.js +29 -30
  91. package/src/schematics/mg-add-tasks/index.js.map +1 -1
  92. package/src/schematics/mg-add-tasks/index.ts +53 -53
  93. package/src/schematics/mg-add-tasks/schema.json +41 -41
  94. package/src/schematics/mg-delete-files/index.d.ts +3 -3
  95. package/src/schematics/mg-delete-files/index.js +12 -13
  96. package/src/schematics/mg-delete-files/index.js.map +1 -1
  97. package/src/schematics/mg-delete-files/index.ts +12 -12
  98. package/src/schematics/mg-delete-files/schema.json +14 -14
  99. package/src/schematics/mg-gen-module/index.d.ts +3 -3
  100. package/src/schematics/mg-gen-module/index.js +14 -15
  101. package/src/schematics/mg-gen-module/index.js.map +1 -1
  102. package/src/schematics/mg-gen-module/index.ts +14 -14
  103. package/src/schematics/mg-gen-module/schema.json +24 -24
  104. package/src/schematics/mg-generate/index.d.ts +3 -3
  105. package/src/schematics/mg-generate/index.js +12 -13
  106. package/src/schematics/mg-generate/index.js.map +1 -1
  107. package/src/schematics/mg-generate/index.ts +12 -12
  108. package/src/schematics/mg-generate/schema.json +34 -34
  109. package/src/schematics/mg-generate-component/index.d.ts +3 -3
  110. package/src/schematics/mg-generate-component/index.js +34 -35
  111. package/src/schematics/mg-generate-component/index.js.map +1 -1
  112. package/src/schematics/mg-install/index.d.ts +3 -3
  113. package/src/schematics/mg-install/index.js +29 -30
  114. package/src/schematics/mg-install/index.js.map +1 -1
  115. package/src/schematics/mg-install/index.ts +37 -37
  116. package/src/schematics/mg-install/schema.json +24 -24
  117. package/src/schematics/mg-routes/index.d.ts +6 -6
  118. package/src/schematics/mg-routes/index.js +62 -63
  119. package/src/schematics/mg-routes/index.js.map +1 -1
  120. package/src/schematics/mg-routes/schema.json +14 -14
  121. package/src/schematics/mg-single-control/index.d.ts +3 -3
  122. package/src/schematics/mg-single-control/index.js +28 -29
  123. package/src/schematics/mg-single-control/index.js.map +1 -1
  124. package/src/schematics/mg-single-control/schema.json +24 -24
  125. package/src/schematics/utils/ast.d.ts +21 -21
  126. package/src/schematics/utils/ast.js +90 -91
  127. package/src/schematics/utils/ast.js.map +1 -1
  128. package/src/schematics/utils/ast.ts +103 -103
  129. package/src/schematics/utils/devkit-utils/README.md +1 -1
  130. package/src/schematics/utils/devkit-utils/ast-utils.d.ts +87 -87
  131. package/src/schematics/utils/devkit-utils/ast-utils.js +489 -490
  132. package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
  133. package/src/schematics/utils/devkit-utils/ast-utils.ts +570 -570
  134. package/src/schematics/utils/devkit-utils/ast-utils_old.d.ts +68 -68
  135. package/src/schematics/utils/devkit-utils/ast-utils_old.js +419 -420
  136. package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
  137. package/src/schematics/utils/devkit-utils/ast-utils_old.ts +478 -478
  138. package/src/schematics/utils/devkit-utils/change.d.ts +66 -66
  139. package/src/schematics/utils/devkit-utils/change.js +94 -94
  140. package/src/schematics/utils/devkit-utils/change.js.map +1 -1
  141. package/src/schematics/utils/devkit-utils/change.ts +127 -127
  142. package/src/schematics/utils/devkit-utils/component.d.ts +2 -2
  143. package/src/schematics/utils/devkit-utils/component.js +96 -97
  144. package/src/schematics/utils/devkit-utils/component.js.map +1 -1
  145. package/src/schematics/utils/devkit-utils/component.ts +136 -136
  146. package/src/schematics/utils/devkit-utils/config.d.ts +78 -78
  147. package/src/schematics/utils/devkit-utils/config.js +52 -52
  148. package/src/schematics/utils/devkit-utils/config.js.map +1 -1
  149. package/src/schematics/utils/devkit-utils/config.ts +120 -120
  150. package/src/schematics/utils/devkit-utils/find-module.d.ts +28 -28
  151. package/src/schematics/utils/devkit-utils/find-module.js +92 -93
  152. package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
  153. package/src/schematics/utils/devkit-utils/find-module.ts +108 -108
  154. package/src/schematics/utils/devkit-utils/ng-ast-utils.d.ts +5 -5
  155. package/src/schematics/utils/devkit-utils/ng-ast-utils.js +73 -74
  156. package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
  157. package/src/schematics/utils/devkit-utils/ng-ast-utils.ts +84 -84
  158. package/src/schematics/utils/devkit-utils/parse-name.d.ts +13 -13
  159. package/src/schematics/utils/devkit-utils/parse-name.js +19 -20
  160. package/src/schematics/utils/devkit-utils/parse-name.js.map +1 -1
  161. package/src/schematics/utils/devkit-utils/parse-name.ts +24 -24
  162. package/src/schematics/utils/devkit-utils/route-utils.d.ts +20 -20
  163. package/src/schematics/utils/devkit-utils/route-utils.js +133 -134
  164. package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
  165. package/src/schematics/utils/devkit-utils/route-utils.ts +180 -180
  166. package/src/schematics/utils/devkit-utils/validation.d.ts +1 -1
  167. package/src/schematics/utils/devkit-utils/validation.js +18 -19
  168. package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
  169. package/src/schematics/utils/devkit-utils/validation.ts +16 -16
  170. package/src/schematics/utils/html.d.ts +18 -18
  171. package/src/schematics/utils/html.js +59 -60
  172. package/src/schematics/utils/html.js.map +1 -1
  173. package/src/schematics/utils/html.ts +63 -63
  174. package/src/schematics/utils/lib-versions.d.ts +3 -3
  175. package/src/schematics/utils/lib-versions.js +6 -6
  176. package/src/schematics/utils/lib-versions.js.map +1 -1
  177. package/src/schematics/utils/lib-versions.ts +3 -3
  178. package/src/schematics/utils/package.d.ts +5 -5
  179. package/src/schematics/utils/package.js +20 -21
  180. package/src/schematics/utils/package.js.map +1 -1
  181. package/src/schematics/utils/package.ts +22 -22
  182. package/src/schematics/utils/testing.d.ts +5 -5
  183. package/src/schematics/utils/testing.js +26 -27
  184. package/src/schematics/utils/testing.js.map +1 -1
  185. package/src/schematics/utils/testing.ts +25 -25
  186. package/src/types/enums/Enums.d.ts +1646 -1646
  187. package/src/types/enums/Enums.js +1862 -1862
  188. package/src/types/enums/Enums.js.map +1 -1
  189. package/src/types/enums/Enums.ts +2063 -2063
  190. package/src/types/enums/generated-file-types.enum.d.ts +6 -6
  191. package/src/types/enums/generated-file-types.enum.js +10 -10
  192. package/src/types/enums/generated-file-types.enum.js.map +1 -1
  193. package/src/types/enums/generated-file-types.enum.ts +6 -6
  194. package/src/types/enums/horizontal-alignments.enum.d.ts +5 -5
  195. package/src/types/enums/horizontal-alignments.enum.js +9 -9
  196. package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
  197. package/src/types/enums/horizontal-alignments.enum.ts +6 -6
  198. package/src/types/enums/themes.enum.d.ts +6 -6
  199. package/src/types/enums/themes.enum.js +10 -10
  200. package/src/types/enums/themes.enum.js.map +1 -1
  201. package/src/types/enums/themes.enum.ts +6 -6
  202. package/src/types/index.d.ts +7 -7
  203. package/src/types/index.js +10 -10
  204. package/src/types/index.js.map +1 -1
  205. package/src/types/index.ts +8 -8
  206. package/src/types/interfaces/app.d.ts +53 -53
  207. package/src/types/interfaces/app.js +9 -9
  208. package/src/types/interfaces/app.js.map +1 -1
  209. package/src/types/interfaces/app.ts +89 -89
  210. package/src/types/interfaces/control.d.ts +82 -82
  211. package/src/types/interfaces/control.js +2 -2
  212. package/src/types/interfaces/control.js.map +1 -1
  213. package/src/types/interfaces/control.ts +106 -106
  214. package/src/types/interfaces/env.interface.d.ts +19 -19
  215. package/src/types/interfaces/env.interface.js +10 -10
  216. package/src/types/interfaces/template.config.d.ts +8 -8
  217. package/src/types/interfaces/template.config.js +2 -2
  218. package/src/types/interfaces/template.config.js.map +1 -1
  219. package/src/types/interfaces/template.config.ts +11 -11
  220. package/templates/angular/src/app/app.component.html.ejs +17 -17
  221. package/templates/angular/src/app/cmp-array.ejs +3 -3
  222. package/templates/angular/src/app/cmp-hash.ejs +3 -3
  223. package/templates/angular/src/app/component-list.g.ts +21 -21
  224. package/templates/angular/src/app.component.ts +14 -14
  225. package/templates/angular/src/app.module.ts +70 -70
  226. package/templates/angular/src/app.routes.ts +73 -73
  227. package/templates/angular/src/styles/app.css +5 -5
  228. package/templates/attributes/button_attributes.ejs +2 -2
  229. package/templates/attributes/common/base/class.ejs +6 -6
  230. package/templates/attributes/common/base/control_type.ejs +53 -53
  231. package/templates/attributes/common/base/enabled.ejs +9 -9
  232. package/templates/attributes/common/base/imageFileName.ejs +3 -3
  233. package/templates/attributes/common/base/no_control_class.ejs +3 -3
  234. package/templates/attributes/common/base/rtol.ejs +3 -3
  235. package/templates/attributes/common/base/tabindex.ejs +11 -11
  236. package/templates/attributes/common/base/testingId.ejs +8 -8
  237. package/templates/attributes/common/base/tooltip.ejs +7 -7
  238. package/templates/attributes/common/base/visible.ejs +6 -6
  239. package/templates/attributes/common/base/wallpaper.ejs +3 -3
  240. package/templates/attributes/common/base_attributes.ejs +10 -10
  241. package/templates/attributes/common/container_attributes.ejs +6 -6
  242. package/templates/attributes/common/control_attributes.ejs +3 -3
  243. package/templates/attributes/common/format.ejs +5 -5
  244. package/templates/attributes/common/input/hint.ejs +13 -13
  245. package/templates/attributes/common/input/multiline_edit.ejs +3 -3
  246. package/templates/attributes/common/input/must_input.ejs +8 -8
  247. package/templates/attributes/common/input/password_edit.ejs +7 -7
  248. package/templates/attributes/common/input/row_editing_input_attributes.ejs +6 -6
  249. package/templates/attributes/common/input/validation.ejs +5 -5
  250. package/templates/attributes/common/input_attributes.ejs +4 -4
  251. package/templates/attributes/common/no_control_base_attributes.ejs +4 -4
  252. package/templates/attributes/common/row_editing_button_attributes.ejs +10 -10
  253. package/templates/component/view.component.html +14 -14
  254. package/templates/component/view.component.ts +123 -122
  255. package/templates/themes/basicHTML/Code/theme.module.ts +10 -10
  256. package/templates/themes/basicHTML/checkbox.ejs +1 -1
  257. package/templates/themes/basicHTML/combobox.ejs +37 -37
  258. package/templates/themes/basicHTML/edit.ejs +169 -169
  259. package/templates/themes/basicHTML/form.ejs +4 -4
  260. package/templates/themes/basicHTML/group.ejs +4 -4
  261. package/templates/themes/basicHTML/image.ejs +6 -6
  262. package/templates/themes/basicHTML/label.ejs +11 -11
  263. package/templates/themes/basicHTML/listbox.ejs +21 -21
  264. package/templates/themes/basicHTML/push-button.ejs +28 -28
  265. package/templates/themes/basicHTML/radio.ejs +20 -20
  266. package/templates/themes/basicHTML/subform.ejs +6 -6
  267. package/templates/themes/basicHTML/tab.ejs +31 -31
  268. package/templates/themes/basicHTML/tabpage.ejs +5 -5
  269. package/templates/themes/basicHiddenHTML/Code/theme.module.ts +10 -10
  270. package/templates/themes/basicHiddenHTML/combobox.ejs +5 -5
  271. package/templates/themes/basicHiddenHTML/form.ejs +3 -3
  272. package/templates/themes/basicHiddenHTML/group.ejs +2 -2
  273. package/templates/themes/basicHiddenHTML/image.ejs +4 -4
  274. package/templates/themes/basicHiddenHTML/label.ejs +1 -1
  275. package/templates/themes/basicHiddenHTML/listbox.ejs +8 -8
  276. package/templates/themes/basicHiddenHTML/push-button.ejs +26 -26
  277. package/templates/themes/basicHiddenHTML/radio.ejs +17 -17
  278. package/templates/themes/basicHiddenHTML/tab.ejs +13 -13
  279. package/templates/themes/basicHiddenHTML/table.ejs +18 -18
  280. package/templates/themes/basicHiddenHTML/tabpage.ejs +2 -2
  281. package/templates/themes/container.ejs +26 -26
  282. package/templates/themes/control.ejs +52 -52
  283. package/templates/themes/editTypeSelector.ejs +1 -1
  284. package/templates/themes/material/Code/theme.module.ts +68 -68
  285. package/templates/themes/material/base_attributes_date.ejs +8 -8
  286. package/templates/themes/material/checkbox.ejs +1 -1
  287. package/templates/themes/material/combobox.ejs +43 -43
  288. package/templates/themes/material/edit.ejs +204 -204
  289. package/templates/themes/material/group.ejs +3 -3
  290. package/templates/themes/material/listbox.ejs +22 -23
  291. package/templates/themes/material/push-button.ejs +28 -28
  292. package/templates/themes/material/radio.ejs +22 -22
  293. package/templates/themes/material/subform.ejs +8 -8
  294. package/templates/themes/material/tab.ejs +19 -19
  295. package/templates/themes/router_outlet.ejs +5 -5
  296. package/templates/themes/table/HTMLTable/columnHeader.ejs +3 -1
  297. package/templates/themes/table/HTMLTable/table.ejs +37 -37
  298. package/templates/themes/table/grid/additionalComponentCode.ejs +26 -26
  299. package/templates/themes/table/grid/additionalIncludes.ejs +1 -1
  300. package/templates/themes/table/grid/column.ejs +3 -1
  301. package/templates/themes/table/grid/table.ejs +37 -37
  302. package/templates/themes/table/repeatable/column.ejs +11 -11
  303. package/templates/themes/table/repeatable/table.ejs +28 -28
  304. package/templates/themes/tableTypeSelector.ejs +21 -21
  305. package/tsconfig.json +36 -36
@@ -1,180 +1,180 @@
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 * as ts from 'typescript';
9
- import { findNode, findNodes, insertAfterLastOccurrence } from "./ast-utils";
10
- import { Change, InsertChange, NoopChange } from "./change";
11
- import {SchematicsException, Tree} from "@angular-devkit/schematics";
12
-
13
-
14
- /**
15
- * Add Import `import { symbolName } from fileName` if the import doesn't exit
16
- * already. Assumes fileToEdit can be resolved and accessed.
17
- * @param fileToEdit (file we want to add import to)
18
- * @param symbolName (item to import)
19
- * @param fileName (path to the file)
20
- * @param isDefault (if true, import follows style for importing default exports)
21
- * @return Change
22
- */
23
-
24
- export function insertImport2(
25
- source : ts.SourceFile,
26
- fileToEdit : string,
27
- symbolName : string,
28
- asSymbolName: string,
29
- fileName : string,
30
- isDefault = false): Change {
31
- const rootNode = source;
32
- const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
33
-
34
- // get nodes that map to import statements from the file fileName
35
- const relevantImports = allImports.filter(node => {
36
- // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
37
- const importFiles = node.getChildren()
38
- .filter(child => child.kind === ts.SyntaxKind.StringLiteral)
39
- .map(n => (n as ts.StringLiteral).text);
40
-
41
- return importFiles.filter(file => file === fileName).length === 1;
42
- });
43
-
44
- if (relevantImports.length > 0) {
45
- let importsAsterisk = false;
46
- // imports from import file
47
- const imports: ts.Node[] = [];
48
- relevantImports.forEach(n => {
49
- Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
50
- if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
51
- importsAsterisk = true;
52
- }
53
- });
54
-
55
- // if imports * from fileName, don't add symbolName
56
- if (importsAsterisk) {
57
- return new NoopChange();
58
- }
59
-
60
- const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
61
-
62
- // insert import if it's not there
63
- if (importTextNodes.length === 0) {
64
- const fallbackPos =
65
- findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
66
- findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
67
-
68
- return insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);
69
- }
70
-
71
- return new NoopChange();
72
- }
73
-
74
- // no such import declaration exists
75
- const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
76
- .filter((n: ts.StringLiteral) => n.text === 'use strict');
77
- let fallbackPos = 0;
78
- if (useStrict.length > 0) {
79
- fallbackPos = useStrict[0].end;
80
- }
81
- const open = isDefault ? '' : '{ ';
82
- const close = isDefault ? '' : ' }';
83
- // if there are no imports or 'use strict' statement, insert import at beginning of file
84
- const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
85
- const separator = insertAtBeginning ? '' : ';\n';
86
- const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +
87
- ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
88
-
89
- return insertAfterLastOccurrence(
90
- allImports,
91
- toInsert,
92
- fileToEdit,
93
- fallbackPos,
94
- ts.SyntaxKind.StringLiteral,
95
- );
96
- }
97
-
98
-
99
- export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string,
100
- fileName: string, isDefault = false): Change {
101
- const rootNode = source;
102
- const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
103
-
104
- // get nodes that map to import statements from the file fileName
105
- const relevantImports = allImports.filter(node => {
106
- // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
107
- const importFiles = node.getChildren()
108
- .filter(child => child.kind === ts.SyntaxKind.StringLiteral)
109
- .map(n => (n as ts.StringLiteral).text);
110
-
111
- return importFiles.filter(file => file === fileName).length === 1;
112
- });
113
-
114
- if (relevantImports.length > 0) {
115
- let importsAsterisk = false;
116
- // imports from import file
117
- const imports: ts.Node[] = [];
118
- relevantImports.forEach(n => {
119
- Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
120
- if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
121
- importsAsterisk = true;
122
- }
123
- });
124
-
125
- // if imports * from fileName, don't add symbolName
126
- if (importsAsterisk) {
127
- return new NoopChange();
128
- }
129
-
130
- const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
131
-
132
- // insert import if it's not there
133
- if (importTextNodes.length === 0) {
134
- const fallbackPos =
135
- findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
136
- findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
137
-
138
- return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
139
- }
140
-
141
- return new NoopChange();
142
- }
143
-
144
- // no such import declaration exists
145
- const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
146
- .filter((n: ts.StringLiteral) => n.text === 'use strict');
147
- let fallbackPos = 0;
148
- if (useStrict.length > 0) {
149
- fallbackPos = useStrict[0].end;
150
- }
151
- const open = isDefault ? '' : '{ ';
152
- const close = isDefault ? '' : ' }';
153
- // if there are no imports or 'use strict' statement, insert import at beginning of file
154
- const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
155
- const separator = insertAtBeginning ? '' : ';\n';
156
- const toInsert = `${separator}import ${open}${symbolName}${close}` +
157
- ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
158
-
159
- return insertAfterLastOccurrence(
160
- allImports,
161
- toInsert,
162
- fileToEdit,
163
- fallbackPos,
164
- ts.SyntaxKind.StringLiteral,
165
- );
166
- }
167
-
168
-
169
-
170
- function getSourceFile(host: Tree, path: string): ts.SourceFile {
171
- const buffer = host.read(path);
172
- if (!buffer) {
173
- throw new SchematicsException(`Could not find ${path}.`);
174
- }
175
- const content = buffer.toString();
176
- const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
177
-
178
- return source;
179
- }
180
-
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 * as ts from 'typescript';
9
+ import { findNode, findNodes, insertAfterLastOccurrence } from "./ast-utils";
10
+ import { Change, InsertChange, NoopChange } from "./change";
11
+ import {SchematicsException, Tree} from "@angular-devkit/schematics";
12
+
13
+
14
+ /**
15
+ * Add Import `import { symbolName } from fileName` if the import doesn't exit
16
+ * already. Assumes fileToEdit can be resolved and accessed.
17
+ * @param fileToEdit (file we want to add import to)
18
+ * @param symbolName (item to import)
19
+ * @param fileName (path to the file)
20
+ * @param isDefault (if true, import follows style for importing default exports)
21
+ * @return Change
22
+ */
23
+
24
+ export function insertImport2(
25
+ source : ts.SourceFile,
26
+ fileToEdit : string,
27
+ symbolName : string,
28
+ asSymbolName: string,
29
+ fileName : string,
30
+ isDefault = false): Change {
31
+ const rootNode = source;
32
+ const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
33
+
34
+ // get nodes that map to import statements from the file fileName
35
+ const relevantImports = allImports.filter(node => {
36
+ // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
37
+ const importFiles = node.getChildren()
38
+ .filter(child => child.kind === ts.SyntaxKind.StringLiteral)
39
+ .map(n => (n as ts.StringLiteral).text);
40
+
41
+ return importFiles.filter(file => file === fileName).length === 1;
42
+ });
43
+
44
+ if (relevantImports.length > 0) {
45
+ let importsAsterisk = false;
46
+ // imports from import file
47
+ const imports: ts.Node[] = [];
48
+ relevantImports.forEach(n => {
49
+ Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
50
+ if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
51
+ importsAsterisk = true;
52
+ }
53
+ });
54
+
55
+ // if imports * from fileName, don't add symbolName
56
+ if (importsAsterisk) {
57
+ return new NoopChange();
58
+ }
59
+
60
+ const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
61
+
62
+ // insert import if it's not there
63
+ if (importTextNodes.length === 0) {
64
+ const fallbackPos =
65
+ findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
66
+ findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
67
+
68
+ return insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);
69
+ }
70
+
71
+ return new NoopChange();
72
+ }
73
+
74
+ // no such import declaration exists
75
+ const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
76
+ .filter((n: ts.StringLiteral) => n.text === 'use strict');
77
+ let fallbackPos = 0;
78
+ if (useStrict.length > 0) {
79
+ fallbackPos = useStrict[0].end;
80
+ }
81
+ const open = isDefault ? '' : '{ ';
82
+ const close = isDefault ? '' : ' }';
83
+ // if there are no imports or 'use strict' statement, insert import at beginning of file
84
+ const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
85
+ const separator = insertAtBeginning ? '' : ';\n';
86
+ const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +
87
+ ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
88
+
89
+ return insertAfterLastOccurrence(
90
+ allImports,
91
+ toInsert,
92
+ fileToEdit,
93
+ fallbackPos,
94
+ ts.SyntaxKind.StringLiteral,
95
+ );
96
+ }
97
+
98
+
99
+ export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string,
100
+ fileName: string, isDefault = false): Change {
101
+ const rootNode = source;
102
+ const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
103
+
104
+ // get nodes that map to import statements from the file fileName
105
+ const relevantImports = allImports.filter(node => {
106
+ // StringLiteral of the ImportDeclaration is the import file (fileName in this case).
107
+ const importFiles = node.getChildren()
108
+ .filter(child => child.kind === ts.SyntaxKind.StringLiteral)
109
+ .map(n => (n as ts.StringLiteral).text);
110
+
111
+ return importFiles.filter(file => file === fileName).length === 1;
112
+ });
113
+
114
+ if (relevantImports.length > 0) {
115
+ let importsAsterisk = false;
116
+ // imports from import file
117
+ const imports: ts.Node[] = [];
118
+ relevantImports.forEach(n => {
119
+ Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
120
+ if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
121
+ importsAsterisk = true;
122
+ }
123
+ });
124
+
125
+ // if imports * from fileName, don't add symbolName
126
+ if (importsAsterisk) {
127
+ return new NoopChange();
128
+ }
129
+
130
+ const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
131
+
132
+ // insert import if it's not there
133
+ if (importTextNodes.length === 0) {
134
+ const fallbackPos =
135
+ findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
136
+ findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
137
+
138
+ return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
139
+ }
140
+
141
+ return new NoopChange();
142
+ }
143
+
144
+ // no such import declaration exists
145
+ const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
146
+ .filter((n: ts.StringLiteral) => n.text === 'use strict');
147
+ let fallbackPos = 0;
148
+ if (useStrict.length > 0) {
149
+ fallbackPos = useStrict[0].end;
150
+ }
151
+ const open = isDefault ? '' : '{ ';
152
+ const close = isDefault ? '' : ' }';
153
+ // if there are no imports or 'use strict' statement, insert import at beginning of file
154
+ const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
155
+ const separator = insertAtBeginning ? '' : ';\n';
156
+ const toInsert = `${separator}import ${open}${symbolName}${close}` +
157
+ ` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
158
+
159
+ return insertAfterLastOccurrence(
160
+ allImports,
161
+ toInsert,
162
+ fileToEdit,
163
+ fallbackPos,
164
+ ts.SyntaxKind.StringLiteral,
165
+ );
166
+ }
167
+
168
+
169
+
170
+ function getSourceFile(host: Tree, path: string): ts.SourceFile {
171
+ const buffer = host.read(path);
172
+ if (!buffer) {
173
+ throw new SchematicsException(`Could not find ${path}.`);
174
+ }
175
+ const content = buffer.toString();
176
+ const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
177
+
178
+ return source;
179
+ }
180
+
@@ -1 +1 @@
1
- export declare function validateName(name: string): void;
1
+ export declare function validateName(name: string): void;
@@ -1,20 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateName = 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
- function validateName(name) {
14
- if (name && /^\d/.test(name)) {
15
- throw new schematics_1.SchematicsException(core_1.tags.oneLine `name (${name})
16
- can not start with a digit.`);
17
- }
18
- }
19
- exports.validateName = validateName;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateName = validateName;
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
+ function validateName(name) {
14
+ if (name && /^\d/.test(name)) {
15
+ throw new schematics_1.SchematicsException(core_1.tags.oneLine `name (${name})
16
+ can not start with a digit.`);
17
+ }
18
+ }
20
19
  //# sourceMappingURL=validation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["validation.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+CAA4C;AAC5C,2DAAiE;AAEjE,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC5B,MAAM,IAAI,gCAAmB,CAAC,WAAI,CAAC,OAAO,CAAA,SAAS,IAAI;oCACvB,CAAC,CAAC;KACnC;AACH,CAAC;AALD,oCAKC","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 { tags } from '@angular-devkit/core';\r\nimport { SchematicsException } from '@angular-devkit/schematics';\r\n\r\nexport function validateName(name: string): void {\r\n if (name && /^\\d/.test(name)) {\r\n throw new SchematicsException(tags.oneLine`name (${name})\r\n can not start with a digit.`);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["validation.ts"],"names":[],"mappings":";;AAUA,oCAKC;AAfD;;;;;;GAMG;AACH,+CAA4C;AAC5C,2DAAiE;AAEjE,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,gCAAmB,CAAC,WAAI,CAAC,OAAO,CAAA,SAAS,IAAI;oCACvB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","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 { tags } from '@angular-devkit/core';\nimport { SchematicsException } from '@angular-devkit/schematics';\n\nexport function validateName(name: string): void {\n if (name && /^\\d/.test(name)) {\n throw new SchematicsException(tags.oneLine`name (${name})\n can not start with a digit.`);\n }\n}\n"]}
@@ -1,16 +1,16 @@
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 { tags } from '@angular-devkit/core';
9
- import { SchematicsException } from '@angular-devkit/schematics';
10
-
11
- export function validateName(name: string): void {
12
- if (name && /^\d/.test(name)) {
13
- throw new SchematicsException(tags.oneLine`name (${name})
14
- can not start with a digit.`);
15
- }
16
- }
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 { tags } from '@angular-devkit/core';
9
+ import { SchematicsException } from '@angular-devkit/schematics';
10
+
11
+ export function validateName(name: string): void {
12
+ if (name && /^\d/.test(name)) {
13
+ throw new SchematicsException(tags.oneLine`name (${name})
14
+ can not start with a digit.`);
15
+ }
16
+ }
@@ -1,18 +1,18 @@
1
- import { Tree } from '@angular-devkit/schematics';
2
- import { Project } from './devkit-utils/config';
3
- /**
4
- * Parses the index.html file to get the HEAD tag position.
5
- * @param host the tree we are traversing
6
- * @param src the src path of the html file to parse
7
- */
8
- export declare function getHeadTag(host: Tree, src: string): {
9
- position: any;
10
- };
11
- /**
12
- * Adds a link to the index.html head tag Example:
13
- * `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
14
- * @param host The tree we are updating
15
- * @param project The project we're targeting.
16
- * @param link html element string we are inserting.
17
- */
18
- export declare function addHeadLink(host: Tree, project: Project, link: string): void;
1
+ import { Tree } from '@angular-devkit/schematics';
2
+ import { Project } from './devkit-utils/config';
3
+ /**
4
+ * Parses the index.html file to get the HEAD tag position.
5
+ * @param host the tree we are traversing
6
+ * @param src the src path of the html file to parse
7
+ */
8
+ export declare function getHeadTag(host: Tree, src: string): {
9
+ position: any;
10
+ };
11
+ /**
12
+ * Adds a link to the index.html head tag Example:
13
+ * `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
14
+ * @param host The tree we are updating
15
+ * @param project The project we're targeting.
16
+ * @param link html element string we are inserting.
17
+ */
18
+ export declare function addHeadLink(host: Tree, project: Project, link: string): void;
@@ -1,61 +1,60 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addHeadLink = exports.getHeadTag = void 0;
4
- const schematics_1 = require("@angular-devkit/schematics");
5
- const parse5 = require("parse5");
6
- const ast_1 = require("./ast");
7
- const change_1 = require("./devkit-utils/change");
8
- /**
9
- * Parses the index.html file to get the HEAD tag position.
10
- * @param host the tree we are traversing
11
- * @param src the src path of the html file to parse
12
- */
13
- function getHeadTag(host, src) {
14
- const document = parse5.parse(src, { locationInfo: true });
15
- let head;
16
- const visit = (nodes) => {
17
- nodes.forEach(node => {
18
- const element = node;
19
- if (element.tagName === 'head') {
20
- head = element;
21
- }
22
- else {
23
- if (element.childNodes) {
24
- visit(element.childNodes);
25
- }
26
- }
27
- });
28
- };
29
- visit(document.childNodes);
30
- if (!head) {
31
- throw new schematics_1.SchematicsException('Head element not found!');
32
- }
33
- return {
34
- position: head.__location.startTag.endOffset
35
- };
36
- }
37
- exports.getHeadTag = getHeadTag;
38
- /**
39
- * Adds a link to the index.html head tag Example:
40
- * `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
41
- * @param host The tree we are updating
42
- * @param project The project we're targeting.
43
- * @param link html element string we are inserting.
44
- */
45
- function addHeadLink(host, project, link) {
46
- const indexPath = (0, ast_1.getIndexHtmlPath)(host, project);
47
- const buffer = host.read(indexPath);
48
- if (!buffer) {
49
- throw new schematics_1.SchematicsException(`Could not find file for path: ${indexPath}`);
50
- }
51
- const src = buffer.toString();
52
- if (src.indexOf(link) === -1) {
53
- const node = getHeadTag(host, src);
54
- const insertion = new change_1.InsertChange(indexPath, node.position, link);
55
- const recorder = host.beginUpdate(indexPath);
56
- recorder.insertLeft(insertion.pos, insertion.toAdd);
57
- host.commitUpdate(recorder);
58
- }
59
- }
60
- exports.addHeadLink = addHeadLink;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHeadTag = getHeadTag;
4
+ exports.addHeadLink = addHeadLink;
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const parse5 = require("parse5");
7
+ const ast_1 = require("./ast");
8
+ const change_1 = require("./devkit-utils/change");
9
+ /**
10
+ * Parses the index.html file to get the HEAD tag position.
11
+ * @param host the tree we are traversing
12
+ * @param src the src path of the html file to parse
13
+ */
14
+ function getHeadTag(host, src) {
15
+ const document = parse5.parse(src, { locationInfo: true });
16
+ let head;
17
+ const visit = (nodes) => {
18
+ nodes.forEach(node => {
19
+ const element = node;
20
+ if (element.tagName === 'head') {
21
+ head = element;
22
+ }
23
+ else {
24
+ if (element.childNodes) {
25
+ visit(element.childNodes);
26
+ }
27
+ }
28
+ });
29
+ };
30
+ visit(document.childNodes);
31
+ if (!head) {
32
+ throw new schematics_1.SchematicsException('Head element not found!');
33
+ }
34
+ return {
35
+ position: head.__location.startTag.endOffset
36
+ };
37
+ }
38
+ /**
39
+ * Adds a link to the index.html head tag Example:
40
+ * `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
41
+ * @param host The tree we are updating
42
+ * @param project The project we're targeting.
43
+ * @param link html element string we are inserting.
44
+ */
45
+ function addHeadLink(host, project, link) {
46
+ const indexPath = (0, ast_1.getIndexHtmlPath)(host, project);
47
+ const buffer = host.read(indexPath);
48
+ if (!buffer) {
49
+ throw new schematics_1.SchematicsException(`Could not find file for path: ${indexPath}`);
50
+ }
51
+ const src = buffer.toString();
52
+ if (src.indexOf(link) === -1) {
53
+ const node = getHeadTag(host, src);
54
+ const insertion = new change_1.InsertChange(indexPath, node.position, link);
55
+ const recorder = host.beginUpdate(indexPath);
56
+ recorder.insertLeft(insertion.pos, insertion.toAdd);
57
+ host.commitUpdate(recorder);
58
+ }
59
+ }
61
60
  //# sourceMappingURL=html.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"html.js","sourceRoot":"","sources":["html.ts"],"names":[],"mappings":";;;AAAA,2DAAqE;AACrE,iCAAiC;AACjC,+BAAuC;AACvC,kDAAmD;AAGnD;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAU,EAAE,GAAW;IAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAC/B,EAAC,YAAY,EAAE,IAAI,EAAC,CAAgC,CAAC;IAEvD,IAAI,IAAI,CAAC;IACT,MAAM,KAAK,GAAG,CAAC,KAAgC,EAAE,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACnB,MAAM,OAAO,GAA+B,IAAI,CAAC;YACjD,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,EAAE;gBAC9B,IAAI,GAAG,OAAO,CAAC;aAChB;iBAAM;gBACL,IAAI,OAAO,CAAC,UAAU,EAAE;oBACtB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;iBAC3B;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3B,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,gCAAmB,CAAC,yBAAyB,CAAC,CAAC;KAC1D;IAED,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS;KAC7C,CAAC;AACJ,CAAC;AA3BD,gCA2BC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,IAAU,EAAE,OAAgB,EAAE,IAAY;IACpE,MAAM,SAAS,GAAG,IAAA,sBAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,gCAAmB,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;KAC7E;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;QAC5B,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACnC,MAAM,SAAS,GAAG,IAAI,qBAAY,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC7C,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;KAC7B;AACH,CAAC;AAfD,kCAeC","sourcesContent":["import {Tree, SchematicsException} from '@angular-devkit/schematics';\r\nimport * as parse5 from 'parse5';\r\nimport {getIndexHtmlPath} from './ast';\r\nimport {InsertChange} from './devkit-utils/change';\r\nimport {Project} from './devkit-utils/config';\r\n\r\n/**\r\n * Parses the index.html file to get the HEAD tag position.\r\n * @param host the tree we are traversing\r\n * @param src the src path of the html file to parse\r\n */\r\nexport function getHeadTag(host: Tree, src: string) {\r\n const document = parse5.parse(src,\r\n {locationInfo: true}) as parse5.AST.Default.Document;\r\n\r\n let head;\r\n const visit = (nodes: parse5.AST.Default.Node[]) => {\r\n nodes.forEach(node => {\r\n const element = <parse5.AST.Default.Element>node;\r\n if (element.tagName === 'head') {\r\n head = element;\r\n } else {\r\n if (element.childNodes) {\r\n visit(element.childNodes);\r\n }\r\n }\r\n });\r\n };\r\n\r\n visit(document.childNodes);\r\n\r\n if (!head) {\r\n throw new SchematicsException('Head element not found!');\r\n }\r\n\r\n return {\r\n position: head.__location.startTag.endOffset\r\n };\r\n}\r\n\r\n/**\r\n * Adds a link to the index.html head tag Example:\r\n * `<link href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" rel=\"stylesheet\">`\r\n * @param host The tree we are updating\r\n * @param project The project we're targeting.\r\n * @param link html element string we are inserting.\r\n */\r\nexport function addHeadLink(host: Tree, project: Project, link: string) {\r\n const indexPath = getIndexHtmlPath(host, project);\r\n const buffer = host.read(indexPath);\r\n if (!buffer) {\r\n throw new SchematicsException(`Could not find file for path: ${indexPath}`);\r\n }\r\n\r\n const src = buffer.toString();\r\n if (src.indexOf(link) === -1) {\r\n const node = getHeadTag(host, src);\r\n const insertion = new InsertChange(indexPath, node.position, link);\r\n const recorder = host.beginUpdate(indexPath);\r\n recorder.insertLeft(insertion.pos, insertion.toAdd);\r\n host.commitUpdate(recorder);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"html.js","sourceRoot":"","sources":["html.ts"],"names":[],"mappings":";;AAWA,gCA2BC;AASD,kCAeC;AA9DD,2DAAqE;AACrE,iCAAiC;AACjC,+BAAuC;AACvC,kDAAmD;AAGnD;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAU,EAAE,GAAW;IAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAC/B,EAAC,YAAY,EAAE,IAAI,EAAC,CAAgC,CAAC;IAEvD,IAAI,IAAI,CAAC;IACT,MAAM,KAAK,GAAG,CAAC,KAAgC,EAAE,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACnB,MAAM,OAAO,GAA+B,IAAI,CAAC;YACjD,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;gBAC/B,IAAI,GAAG,OAAO,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACN,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;oBACvB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,gCAAmB,CAAC,yBAAyB,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS;KAC7C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,IAAU,EAAE,OAAgB,EAAE,IAAY;IACpE,MAAM,SAAS,GAAG,IAAA,sBAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,gCAAmB,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACnC,MAAM,SAAS,GAAG,IAAI,qBAAY,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC7C,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC","sourcesContent":["import {Tree, SchematicsException} from '@angular-devkit/schematics';\nimport * as parse5 from 'parse5';\nimport {getIndexHtmlPath} from './ast';\nimport {InsertChange} from './devkit-utils/change';\nimport {Project} from './devkit-utils/config';\n\n/**\n * Parses the index.html file to get the HEAD tag position.\n * @param host the tree we are traversing\n * @param src the src path of the html file to parse\n */\nexport function getHeadTag(host: Tree, src: string) {\n const document = parse5.parse(src,\n {locationInfo: true}) as parse5.AST.Default.Document;\n\n let head;\n const visit = (nodes: parse5.AST.Default.Node[]) => {\n nodes.forEach(node => {\n const element = <parse5.AST.Default.Element>node;\n if (element.tagName === 'head') {\n head = element;\n } else {\n if (element.childNodes) {\n visit(element.childNodes);\n }\n }\n });\n };\n\n visit(document.childNodes);\n\n if (!head) {\n throw new SchematicsException('Head element not found!');\n }\n\n return {\n position: head.__location.startTag.endOffset\n };\n}\n\n/**\n * Adds a link to the index.html head tag Example:\n * `<link href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" rel=\"stylesheet\">`\n * @param host The tree we are updating\n * @param project The project we're targeting.\n * @param link html element string we are inserting.\n */\nexport function addHeadLink(host: Tree, project: Project, link: string) {\n const indexPath = getIndexHtmlPath(host, project);\n const buffer = host.read(indexPath);\n if (!buffer) {\n throw new SchematicsException(`Could not find file for path: ${indexPath}`);\n }\n\n const src = buffer.toString();\n if (src.indexOf(link) === -1) {\n const node = getHeadTag(host, src);\n const insertion = new InsertChange(indexPath, node.position, link);\n const recorder = host.beginUpdate(indexPath);\n recorder.insertLeft(insertion.pos, insertion.toAdd);\n host.commitUpdate(recorder);\n }\n}\n"]}