@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,98 +1,97 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildComponent =
|
|
4
|
-
const core_1 = require("@angular-devkit/core");
|
|
5
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
|
-
const ts = require("typescript");
|
|
7
|
-
const ast_utils_1 = require("./ast-utils");
|
|
8
|
-
const change_1 = require("./change");
|
|
9
|
-
const find_module_1 = require("./find-module");
|
|
10
|
-
const config_1 = require("./config");
|
|
11
|
-
const parse_name_1 = require("./parse-name");
|
|
12
|
-
const validation_1 = require("./validation");
|
|
13
|
-
function addDeclarationToNgModule(options) {
|
|
14
|
-
return (host) => {
|
|
15
|
-
if (options.skipImport || !options.module) {
|
|
16
|
-
return host;
|
|
17
|
-
}
|
|
18
|
-
const modulePath = options.module;
|
|
19
|
-
const text = host.read(modulePath);
|
|
20
|
-
if (text === null) {
|
|
21
|
-
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
|
|
22
|
-
}
|
|
23
|
-
const sourceText = text.toString('utf-8');
|
|
24
|
-
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
25
|
-
const componentPath = `/${options.path}/`
|
|
26
|
-
+ (options.flat ? '' : core_1.strings.dasherize(options.name) + '/')
|
|
27
|
-
+ core_1.strings.dasherize(options.name)
|
|
28
|
-
+ '.component';
|
|
29
|
-
const relativePath = (0, find_module_1.buildRelativePath)(modulePath, componentPath);
|
|
30
|
-
const classifiedName = core_1.strings.classify(`${options.name}Component`);
|
|
31
|
-
const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
|
|
32
|
-
const declarationRecorder = host.beginUpdate(modulePath);
|
|
33
|
-
for (const change of declarationChanges) {
|
|
34
|
-
if (change instanceof change_1.InsertChange) {
|
|
35
|
-
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
host.commitUpdate(declarationRecorder);
|
|
39
|
-
if (options.export) {
|
|
40
|
-
// Need to refresh the AST because we overwrote the file in the host.
|
|
41
|
-
const text = host.read(modulePath);
|
|
42
|
-
if (text === null) {
|
|
43
|
-
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
|
|
44
|
-
}
|
|
45
|
-
const sourceText = text.toString('utf-8');
|
|
46
|
-
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
47
|
-
const exportRecorder = host.beginUpdate(modulePath);
|
|
48
|
-
const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath);
|
|
49
|
-
for (const change of exportChanges) {
|
|
50
|
-
if (change instanceof change_1.InsertChange) {
|
|
51
|
-
exportRecorder.insertLeft(change.pos, change.toAdd);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
host.commitUpdate(exportRecorder);
|
|
55
|
-
}
|
|
56
|
-
return host;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function buildSelector(options) {
|
|
60
|
-
let selector = core_1.strings.dasherize(options.name);
|
|
61
|
-
if (options.prefix) {
|
|
62
|
-
selector = `${options.prefix}-${selector}`;
|
|
63
|
-
}
|
|
64
|
-
return selector;
|
|
65
|
-
}
|
|
66
|
-
function buildComponent(options) {
|
|
67
|
-
return (host, context) => {
|
|
68
|
-
const workspace = (0, config_1.getWorkspace)(host);
|
|
69
|
-
if (!options.project) {
|
|
70
|
-
options.project = Object.keys(workspace.projects)[0];
|
|
71
|
-
}
|
|
72
|
-
const project = workspace.projects[options.project];
|
|
73
|
-
if (options.path === undefined) {
|
|
74
|
-
options.path = `/${project.root}/src/app`;
|
|
75
|
-
}
|
|
76
|
-
options.selector = options.selector || buildSelector(options);
|
|
77
|
-
options.module = (0, find_module_1.findModuleFromOptions)(host, options);
|
|
78
|
-
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
79
|
-
options.name = parsedPath.name;
|
|
80
|
-
options.path = parsedPath.path;
|
|
81
|
-
(0, validation_1.validateName)(options.name);
|
|
82
|
-
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
83
|
-
options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('.spec.ts')),
|
|
84
|
-
options.inlineStyle ? (0, schematics_1.filter)(path => !path.endsWith('.__styleext__')) : (0, schematics_1.noop)(),
|
|
85
|
-
options.inlineTemplate ? (0, schematics_1.filter)(path => !path.endsWith('.html')) : (0, schematics_1.noop)(),
|
|
86
|
-
(0, schematics_1.template)(Object.assign(Object.assign(Object.assign({}, core_1.strings), { 'if-flat': (s) => options.flat ? '' : s }), options)),
|
|
87
|
-
(0, schematics_1.move)(null, parsedPath.path),
|
|
88
|
-
]);
|
|
89
|
-
return (0, schematics_1.chain)([
|
|
90
|
-
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
91
|
-
addDeclarationToNgModule(options),
|
|
92
|
-
(0, schematics_1.mergeWith)(templateSource),
|
|
93
|
-
])),
|
|
94
|
-
])(host, context);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
exports.buildComponent = buildComponent;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildComponent = buildComponent;
|
|
4
|
+
const core_1 = require("@angular-devkit/core");
|
|
5
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
|
+
const ts = require("typescript");
|
|
7
|
+
const ast_utils_1 = require("./ast-utils");
|
|
8
|
+
const change_1 = require("./change");
|
|
9
|
+
const find_module_1 = require("./find-module");
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const parse_name_1 = require("./parse-name");
|
|
12
|
+
const validation_1 = require("./validation");
|
|
13
|
+
function addDeclarationToNgModule(options) {
|
|
14
|
+
return (host) => {
|
|
15
|
+
if (options.skipImport || !options.module) {
|
|
16
|
+
return host;
|
|
17
|
+
}
|
|
18
|
+
const modulePath = options.module;
|
|
19
|
+
const text = host.read(modulePath);
|
|
20
|
+
if (text === null) {
|
|
21
|
+
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
|
|
22
|
+
}
|
|
23
|
+
const sourceText = text.toString('utf-8');
|
|
24
|
+
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
25
|
+
const componentPath = `/${options.path}/`
|
|
26
|
+
+ (options.flat ? '' : core_1.strings.dasherize(options.name) + '/')
|
|
27
|
+
+ core_1.strings.dasherize(options.name)
|
|
28
|
+
+ '.component';
|
|
29
|
+
const relativePath = (0, find_module_1.buildRelativePath)(modulePath, componentPath);
|
|
30
|
+
const classifiedName = core_1.strings.classify(`${options.name}Component`);
|
|
31
|
+
const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
|
|
32
|
+
const declarationRecorder = host.beginUpdate(modulePath);
|
|
33
|
+
for (const change of declarationChanges) {
|
|
34
|
+
if (change instanceof change_1.InsertChange) {
|
|
35
|
+
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
host.commitUpdate(declarationRecorder);
|
|
39
|
+
if (options.export) {
|
|
40
|
+
// Need to refresh the AST because we overwrote the file in the host.
|
|
41
|
+
const text = host.read(modulePath);
|
|
42
|
+
if (text === null) {
|
|
43
|
+
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
|
|
44
|
+
}
|
|
45
|
+
const sourceText = text.toString('utf-8');
|
|
46
|
+
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
47
|
+
const exportRecorder = host.beginUpdate(modulePath);
|
|
48
|
+
const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath);
|
|
49
|
+
for (const change of exportChanges) {
|
|
50
|
+
if (change instanceof change_1.InsertChange) {
|
|
51
|
+
exportRecorder.insertLeft(change.pos, change.toAdd);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
host.commitUpdate(exportRecorder);
|
|
55
|
+
}
|
|
56
|
+
return host;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function buildSelector(options) {
|
|
60
|
+
let selector = core_1.strings.dasherize(options.name);
|
|
61
|
+
if (options.prefix) {
|
|
62
|
+
selector = `${options.prefix}-${selector}`;
|
|
63
|
+
}
|
|
64
|
+
return selector;
|
|
65
|
+
}
|
|
66
|
+
function buildComponent(options) {
|
|
67
|
+
return (host, context) => {
|
|
68
|
+
const workspace = (0, config_1.getWorkspace)(host);
|
|
69
|
+
if (!options.project) {
|
|
70
|
+
options.project = Object.keys(workspace.projects)[0];
|
|
71
|
+
}
|
|
72
|
+
const project = workspace.projects[options.project];
|
|
73
|
+
if (options.path === undefined) {
|
|
74
|
+
options.path = `/${project.root}/src/app`;
|
|
75
|
+
}
|
|
76
|
+
options.selector = options.selector || buildSelector(options);
|
|
77
|
+
options.module = (0, find_module_1.findModuleFromOptions)(host, options);
|
|
78
|
+
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
79
|
+
options.name = parsedPath.name;
|
|
80
|
+
options.path = parsedPath.path;
|
|
81
|
+
(0, validation_1.validateName)(options.name);
|
|
82
|
+
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
83
|
+
options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('.spec.ts')),
|
|
84
|
+
options.inlineStyle ? (0, schematics_1.filter)(path => !path.endsWith('.__styleext__')) : (0, schematics_1.noop)(),
|
|
85
|
+
options.inlineTemplate ? (0, schematics_1.filter)(path => !path.endsWith('.html')) : (0, schematics_1.noop)(),
|
|
86
|
+
(0, schematics_1.template)(Object.assign(Object.assign(Object.assign({}, core_1.strings), { 'if-flat': (s) => options.flat ? '' : s }), options)),
|
|
87
|
+
(0, schematics_1.move)(null, parsedPath.path),
|
|
88
|
+
]);
|
|
89
|
+
return (0, schematics_1.chain)([
|
|
90
|
+
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
91
|
+
addDeclarationToNgModule(options),
|
|
92
|
+
(0, schematics_1.mergeWith)(templateSource),
|
|
93
|
+
])),
|
|
94
|
+
])(host, context);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
98
97
|
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":";;AA+FA,wCAwCC;AAvID,+CAAwD;AACxD,2DAcoC;AACpC,iCAAiC;AACjC,2CAAsE;AACtE,qCAAsC;AACtC,+CAAuE;AACvE,qCAAsC;AACtC,6CAAuC;AACvC,6CAA0C;AAE1C,SAAS,wBAAwB,CAAC,OAAY;IAC5C,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,IAAI,OAAO,CAAC,UAAU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AA,iBAAI,GAAE,CAAC,CAAC,CAAC,IAAA,mBAAM,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAClE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAA,mBAAM,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE;YAC9E,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,IAAA,mBAAM,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE;YACzE,IAAA,qBAAQ,gDACH,cAAO,KACV,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAC5C,OAAO,EACV;YACF,IAAA,iBAAI,EAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;SAC5B,CAAC,CAAC;QAEH,OAAO,IAAA,kBAAK,EAAC;YACX,IAAA,2BAAc,EAAC,IAAA,kBAAK,EAAC;gBACnB,wBAAwB,CAAC,OAAO,CAAC;gBACjC,IAAA,sBAAS,EAAC,cAAc,CAAC;aAC1B,CAAC,CAAC;SACJ,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {normalize, strings} from '@angular-devkit/core';\r\nimport {\r\n apply,\r\n branchAndMerge,\r\n chain,\r\n filter,\r\n mergeWith,\r\n move,\r\n noop,\r\n Rule,\r\n SchematicContext,\r\n SchematicsException,\r\n template,\r\n Tree,\r\n url,\r\n} from '@angular-devkit/schematics';\r\nimport * as ts from 'typescript';\r\nimport {addDeclarationToModule, addExportToModule} from './ast-utils';\r\nimport {InsertChange} from './change';\r\nimport {buildRelativePath, findModuleFromOptions} from './find-module';\r\nimport {getWorkspace} from './config';\r\nimport {parseName} from './parse-name';\r\nimport {validateName} from './validation';\r\n\r\nfunction addDeclarationToNgModule(options: any): Rule {\r\n return (host: Tree) => {\r\n if (options.skipImport || !options.module) {\r\n return host;\r\n }\r\n\r\n const modulePath = options.module;\r\n const text = host.read(modulePath);\r\n if (text === null) {\r\n throw new SchematicsException(`File ${modulePath} does not exist.`);\r\n }\r\n const sourceText = text.toString('utf-8');\r\n const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);\r\n\r\n const componentPath = `/${options.path}/`\r\n + (options.flat ? '' : strings.dasherize(options.name) + '/')\r\n + strings.dasherize(options.name)\r\n + '.component';\r\n const relativePath = buildRelativePath(modulePath, componentPath);\r\n const classifiedName = strings.classify(`${options.name}Component`);\r\n const declarationChanges = addDeclarationToModule(source,\r\n modulePath,\r\n classifiedName,\r\n relativePath);\r\n\r\n const declarationRecorder = host.beginUpdate(modulePath);\r\n for (const change of declarationChanges) {\r\n if (change instanceof InsertChange) {\r\n declarationRecorder.insertLeft(change.pos, change.toAdd);\r\n }\r\n }\r\n host.commitUpdate(declarationRecorder);\r\n\r\n if (options.export) {\r\n // Need to refresh the AST because we overwrote the file in the host.\r\n const text = host.read(modulePath);\r\n if (text === null) {\r\n throw new SchematicsException(`File ${modulePath} does not exist.`);\r\n }\r\n const sourceText = text.toString('utf-8');\r\n const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);\r\n\r\n const exportRecorder = host.beginUpdate(modulePath);\r\n const exportChanges = addExportToModule(source, modulePath,\r\n strings.classify(`${options.name}Component`),\r\n relativePath);\r\n\r\n for (const change of exportChanges) {\r\n if (change instanceof InsertChange) {\r\n exportRecorder.insertLeft(change.pos, change.toAdd);\r\n }\r\n }\r\n host.commitUpdate(exportRecorder);\r\n }\r\n\r\n\r\n return host;\r\n };\r\n}\r\n\r\n\r\nfunction buildSelector(options: any) {\r\n let selector = strings.dasherize(options.name);\r\n if (options.prefix) {\r\n selector = `${options.prefix}-${selector}`;\r\n }\r\n\r\n return selector;\r\n}\r\n\r\n\r\nexport function buildComponent(options: any): Rule {\r\n return (host: Tree, context: SchematicContext) => {\r\n const workspace = getWorkspace(host);\r\n if (!options.project) {\r\n options.project = Object.keys(workspace.projects)[0];\r\n }\r\n const project = workspace.projects[options.project];\r\n\r\n if (options.path === undefined) {\r\n options.path = `/${project.root}/src/app`;\r\n }\r\n\r\n options.selector = options.selector || buildSelector(options);\r\n options.module = findModuleFromOptions(host, options);\r\n\r\n const parsedPath = parseName(options.path, options.name);\r\n options.name = parsedPath.name;\r\n options.path = parsedPath.path;\r\n\r\n validateName(options.name);\r\n\r\n const templateSource = apply(url('./files'), [\r\n options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),\r\n options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(),\r\n options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),\r\n template({\r\n ...strings,\r\n 'if-flat': (s: string) => options.flat ? '' : s,\r\n ...options,\r\n }),\r\n move(null, parsedPath.path),\r\n ]);\r\n\r\n return chain([\r\n branchAndMerge(chain([\r\n addDeclarationToNgModule(options),\r\n mergeWith(templateSource),\r\n ])),\r\n ])(host, context);\r\n };\r\n}\r\n"]}
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import {normalize, strings} from '@angular-devkit/core';
|
|
2
|
-
import {
|
|
3
|
-
apply,
|
|
4
|
-
branchAndMerge,
|
|
5
|
-
chain,
|
|
6
|
-
filter,
|
|
7
|
-
mergeWith,
|
|
8
|
-
move,
|
|
9
|
-
noop,
|
|
10
|
-
Rule,
|
|
11
|
-
SchematicContext,
|
|
12
|
-
SchematicsException,
|
|
13
|
-
template,
|
|
14
|
-
Tree,
|
|
15
|
-
url,
|
|
16
|
-
} from '@angular-devkit/schematics';
|
|
17
|
-
import * as ts from 'typescript';
|
|
18
|
-
import {addDeclarationToModule, addExportToModule} from './ast-utils';
|
|
19
|
-
import {InsertChange} from './change';
|
|
20
|
-
import {buildRelativePath, findModuleFromOptions} from './find-module';
|
|
21
|
-
import {getWorkspace} from './config';
|
|
22
|
-
import {parseName} from './parse-name';
|
|
23
|
-
import {validateName} from './validation';
|
|
24
|
-
|
|
25
|
-
function addDeclarationToNgModule(options: any): Rule {
|
|
26
|
-
return (host: Tree) => {
|
|
27
|
-
if (options.skipImport || !options.module) {
|
|
28
|
-
return host;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const modulePath = options.module;
|
|
32
|
-
const text = host.read(modulePath);
|
|
33
|
-
if (text === null) {
|
|
34
|
-
throw new SchematicsException(`File ${modulePath} does not exist.`);
|
|
35
|
-
}
|
|
36
|
-
const sourceText = text.toString('utf-8');
|
|
37
|
-
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
38
|
-
|
|
39
|
-
const componentPath = `/${options.path}/`
|
|
40
|
-
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
|
|
41
|
-
+ strings.dasherize(options.name)
|
|
42
|
-
+ '.component';
|
|
43
|
-
const relativePath = buildRelativePath(modulePath, componentPath);
|
|
44
|
-
const classifiedName = strings.classify(`${options.name}Component`);
|
|
45
|
-
const declarationChanges = addDeclarationToModule(source,
|
|
46
|
-
modulePath,
|
|
47
|
-
classifiedName,
|
|
48
|
-
relativePath);
|
|
49
|
-
|
|
50
|
-
const declarationRecorder = host.beginUpdate(modulePath);
|
|
51
|
-
for (const change of declarationChanges) {
|
|
52
|
-
if (change instanceof InsertChange) {
|
|
53
|
-
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
host.commitUpdate(declarationRecorder);
|
|
57
|
-
|
|
58
|
-
if (options.export) {
|
|
59
|
-
// Need to refresh the AST because we overwrote the file in the host.
|
|
60
|
-
const text = host.read(modulePath);
|
|
61
|
-
if (text === null) {
|
|
62
|
-
throw new SchematicsException(`File ${modulePath} does not exist.`);
|
|
63
|
-
}
|
|
64
|
-
const sourceText = text.toString('utf-8');
|
|
65
|
-
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
66
|
-
|
|
67
|
-
const exportRecorder = host.beginUpdate(modulePath);
|
|
68
|
-
const exportChanges = addExportToModule(source, modulePath,
|
|
69
|
-
strings.classify(`${options.name}Component`),
|
|
70
|
-
relativePath);
|
|
71
|
-
|
|
72
|
-
for (const change of exportChanges) {
|
|
73
|
-
if (change instanceof InsertChange) {
|
|
74
|
-
exportRecorder.insertLeft(change.pos, change.toAdd);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
host.commitUpdate(exportRecorder);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return host;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
function buildSelector(options: any) {
|
|
87
|
-
let selector = strings.dasherize(options.name);
|
|
88
|
-
if (options.prefix) {
|
|
89
|
-
selector = `${options.prefix}-${selector}`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return selector;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
export function buildComponent(options: any): Rule {
|
|
97
|
-
return (host: Tree, context: SchematicContext) => {
|
|
98
|
-
const workspace = getWorkspace(host);
|
|
99
|
-
if (!options.project) {
|
|
100
|
-
options.project = Object.keys(workspace.projects)[0];
|
|
101
|
-
}
|
|
102
|
-
const project = workspace.projects[options.project];
|
|
103
|
-
|
|
104
|
-
if (options.path === undefined) {
|
|
105
|
-
options.path = `/${project.root}/src/app`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
options.selector = options.selector || buildSelector(options);
|
|
109
|
-
options.module = findModuleFromOptions(host, options);
|
|
110
|
-
|
|
111
|
-
const parsedPath = parseName(options.path, options.name);
|
|
112
|
-
options.name = parsedPath.name;
|
|
113
|
-
options.path = parsedPath.path;
|
|
114
|
-
|
|
115
|
-
validateName(options.name);
|
|
116
|
-
|
|
117
|
-
const templateSource = apply(url('./files'), [
|
|
118
|
-
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
|
|
119
|
-
options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(),
|
|
120
|
-
options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
|
|
121
|
-
template({
|
|
122
|
-
...strings,
|
|
123
|
-
'if-flat': (s: string) => options.flat ? '' : s,
|
|
124
|
-
...options,
|
|
125
|
-
}),
|
|
126
|
-
move(null, parsedPath.path),
|
|
127
|
-
]);
|
|
128
|
-
|
|
129
|
-
return chain([
|
|
130
|
-
branchAndMerge(chain([
|
|
131
|
-
addDeclarationToNgModule(options),
|
|
132
|
-
mergeWith(templateSource),
|
|
133
|
-
])),
|
|
134
|
-
])(host, context);
|
|
135
|
-
};
|
|
136
|
-
}
|
|
1
|
+
import {normalize, strings} from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
branchAndMerge,
|
|
5
|
+
chain,
|
|
6
|
+
filter,
|
|
7
|
+
mergeWith,
|
|
8
|
+
move,
|
|
9
|
+
noop,
|
|
10
|
+
Rule,
|
|
11
|
+
SchematicContext,
|
|
12
|
+
SchematicsException,
|
|
13
|
+
template,
|
|
14
|
+
Tree,
|
|
15
|
+
url,
|
|
16
|
+
} from '@angular-devkit/schematics';
|
|
17
|
+
import * as ts from 'typescript';
|
|
18
|
+
import {addDeclarationToModule, addExportToModule} from './ast-utils';
|
|
19
|
+
import {InsertChange} from './change';
|
|
20
|
+
import {buildRelativePath, findModuleFromOptions} from './find-module';
|
|
21
|
+
import {getWorkspace} from './config';
|
|
22
|
+
import {parseName} from './parse-name';
|
|
23
|
+
import {validateName} from './validation';
|
|
24
|
+
|
|
25
|
+
function addDeclarationToNgModule(options: any): Rule {
|
|
26
|
+
return (host: Tree) => {
|
|
27
|
+
if (options.skipImport || !options.module) {
|
|
28
|
+
return host;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const modulePath = options.module;
|
|
32
|
+
const text = host.read(modulePath);
|
|
33
|
+
if (text === null) {
|
|
34
|
+
throw new SchematicsException(`File ${modulePath} does not exist.`);
|
|
35
|
+
}
|
|
36
|
+
const sourceText = text.toString('utf-8');
|
|
37
|
+
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
38
|
+
|
|
39
|
+
const componentPath = `/${options.path}/`
|
|
40
|
+
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
|
|
41
|
+
+ strings.dasherize(options.name)
|
|
42
|
+
+ '.component';
|
|
43
|
+
const relativePath = buildRelativePath(modulePath, componentPath);
|
|
44
|
+
const classifiedName = strings.classify(`${options.name}Component`);
|
|
45
|
+
const declarationChanges = addDeclarationToModule(source,
|
|
46
|
+
modulePath,
|
|
47
|
+
classifiedName,
|
|
48
|
+
relativePath);
|
|
49
|
+
|
|
50
|
+
const declarationRecorder = host.beginUpdate(modulePath);
|
|
51
|
+
for (const change of declarationChanges) {
|
|
52
|
+
if (change instanceof InsertChange) {
|
|
53
|
+
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
host.commitUpdate(declarationRecorder);
|
|
57
|
+
|
|
58
|
+
if (options.export) {
|
|
59
|
+
// Need to refresh the AST because we overwrote the file in the host.
|
|
60
|
+
const text = host.read(modulePath);
|
|
61
|
+
if (text === null) {
|
|
62
|
+
throw new SchematicsException(`File ${modulePath} does not exist.`);
|
|
63
|
+
}
|
|
64
|
+
const sourceText = text.toString('utf-8');
|
|
65
|
+
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
66
|
+
|
|
67
|
+
const exportRecorder = host.beginUpdate(modulePath);
|
|
68
|
+
const exportChanges = addExportToModule(source, modulePath,
|
|
69
|
+
strings.classify(`${options.name}Component`),
|
|
70
|
+
relativePath);
|
|
71
|
+
|
|
72
|
+
for (const change of exportChanges) {
|
|
73
|
+
if (change instanceof InsertChange) {
|
|
74
|
+
exportRecorder.insertLeft(change.pos, change.toAdd);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
host.commitUpdate(exportRecorder);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
return host;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
function buildSelector(options: any) {
|
|
87
|
+
let selector = strings.dasherize(options.name);
|
|
88
|
+
if (options.prefix) {
|
|
89
|
+
selector = `${options.prefix}-${selector}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return selector;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export function buildComponent(options: any): Rule {
|
|
97
|
+
return (host: Tree, context: SchematicContext) => {
|
|
98
|
+
const workspace = getWorkspace(host);
|
|
99
|
+
if (!options.project) {
|
|
100
|
+
options.project = Object.keys(workspace.projects)[0];
|
|
101
|
+
}
|
|
102
|
+
const project = workspace.projects[options.project];
|
|
103
|
+
|
|
104
|
+
if (options.path === undefined) {
|
|
105
|
+
options.path = `/${project.root}/src/app`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
options.selector = options.selector || buildSelector(options);
|
|
109
|
+
options.module = findModuleFromOptions(host, options);
|
|
110
|
+
|
|
111
|
+
const parsedPath = parseName(options.path, options.name);
|
|
112
|
+
options.name = parsedPath.name;
|
|
113
|
+
options.path = parsedPath.path;
|
|
114
|
+
|
|
115
|
+
validateName(options.name);
|
|
116
|
+
|
|
117
|
+
const templateSource = apply(url('./files'), [
|
|
118
|
+
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
|
|
119
|
+
options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(),
|
|
120
|
+
options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
|
|
121
|
+
template({
|
|
122
|
+
...strings,
|
|
123
|
+
'if-flat': (s: string) => options.flat ? '' : s,
|
|
124
|
+
...options,
|
|
125
|
+
}),
|
|
126
|
+
move(null, parsedPath.path),
|
|
127
|
+
]);
|
|
128
|
+
|
|
129
|
+
return chain([
|
|
130
|
+
branchAndMerge(chain([
|
|
131
|
+
addDeclarationToNgModule(options),
|
|
132
|
+
mergeWith(templateSource),
|
|
133
|
+
])),
|
|
134
|
+
])(host, context);
|
|
135
|
+
};
|
|
136
|
+
}
|