@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.
- package/README.md +28 -28
- package/index.d.ts +1 -1
- package/index.js +4 -4
- package/index.js.map +1 -1
- package/index.ts +1 -1
- package/package.json +2 -2
- package/src/collection.json +75 -75
- package/src/public_api.d.ts +3 -3
- package/src/public_api.js +6 -6
- package/src/public_api.js.map +1 -1
- package/src/public_api.ts +5 -5
- package/src/schematics/magic-utils/Util.d.ts +6 -6
- package/src/schematics/magic-utils/Util.js +26 -26
- package/src/schematics/magic-utils/Util.js.map +1 -1
- package/src/schematics/magic-utils/config.d.ts +12 -12
- package/src/schematics/magic-utils/config.js +56 -56
- package/src/schematics/magic-utils/config.js.map +1 -1
- package/src/schematics/magic-utils/config.ts +68 -68
- package/src/schematics/magic-utils/env.d.ts +23 -23
- package/src/schematics/magic-utils/env.js +39 -39
- package/src/schematics/magic-utils/env.js.map +1 -1
- package/src/schematics/magic-utils/env.ts +50 -50
- package/src/schematics/magic-utils/manifest.d.ts +11 -11
- package/src/schematics/magic-utils/manifest.js +40 -40
- package/src/schematics/magic-utils/manifest.js.map +1 -1
- package/src/schematics/magic-utils/manifest.ts +46 -46
- package/src/schematics/magic-utils/metadata.class.d.ts +51 -51
- package/src/schematics/magic-utils/metadata.class.js +124 -124
- package/src/schematics/magic-utils/metadata.class.js.map +1 -1
- package/src/schematics/magic-utils/metadata.class.ts +159 -159
- package/src/schematics/magic-utils/process-json.d.ts +2 -2
- package/src/schematics/magic-utils/process-json.js +157 -158
- package/src/schematics/magic-utils/process-json.js.map +1 -1
- package/src/schematics/magic-utils/rules/build-control.rule.d.ts +5 -5
- package/src/schematics/magic-utils/rules/build-control.rule.js +73 -74
- package/src/schematics/magic-utils/rules/build-control.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/build-view.rule.d.ts +3 -3
- package/src/schematics/magic-utils/rules/build-view.rule.js +82 -80
- package/src/schematics/magic-utils/rules/build-view.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/build-view.rule.ts +4 -0
- package/src/schematics/magic-utils/rules/component-list.rule.d.ts +3 -3
- package/src/schematics/magic-utils/rules/component-list.rule.js +316 -317
- package/src/schematics/magic-utils/rules/component-list.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/generate.rule.d.ts +5 -5
- package/src/schematics/magic-utils/rules/generate.rule.js +53 -54
- package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/generate.rule.ts +61 -61
- package/src/schematics/magic-utils/rules/init-add-modules.rule.d.ts +12 -12
- package/src/schematics/magic-utils/rules/init-add-modules.rule.js +295 -296
- package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +360 -360
- package/src/schematics/magic-utils/rules/init-gen-components.rule.d.ts +4 -4
- package/src/schematics/magic-utils/rules/init-gen-components.rule.js +65 -66
- package/src/schematics/magic-utils/rules/init-gen-components.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-magic-metadata.rule.d.ts +3 -3
- package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js +17 -18
- package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-magic-metadata.rule.ts +19 -19
- package/src/schematics/magic-utils/rules/load-views-gen.rule.d.ts +3 -3
- package/src/schematics/magic-utils/rules/load-views-gen.rule.js +28 -29
- package/src/schematics/magic-utils/rules/load-views-gen.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/magic-option.scheme.d.ts +22 -21
- package/src/schematics/magic-utils/rules/magic-option.scheme.js +2 -2
- package/src/schematics/magic-utils/rules/magic-option.scheme.js.map +1 -1
- package/src/schematics/magic-utils/rules/magic-option.scheme.ts +24 -23
- package/src/schematics/magic-utils/utils.d.ts +12 -12
- package/src/schematics/magic-utils/utils.js +116 -117
- package/src/schematics/magic-utils/utils.js.map +1 -1
- package/src/schematics/magic-utils/utils.ts +134 -134
- package/src/schematics/mg-Install-prerequisites/index.d.ts +3 -3
- package/src/schematics/mg-Install-prerequisites/index.js +24 -25
- package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
- package/src/schematics/mg-Install-prerequisites/index.ts +30 -30
- package/src/schematics/mg-Install-prerequisites/schema.json +14 -14
- package/src/schematics/mg-add/files/src/app/app.component.html +17 -17
- package/src/schematics/mg-add/files/src/app/app.routes.ts +14 -14
- package/src/schematics/mg-add/files/src/app/magic/component-list.g.ts +9 -9
- package/src/schematics/mg-add/files/src/app/magic/lazy-loader.service.ts +2 -1
- package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +19 -19
- package/src/schematics/mg-add/files/src/magic-styles.css +131 -131
- package/src/schematics/mg-add/index.d.ts +3 -3
- package/src/schematics/mg-add/index.js +150 -151
- package/src/schematics/mg-add/index.js.map +1 -1
- package/src/schematics/mg-add/schema.json +29 -29
- package/src/schematics/mg-add/utils/add-declaration-to-root-module.d.ts +2 -2
- package/src/schematics/mg-add/utils/add-declaration-to-root-module.js +10 -11
- package/src/schematics/mg-add/utils/add-declaration-to-root-module.js.map +1 -1
- package/src/schematics/mg-add/utils/add-declaration-to-root-module.ts +12 -12
- package/src/schematics/mg-add/webModule/app.routes.ts +14 -14
- package/src/schematics/mg-add-tasks/index.d.ts +3 -3
- package/src/schematics/mg-add-tasks/index.js +29 -30
- package/src/schematics/mg-add-tasks/index.js.map +1 -1
- package/src/schematics/mg-add-tasks/index.ts +53 -53
- package/src/schematics/mg-add-tasks/schema.json +41 -41
- package/src/schematics/mg-delete-files/index.d.ts +3 -3
- package/src/schematics/mg-delete-files/index.js +12 -13
- package/src/schematics/mg-delete-files/index.js.map +1 -1
- package/src/schematics/mg-delete-files/index.ts +12 -12
- package/src/schematics/mg-delete-files/schema.json +14 -14
- package/src/schematics/mg-gen-module/index.d.ts +3 -3
- package/src/schematics/mg-gen-module/index.js +14 -15
- package/src/schematics/mg-gen-module/index.js.map +1 -1
- package/src/schematics/mg-gen-module/index.ts +14 -14
- package/src/schematics/mg-gen-module/schema.json +24 -24
- package/src/schematics/mg-generate/index.d.ts +3 -3
- package/src/schematics/mg-generate/index.js +12 -13
- package/src/schematics/mg-generate/index.js.map +1 -1
- package/src/schematics/mg-generate/index.ts +12 -12
- package/src/schematics/mg-generate/schema.json +34 -34
- package/src/schematics/mg-generate-component/index.d.ts +3 -3
- package/src/schematics/mg-generate-component/index.js +34 -35
- package/src/schematics/mg-generate-component/index.js.map +1 -1
- package/src/schematics/mg-generate-component/schema.json +6 -0
- package/src/schematics/mg-install/index.d.ts +3 -3
- package/src/schematics/mg-install/index.js +29 -30
- package/src/schematics/mg-install/index.js.map +1 -1
- package/src/schematics/mg-install/index.ts +37 -37
- package/src/schematics/mg-install/schema.json +24 -24
- package/src/schematics/mg-routes/index.d.ts +6 -6
- package/src/schematics/mg-routes/index.js +62 -63
- package/src/schematics/mg-routes/index.js.map +1 -1
- package/src/schematics/mg-routes/schema.json +14 -14
- package/src/schematics/mg-single-control/index.d.ts +3 -3
- package/src/schematics/mg-single-control/index.js +28 -29
- package/src/schematics/mg-single-control/index.js.map +1 -1
- package/src/schematics/mg-single-control/schema.json +24 -24
- package/src/schematics/utils/ast.d.ts +21 -21
- package/src/schematics/utils/ast.js +90 -91
- package/src/schematics/utils/ast.js.map +1 -1
- package/src/schematics/utils/ast.ts +103 -103
- package/src/schematics/utils/devkit-utils/README.md +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils.d.ts +87 -87
- package/src/schematics/utils/devkit-utils/ast-utils.js +489 -490
- package/src/schematics/utils/devkit-utils/ast-utils.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils.ts +570 -570
- package/src/schematics/utils/devkit-utils/ast-utils_old.d.ts +68 -68
- package/src/schematics/utils/devkit-utils/ast-utils_old.js +419 -420
- package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils_old.ts +478 -478
- package/src/schematics/utils/devkit-utils/change.d.ts +66 -66
- package/src/schematics/utils/devkit-utils/change.js +94 -94
- package/src/schematics/utils/devkit-utils/change.js.map +1 -1
- package/src/schematics/utils/devkit-utils/change.ts +127 -127
- package/src/schematics/utils/devkit-utils/component.d.ts +2 -2
- package/src/schematics/utils/devkit-utils/component.js +96 -97
- package/src/schematics/utils/devkit-utils/component.js.map +1 -1
- package/src/schematics/utils/devkit-utils/component.ts +136 -136
- package/src/schematics/utils/devkit-utils/config.d.ts +78 -78
- package/src/schematics/utils/devkit-utils/config.js +52 -52
- package/src/schematics/utils/devkit-utils/config.js.map +1 -1
- package/src/schematics/utils/devkit-utils/config.ts +120 -120
- package/src/schematics/utils/devkit-utils/find-module.d.ts +28 -28
- package/src/schematics/utils/devkit-utils/find-module.js +92 -93
- package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
- package/src/schematics/utils/devkit-utils/find-module.ts +108 -108
- package/src/schematics/utils/devkit-utils/ng-ast-utils.d.ts +5 -5
- package/src/schematics/utils/devkit-utils/ng-ast-utils.js +73 -74
- package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ng-ast-utils.ts +84 -84
- package/src/schematics/utils/devkit-utils/parse-name.d.ts +13 -13
- package/src/schematics/utils/devkit-utils/parse-name.js +19 -20
- package/src/schematics/utils/devkit-utils/parse-name.js.map +1 -1
- package/src/schematics/utils/devkit-utils/parse-name.ts +24 -24
- package/src/schematics/utils/devkit-utils/route-utils.d.ts +20 -20
- package/src/schematics/utils/devkit-utils/route-utils.js +133 -134
- package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
- package/src/schematics/utils/devkit-utils/route-utils.ts +180 -180
- package/src/schematics/utils/devkit-utils/validation.d.ts +1 -1
- package/src/schematics/utils/devkit-utils/validation.js +18 -19
- package/src/schematics/utils/devkit-utils/validation.js.map +1 -1
- package/src/schematics/utils/devkit-utils/validation.ts +16 -16
- package/src/schematics/utils/html.d.ts +18 -18
- package/src/schematics/utils/html.js +59 -60
- package/src/schematics/utils/html.js.map +1 -1
- package/src/schematics/utils/html.ts +63 -63
- package/src/schematics/utils/lib-versions.d.ts +3 -3
- package/src/schematics/utils/lib-versions.js +6 -6
- package/src/schematics/utils/lib-versions.js.map +1 -1
- package/src/schematics/utils/lib-versions.ts +3 -3
- package/src/schematics/utils/package.d.ts +5 -5
- package/src/schematics/utils/package.js +20 -21
- package/src/schematics/utils/package.js.map +1 -1
- package/src/schematics/utils/package.ts +22 -22
- package/src/schematics/utils/testing.d.ts +5 -5
- package/src/schematics/utils/testing.js +26 -27
- package/src/schematics/utils/testing.js.map +1 -1
- package/src/schematics/utils/testing.ts +25 -25
- package/src/types/enums/Enums.d.ts +1646 -1646
- package/src/types/enums/Enums.js +1862 -1862
- package/src/types/enums/Enums.js.map +1 -1
- package/src/types/enums/Enums.ts +2063 -2063
- package/src/types/enums/generated-file-types.enum.d.ts +6 -6
- package/src/types/enums/generated-file-types.enum.js +10 -10
- package/src/types/enums/generated-file-types.enum.js.map +1 -1
- package/src/types/enums/generated-file-types.enum.ts +6 -6
- package/src/types/enums/horizontal-alignments.enum.d.ts +5 -5
- package/src/types/enums/horizontal-alignments.enum.js +9 -9
- package/src/types/enums/horizontal-alignments.enum.js.map +1 -1
- package/src/types/enums/horizontal-alignments.enum.ts +6 -6
- package/src/types/enums/themes.enum.d.ts +6 -6
- package/src/types/enums/themes.enum.js +10 -10
- package/src/types/enums/themes.enum.js.map +1 -1
- package/src/types/enums/themes.enum.ts +6 -6
- package/src/types/index.d.ts +7 -7
- package/src/types/index.js +10 -10
- package/src/types/index.js.map +1 -1
- package/src/types/index.ts +8 -8
- package/src/types/interfaces/app.d.ts +53 -53
- package/src/types/interfaces/app.js +9 -9
- package/src/types/interfaces/app.js.map +1 -1
- package/src/types/interfaces/app.ts +89 -89
- package/src/types/interfaces/control.d.ts +82 -82
- package/src/types/interfaces/control.js +2 -2
- package/src/types/interfaces/control.js.map +1 -1
- package/src/types/interfaces/control.ts +106 -106
- package/src/types/interfaces/env.interface.d.ts +19 -19
- package/src/types/interfaces/env.interface.js +10 -10
- package/src/types/interfaces/template.config.d.ts +8 -8
- package/src/types/interfaces/template.config.js +2 -2
- package/src/types/interfaces/template.config.js.map +1 -1
- package/src/types/interfaces/template.config.ts +11 -11
- package/templates/angular/src/app/app.component.html.ejs +17 -17
- package/templates/angular/src/app/cmp-array.ejs +3 -3
- package/templates/angular/src/app/cmp-hash.ejs +3 -3
- package/templates/angular/src/app/component-list.g.ts +21 -21
- package/templates/angular/src/app.component.ts +14 -14
- package/templates/angular/src/app.module.ts +70 -70
- package/templates/angular/src/app.routes.ts +73 -73
- package/templates/angular/src/styles/app.css +5 -5
- package/templates/attributes/button_attributes.ejs +2 -2
- package/templates/attributes/common/base/class.ejs +6 -6
- package/templates/attributes/common/base/control_type.ejs +53 -53
- package/templates/attributes/common/base/enabled.ejs +9 -9
- package/templates/attributes/common/base/imageFileName.ejs +3 -3
- package/templates/attributes/common/base/no_control_class.ejs +3 -3
- package/templates/attributes/common/base/rtol.ejs +3 -3
- package/templates/attributes/common/base/tabindex.ejs +11 -11
- package/templates/attributes/common/base/testingId.ejs +8 -8
- package/templates/attributes/common/base/tooltip.ejs +7 -7
- package/templates/attributes/common/base/visible.ejs +6 -6
- package/templates/attributes/common/base/wallpaper.ejs +3 -3
- package/templates/attributes/common/base_attributes.ejs +10 -10
- package/templates/attributes/common/container_attributes.ejs +6 -6
- package/templates/attributes/common/control_attributes.ejs +3 -3
- package/templates/attributes/common/format.ejs +5 -5
- package/templates/attributes/common/input/hint.ejs +13 -13
- package/templates/attributes/common/input/multiline_edit.ejs +3 -3
- package/templates/attributes/common/input/must_input.ejs +8 -8
- package/templates/attributes/common/input/password_edit.ejs +7 -7
- package/templates/attributes/common/input/row_editing_input_attributes.ejs +6 -6
- package/templates/attributes/common/input/validation.ejs +5 -5
- package/templates/attributes/common/input_attributes.ejs +4 -4
- package/templates/attributes/common/no_control_base_attributes.ejs +4 -4
- package/templates/attributes/common/row_editing_button_attributes.ejs +10 -10
- package/templates/component/view.component.html +14 -14
- package/templates/component/view.component.ts +123 -122
- package/templates/themes/basicHTML/Code/theme.module.ts +10 -10
- package/templates/themes/basicHTML/checkbox.ejs +1 -1
- package/templates/themes/basicHTML/combobox.ejs +37 -37
- package/templates/themes/basicHTML/edit.ejs +169 -168
- package/templates/themes/basicHTML/form.ejs +4 -4
- package/templates/themes/basicHTML/group.ejs +4 -4
- package/templates/themes/basicHTML/image.ejs +6 -6
- package/templates/themes/basicHTML/label.ejs +11 -11
- package/templates/themes/basicHTML/listbox.ejs +21 -21
- package/templates/themes/basicHTML/push-button.ejs +28 -28
- package/templates/themes/basicHTML/radio.ejs +20 -20
- package/templates/themes/basicHTML/subform.ejs +6 -6
- package/templates/themes/basicHTML/tab.ejs +31 -31
- package/templates/themes/basicHTML/tabpage.ejs +5 -5
- package/templates/themes/basicHiddenHTML/Code/theme.module.ts +10 -10
- package/templates/themes/basicHiddenHTML/combobox.ejs +5 -5
- package/templates/themes/basicHiddenHTML/form.ejs +3 -3
- package/templates/themes/basicHiddenHTML/group.ejs +2 -2
- package/templates/themes/basicHiddenHTML/image.ejs +4 -4
- package/templates/themes/basicHiddenHTML/label.ejs +1 -1
- package/templates/themes/basicHiddenHTML/listbox.ejs +8 -8
- package/templates/themes/basicHiddenHTML/push-button.ejs +26 -26
- package/templates/themes/basicHiddenHTML/radio.ejs +17 -17
- package/templates/themes/basicHiddenHTML/tab.ejs +13 -13
- package/templates/themes/basicHiddenHTML/table.ejs +18 -18
- package/templates/themes/basicHiddenHTML/tabpage.ejs +2 -2
- package/templates/themes/container.ejs +26 -26
- package/templates/themes/control.ejs +52 -52
- package/templates/themes/editTypeSelector.ejs +1 -1
- package/templates/themes/material/Code/theme.module.ts +68 -68
- package/templates/themes/material/base_attributes_date.ejs +8 -8
- package/templates/themes/material/checkbox.ejs +1 -1
- package/templates/themes/material/combobox.ejs +43 -43
- package/templates/themes/material/edit.ejs +204 -204
- package/templates/themes/material/group.ejs +3 -3
- package/templates/themes/material/listbox.ejs +22 -23
- package/templates/themes/material/push-button.ejs +28 -28
- package/templates/themes/material/radio.ejs +22 -22
- package/templates/themes/material/subform.ejs +8 -8
- package/templates/themes/material/tab.ejs +19 -19
- package/templates/themes/router_outlet.ejs +5 -5
- package/templates/themes/table/HTMLTable/columnHeader.ejs +3 -1
- package/templates/themes/table/HTMLTable/table.ejs +37 -37
- package/templates/themes/table/grid/additionalComponentCode.ejs +26 -26
- package/templates/themes/table/grid/additionalIncludes.ejs +1 -1
- package/templates/themes/table/grid/column.ejs +3 -1
- package/templates/themes/table/grid/table.ejs +37 -37
- package/templates/themes/table/repeatable/column.ejs +11 -11
- package/templates/themes/table/repeatable/table.ejs +28 -28
- package/templates/themes/tableTypeSelector.ejs +21 -21
- package/tsconfig.json +36 -36
|
@@ -1,491 +1,490 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*
|
|
150
|
-
* @
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
function
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Determine if an import already exists.
|
|
471
|
-
*/
|
|
472
|
-
function isImported(source, classifiedName, importPath) {
|
|
473
|
-
const allNodes = getSourceNodes(source);
|
|
474
|
-
const matchingNodes = allNodes
|
|
475
|
-
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
|
|
476
|
-
.filter((imp) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
|
|
477
|
-
.filter((imp) => {
|
|
478
|
-
return imp.moduleSpecifier.text === importPath;
|
|
479
|
-
})
|
|
480
|
-
.filter((imp) => {
|
|
481
|
-
if (!imp.importClause) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier)
|
|
485
|
-
.filter(n => n.getText() === classifiedName);
|
|
486
|
-
return nodes.length > 0;
|
|
487
|
-
});
|
|
488
|
-
return matchingNodes.length > 0;
|
|
489
|
-
}
|
|
490
|
-
exports.isImported = isImported;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.insertImport = insertImport;
|
|
4
|
+
exports.findNodes = findNodes;
|
|
5
|
+
exports.getSourceNodes = getSourceNodes;
|
|
6
|
+
exports.findNode = findNode;
|
|
7
|
+
exports.insertAfterLastOccurrence = insertAfterLastOccurrence;
|
|
8
|
+
exports.getContentOfKeyLiteral = getContentOfKeyLiteral;
|
|
9
|
+
exports.getDecoratorMetadata = getDecoratorMetadata;
|
|
10
|
+
exports.getFirstNgModuleName = getFirstNgModuleName;
|
|
11
|
+
exports.addSymbolToNgModuleMetadata = addSymbolToNgModuleMetadata;
|
|
12
|
+
exports.addDeclarationToModule = addDeclarationToModule;
|
|
13
|
+
exports.addImportToModule = addImportToModule;
|
|
14
|
+
exports.addProviderToModule = addProviderToModule;
|
|
15
|
+
exports.addExportToModule = addExportToModule;
|
|
16
|
+
exports.addBootstrapToModule = addBootstrapToModule;
|
|
17
|
+
exports.addEntryComponentToModule = addEntryComponentToModule;
|
|
18
|
+
exports.isImported = isImported;
|
|
19
|
+
/**
|
|
20
|
+
* @license
|
|
21
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
22
|
+
*
|
|
23
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
24
|
+
* found in the LICENSE file at https://angular.io/license
|
|
25
|
+
*/
|
|
26
|
+
const ts = require("typescript");
|
|
27
|
+
const change_1 = require("./change");
|
|
28
|
+
/**
|
|
29
|
+
* Add Import `import { symbolName } from fileName` if the import doesn't exit
|
|
30
|
+
* already. Assumes fileToEdit can be resolved and accessed.
|
|
31
|
+
* @param fileToEdit (file we want to add import to)
|
|
32
|
+
* @param symbolName (item to import)
|
|
33
|
+
* @param fileName (path to the file)
|
|
34
|
+
* @param isDefault (if true, import follows style for importing default exports)
|
|
35
|
+
* @return Change
|
|
36
|
+
*/
|
|
37
|
+
function insertImport(source, fileToEdit, symbolName, fileName, isDefault = false) {
|
|
38
|
+
const rootNode = source;
|
|
39
|
+
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
40
|
+
// get nodes that map to import statements from the file fileName
|
|
41
|
+
const relevantImports = allImports.filter(node => {
|
|
42
|
+
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
43
|
+
const importFiles = node.getChildren()
|
|
44
|
+
.filter(child => child.kind === ts.SyntaxKind.StringLiteral)
|
|
45
|
+
.map(n => n.text);
|
|
46
|
+
return importFiles.filter(file => file === fileName).length === 1;
|
|
47
|
+
});
|
|
48
|
+
if (relevantImports.length > 0) {
|
|
49
|
+
let importsAsterisk = false;
|
|
50
|
+
// imports from import file
|
|
51
|
+
const imports = [];
|
|
52
|
+
relevantImports.forEach(n => {
|
|
53
|
+
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
|
54
|
+
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
55
|
+
importsAsterisk = true;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
// if imports * from fileName, don't add symbolName
|
|
59
|
+
if (importsAsterisk) {
|
|
60
|
+
return new change_1.NoopChange();
|
|
61
|
+
}
|
|
62
|
+
const importTextNodes = imports.filter(n => n.text === symbolName);
|
|
63
|
+
// insert import if it's not there
|
|
64
|
+
if (importTextNodes.length === 0) {
|
|
65
|
+
const fallbackPos = findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
66
|
+
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
67
|
+
return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
|
68
|
+
}
|
|
69
|
+
return new change_1.NoopChange();
|
|
70
|
+
}
|
|
71
|
+
// no such import declaration exists
|
|
72
|
+
const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
73
|
+
.filter((n) => n.text === 'use strict');
|
|
74
|
+
let fallbackPos = 0;
|
|
75
|
+
if (useStrict.length > 0) {
|
|
76
|
+
fallbackPos = useStrict[0].end;
|
|
77
|
+
}
|
|
78
|
+
const open = isDefault ? '' : '{ ';
|
|
79
|
+
const close = isDefault ? '' : ' }';
|
|
80
|
+
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
|
81
|
+
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
|
82
|
+
const separator = insertAtBeginning ? '' : ';\n';
|
|
83
|
+
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
|
84
|
+
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
85
|
+
return insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Find all nodes from the AST in the subtree of node of SyntaxKind kind.
|
|
89
|
+
* @param node
|
|
90
|
+
* @param kind
|
|
91
|
+
* @param max The maximum number of items to return.
|
|
92
|
+
* @return all nodes of kind, or [] if none is found
|
|
93
|
+
*/
|
|
94
|
+
function findNodes(node, kind, max = Infinity) {
|
|
95
|
+
if (!node || max == 0) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const arr = [];
|
|
99
|
+
if (node.kind === kind) {
|
|
100
|
+
arr.push(node);
|
|
101
|
+
max--;
|
|
102
|
+
}
|
|
103
|
+
if (max > 0) {
|
|
104
|
+
for (const child of node.getChildren()) {
|
|
105
|
+
findNodes(child, kind, max).forEach(node => {
|
|
106
|
+
if (max > 0) {
|
|
107
|
+
arr.push(node);
|
|
108
|
+
}
|
|
109
|
+
max--;
|
|
110
|
+
});
|
|
111
|
+
if (max <= 0) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return arr;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get all the nodes from a source.
|
|
120
|
+
* @param sourceFile The source file object.
|
|
121
|
+
* @returns {Observable<ts.Node>} An observable of all the nodes in the source.
|
|
122
|
+
*/
|
|
123
|
+
function getSourceNodes(sourceFile) {
|
|
124
|
+
const nodes = [sourceFile];
|
|
125
|
+
const result = [];
|
|
126
|
+
while (nodes.length > 0) {
|
|
127
|
+
const node = nodes.shift();
|
|
128
|
+
if (node) {
|
|
129
|
+
result.push(node);
|
|
130
|
+
if (node.getChildCount(sourceFile) >= 0) {
|
|
131
|
+
nodes.unshift(...node.getChildren());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
function findNode(node, kind, text) {
|
|
138
|
+
if (node.kind === kind && node.getText() === text) {
|
|
139
|
+
// throw new Error(node.getText());
|
|
140
|
+
return node;
|
|
141
|
+
}
|
|
142
|
+
let foundNode = null;
|
|
143
|
+
ts.forEachChild(node, childNode => {
|
|
144
|
+
foundNode = foundNode || findNode(childNode, kind, text);
|
|
145
|
+
});
|
|
146
|
+
return foundNode;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Helper for sorting nodes.
|
|
150
|
+
* @return function to sort nodes in increasing order of position in sourceFile
|
|
151
|
+
*/
|
|
152
|
+
function nodesByPosition(first, second) {
|
|
153
|
+
return first.getStart() - second.getStart();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`
|
|
157
|
+
* or after the last of occurence of `syntaxKind` if the last occurence is a sub child
|
|
158
|
+
* of ts.SyntaxKind[nodes[i].kind] and save the changes in file.
|
|
159
|
+
*
|
|
160
|
+
* @param nodes insert after the last occurence of nodes
|
|
161
|
+
* @param toInsert string to insert
|
|
162
|
+
* @param file file to insert changes into
|
|
163
|
+
* @param fallbackPos position to insert if toInsert happens to be the first occurence
|
|
164
|
+
* @param syntaxKind the ts.SyntaxKind of the subchildren to insert after
|
|
165
|
+
* @return Change instance
|
|
166
|
+
* @throw Error if toInsert is first occurence but fall back is not set
|
|
167
|
+
*/
|
|
168
|
+
function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind) {
|
|
169
|
+
let lastItem = nodes.sort(nodesByPosition).pop();
|
|
170
|
+
if (!lastItem) {
|
|
171
|
+
//throw new Error();
|
|
172
|
+
new change_1.InsertChange(file, 0, toInsert); // Eyal Vardi Fix when no import at all.
|
|
173
|
+
}
|
|
174
|
+
if (syntaxKind) {
|
|
175
|
+
lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
|
|
176
|
+
}
|
|
177
|
+
if (!lastItem && fallbackPos == undefined) {
|
|
178
|
+
throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);
|
|
179
|
+
}
|
|
180
|
+
const lastItemPosition = lastItem ? lastItem.getEnd() : fallbackPos;
|
|
181
|
+
return new change_1.InsertChange(file, lastItemPosition, toInsert);
|
|
182
|
+
}
|
|
183
|
+
function getContentOfKeyLiteral(_source, node) {
|
|
184
|
+
if (node.kind == ts.SyntaxKind.Identifier) {
|
|
185
|
+
return node.text;
|
|
186
|
+
}
|
|
187
|
+
else if (node.kind == ts.SyntaxKind.StringLiteral) {
|
|
188
|
+
return node.text;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function _angularImportsFromNode(node, _sourceFile) {
|
|
195
|
+
const ms = node.moduleSpecifier;
|
|
196
|
+
let modulePath;
|
|
197
|
+
switch (ms.kind) {
|
|
198
|
+
case ts.SyntaxKind.StringLiteral:
|
|
199
|
+
modulePath = ms.text;
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
if (!modulePath.startsWith('@angular/')) {
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
207
|
+
if (node.importClause) {
|
|
208
|
+
if (node.importClause.name) {
|
|
209
|
+
// This is of the form `import Name from 'path'`. Ignore.
|
|
210
|
+
return {};
|
|
211
|
+
}
|
|
212
|
+
else if (node.importClause.namedBindings) {
|
|
213
|
+
const nb = node.importClause.namedBindings;
|
|
214
|
+
if (nb.kind == ts.SyntaxKind.NamespaceImport) {
|
|
215
|
+
// This is of the form `import * as name from 'path'`. Return `name.`.
|
|
216
|
+
return {
|
|
217
|
+
[nb.name.text + '.']: modulePath,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// This is of the form `import {a,b,c} from 'path'`
|
|
222
|
+
const namedImports = nb;
|
|
223
|
+
return namedImports.elements
|
|
224
|
+
.map((is) => is.propertyName ? is.propertyName.text : is.name.text)
|
|
225
|
+
.reduce((acc, curr) => {
|
|
226
|
+
acc[curr] = modulePath;
|
|
227
|
+
return acc;
|
|
228
|
+
}, {});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return {};
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
// This is of the form `import 'path';`. Nothing to do.
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function getDecoratorMetadata(source, identifier, module) {
|
|
239
|
+
const angularImports = findNodes(source, ts.SyntaxKind.ImportDeclaration)
|
|
240
|
+
.map((node) => _angularImportsFromNode(node, source))
|
|
241
|
+
.reduce((acc, current) => {
|
|
242
|
+
for (const key of Object.keys(current)) {
|
|
243
|
+
acc[key] = current[key];
|
|
244
|
+
}
|
|
245
|
+
return acc;
|
|
246
|
+
}, {});
|
|
247
|
+
return getSourceNodes(source)
|
|
248
|
+
.filter(node => {
|
|
249
|
+
return node.kind == ts.SyntaxKind.Decorator
|
|
250
|
+
&& node.expression.kind == ts.SyntaxKind.CallExpression;
|
|
251
|
+
})
|
|
252
|
+
.map(node => node.expression)
|
|
253
|
+
.filter(expr => {
|
|
254
|
+
if (expr.expression.kind == ts.SyntaxKind.Identifier) {
|
|
255
|
+
const id = expr.expression;
|
|
256
|
+
return id.getFullText(source) == identifier
|
|
257
|
+
&& angularImports[id.getFullText(source)] === module;
|
|
258
|
+
}
|
|
259
|
+
else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
|
|
260
|
+
// This covers foo.NgModule when importing * as foo.
|
|
261
|
+
const paExpr = expr.expression;
|
|
262
|
+
// If the left expression is not an identifier, just give up at that point.
|
|
263
|
+
if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
const id = paExpr.name.text;
|
|
267
|
+
const moduleId = paExpr.expression.getText(source);
|
|
268
|
+
return id === identifier && (angularImports[moduleId + '.'] === module);
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
})
|
|
272
|
+
.filter(expr => expr.arguments[0]
|
|
273
|
+
&& expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)
|
|
274
|
+
.map(expr => expr.arguments[0]);
|
|
275
|
+
}
|
|
276
|
+
function findClassDeclarationParent(node) {
|
|
277
|
+
if (ts.isClassDeclaration(node)) {
|
|
278
|
+
return node;
|
|
279
|
+
}
|
|
280
|
+
return node.parent && findClassDeclarationParent(node.parent);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Given a source file with @NgModule class(es), find the name of the first @NgModule class.
|
|
284
|
+
*
|
|
285
|
+
* @param source source file containing one or more @NgModule
|
|
286
|
+
* @returns the name of the first @NgModule, or `undefined` if none is found
|
|
287
|
+
*/
|
|
288
|
+
function getFirstNgModuleName(source) {
|
|
289
|
+
// First, find the @NgModule decorators.
|
|
290
|
+
const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');
|
|
291
|
+
if (ngModulesMetadata.length === 0) {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
// Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule
|
|
295
|
+
// metadata.
|
|
296
|
+
const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);
|
|
297
|
+
if (!moduleClass || !moduleClass.name) {
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
// Get the class name of the module ClassDeclaration.
|
|
301
|
+
return moduleClass.name.text;
|
|
302
|
+
}
|
|
303
|
+
function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbolName, importPath = null) {
|
|
304
|
+
const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');
|
|
305
|
+
let node = nodes[0]; // tslint:disable-line:no-any
|
|
306
|
+
// Find the decorator declaration.
|
|
307
|
+
if (!node) {
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
// Get all the children property assignment of object literals.
|
|
311
|
+
const matchingProperties = node.properties
|
|
312
|
+
.filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment)
|
|
313
|
+
// Filter out every fields that's not "metadataField". Also handles string literals
|
|
314
|
+
// (but not expressions).
|
|
315
|
+
.filter((prop) => {
|
|
316
|
+
const name = prop.name;
|
|
317
|
+
switch (name.kind) {
|
|
318
|
+
case ts.SyntaxKind.Identifier:
|
|
319
|
+
return name.getText(source) == metadataField;
|
|
320
|
+
case ts.SyntaxKind.StringLiteral:
|
|
321
|
+
return name.text == metadataField;
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
});
|
|
325
|
+
// Get the last node of the array literal.
|
|
326
|
+
if (!matchingProperties) {
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
329
|
+
if (matchingProperties.length == 0) {
|
|
330
|
+
// We haven't found the field in the metadata declaration. Insert a new field.
|
|
331
|
+
const expr = node;
|
|
332
|
+
let position;
|
|
333
|
+
let toInsert;
|
|
334
|
+
if (expr.properties.length == 0) {
|
|
335
|
+
position = expr.getEnd() - 1;
|
|
336
|
+
toInsert = ` ${metadataField}: [${symbolName}]\n`;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
node = expr.properties[expr.properties.length - 1];
|
|
340
|
+
position = node.getEnd();
|
|
341
|
+
// Get the indentation of the last element, if any.
|
|
342
|
+
const text = node.getFullText(source);
|
|
343
|
+
const matches = text.match(/^\r?\n\s*/);
|
|
344
|
+
if (matches.length > 0) {
|
|
345
|
+
toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
toInsert = `, ${metadataField}: [${symbolName}]`;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (importPath !== null) {
|
|
352
|
+
return [
|
|
353
|
+
new change_1.InsertChange(ngModulePath, position, toInsert),
|
|
354
|
+
insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
|
|
355
|
+
];
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
return [new change_1.InsertChange(ngModulePath, position, toInsert)];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const assignment = matchingProperties[0];
|
|
362
|
+
// If it's not an array, nothing we can do really.
|
|
363
|
+
if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
const arrLiteral = assignment.initializer;
|
|
367
|
+
if (arrLiteral.elements.length == 0) {
|
|
368
|
+
// Forward the property.
|
|
369
|
+
node = arrLiteral;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
node = arrLiteral.elements;
|
|
373
|
+
}
|
|
374
|
+
if (!node) {
|
|
375
|
+
console.log('No app module found. Please add your new class to your component.');
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
if (Array.isArray(node)) {
|
|
379
|
+
const nodeArray = node;
|
|
380
|
+
const symbolsArray = nodeArray.map(node => node.getText());
|
|
381
|
+
if (symbolsArray.includes(symbolName)) {
|
|
382
|
+
return [];
|
|
383
|
+
}
|
|
384
|
+
node = node[node.length - 1];
|
|
385
|
+
}
|
|
386
|
+
let toInsert;
|
|
387
|
+
let position = node.getEnd();
|
|
388
|
+
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
|
|
389
|
+
// We haven't found the field in the metadata declaration. Insert a new
|
|
390
|
+
// field.
|
|
391
|
+
const expr = node;
|
|
392
|
+
if (expr.properties.length == 0) {
|
|
393
|
+
position = expr.getEnd() - 1;
|
|
394
|
+
toInsert = ` ${metadataField}: [${symbolName}]\n`;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
node = expr.properties[expr.properties.length - 1];
|
|
398
|
+
position = node.getEnd();
|
|
399
|
+
// Get the indentation of the last element, if any.
|
|
400
|
+
const text = node.getFullText(source);
|
|
401
|
+
if (text.match('^\r?\r?\n')) {
|
|
402
|
+
toInsert = `,${text.match(/^\r?\n\s+/)[0]}${metadataField}: [${symbolName}]`;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
toInsert = `, ${metadataField}: [${symbolName}]`;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {
|
|
410
|
+
// We found the field but it's empty. Insert it just before the `]`.
|
|
411
|
+
position--;
|
|
412
|
+
toInsert = `${symbolName}`;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
// Get the indentation of the last element, if any.
|
|
416
|
+
const text = node.getFullText(source);
|
|
417
|
+
if (text.match(/^\r?\n/)) {
|
|
418
|
+
toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbolName}`;
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
toInsert = `, ${symbolName}`;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (importPath !== null) {
|
|
425
|
+
return [
|
|
426
|
+
new change_1.InsertChange(ngModulePath, position, toInsert),
|
|
427
|
+
insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
|
|
428
|
+
];
|
|
429
|
+
}
|
|
430
|
+
return [new change_1.InsertChange(ngModulePath, position, toInsert)];
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Custom function to insert a declaration (component, pipe, directive)
|
|
434
|
+
* into NgModule declarations. It also imports the component.
|
|
435
|
+
*/
|
|
436
|
+
function addDeclarationToModule(source, modulePath, classifiedName, importPath) {
|
|
437
|
+
return addSymbolToNgModuleMetadata(source, modulePath, 'declarations', classifiedName, importPath);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Custom function to insert an NgModule into NgModule imports. It also imports the module.
|
|
441
|
+
*/
|
|
442
|
+
function addImportToModule(source, modulePath, classifiedName, importPath) {
|
|
443
|
+
return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Custom function to insert a provider into NgModule. It also imports it.
|
|
447
|
+
*/
|
|
448
|
+
function addProviderToModule(source, modulePath, classifiedName, importPath) {
|
|
449
|
+
return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Custom function to insert an export into NgModule. It also imports it.
|
|
453
|
+
*/
|
|
454
|
+
function addExportToModule(source, modulePath, classifiedName, importPath) {
|
|
455
|
+
return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Custom function to insert an export into NgModule. It also imports it.
|
|
459
|
+
*/
|
|
460
|
+
function addBootstrapToModule(source, modulePath, classifiedName, importPath) {
|
|
461
|
+
return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Custom function to insert an entryComponent into NgModule. It also imports it.
|
|
465
|
+
*/
|
|
466
|
+
function addEntryComponentToModule(source, modulePath, classifiedName, importPath) {
|
|
467
|
+
return addSymbolToNgModuleMetadata(source, modulePath, 'entryComponents', classifiedName, importPath);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Determine if an import already exists.
|
|
471
|
+
*/
|
|
472
|
+
function isImported(source, classifiedName, importPath) {
|
|
473
|
+
const allNodes = getSourceNodes(source);
|
|
474
|
+
const matchingNodes = allNodes
|
|
475
|
+
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
|
|
476
|
+
.filter((imp) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
|
|
477
|
+
.filter((imp) => {
|
|
478
|
+
return imp.moduleSpecifier.text === importPath;
|
|
479
|
+
})
|
|
480
|
+
.filter((imp) => {
|
|
481
|
+
if (!imp.importClause) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier)
|
|
485
|
+
.filter(n => n.getText() === classifiedName);
|
|
486
|
+
return nodes.length > 0;
|
|
487
|
+
});
|
|
488
|
+
return matchingNodes.length > 0;
|
|
489
|
+
}
|
|
491
490
|
//# sourceMappingURL=ast-utils.js.map
|