@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,180 +1,180 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import * as ts from 'typescript';
|
|
9
|
-
import { findNode, findNodes, insertAfterLastOccurrence } from "./ast-utils";
|
|
10
|
-
import { Change, InsertChange, NoopChange } from "./change";
|
|
11
|
-
import {SchematicsException, Tree} from "@angular-devkit/schematics";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Add Import `import { symbolName } from fileName` if the import doesn't exit
|
|
16
|
-
* already. Assumes fileToEdit can be resolved and accessed.
|
|
17
|
-
* @param fileToEdit (file we want to add import to)
|
|
18
|
-
* @param symbolName (item to import)
|
|
19
|
-
* @param fileName (path to the file)
|
|
20
|
-
* @param isDefault (if true, import follows style for importing default exports)
|
|
21
|
-
* @return Change
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
export function insertImport2(
|
|
25
|
-
source : ts.SourceFile,
|
|
26
|
-
fileToEdit : string,
|
|
27
|
-
symbolName : string,
|
|
28
|
-
asSymbolName: string,
|
|
29
|
-
fileName : string,
|
|
30
|
-
isDefault = false): Change {
|
|
31
|
-
const rootNode = source;
|
|
32
|
-
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
33
|
-
|
|
34
|
-
// get nodes that map to import statements from the file fileName
|
|
35
|
-
const relevantImports = allImports.filter(node => {
|
|
36
|
-
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
37
|
-
const importFiles = node.getChildren()
|
|
38
|
-
.filter(child => child.kind === ts.SyntaxKind.StringLiteral)
|
|
39
|
-
.map(n => (n as ts.StringLiteral).text);
|
|
40
|
-
|
|
41
|
-
return importFiles.filter(file => file === fileName).length === 1;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (relevantImports.length > 0) {
|
|
45
|
-
let importsAsterisk = false;
|
|
46
|
-
// imports from import file
|
|
47
|
-
const imports: ts.Node[] = [];
|
|
48
|
-
relevantImports.forEach(n => {
|
|
49
|
-
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
|
50
|
-
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
51
|
-
importsAsterisk = true;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// if imports * from fileName, don't add symbolName
|
|
56
|
-
if (importsAsterisk) {
|
|
57
|
-
return new NoopChange();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
|
|
61
|
-
|
|
62
|
-
// insert import if it's not there
|
|
63
|
-
if (importTextNodes.length === 0) {
|
|
64
|
-
const fallbackPos =
|
|
65
|
-
findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
66
|
-
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
67
|
-
|
|
68
|
-
return insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return new NoopChange();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// no such import declaration exists
|
|
75
|
-
const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
76
|
-
.filter((n: ts.StringLiteral) => n.text === 'use strict');
|
|
77
|
-
let fallbackPos = 0;
|
|
78
|
-
if (useStrict.length > 0) {
|
|
79
|
-
fallbackPos = useStrict[0].end;
|
|
80
|
-
}
|
|
81
|
-
const open = isDefault ? '' : '{ ';
|
|
82
|
-
const close = isDefault ? '' : ' }';
|
|
83
|
-
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
|
84
|
-
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
|
85
|
-
const separator = insertAtBeginning ? '' : ';\n';
|
|
86
|
-
const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +
|
|
87
|
-
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
88
|
-
|
|
89
|
-
return insertAfterLastOccurrence(
|
|
90
|
-
allImports,
|
|
91
|
-
toInsert,
|
|
92
|
-
fileToEdit,
|
|
93
|
-
fallbackPos,
|
|
94
|
-
ts.SyntaxKind.StringLiteral,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string,
|
|
100
|
-
fileName: string, isDefault = false): Change {
|
|
101
|
-
const rootNode = source;
|
|
102
|
-
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
103
|
-
|
|
104
|
-
// get nodes that map to import statements from the file fileName
|
|
105
|
-
const relevantImports = allImports.filter(node => {
|
|
106
|
-
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
107
|
-
const importFiles = node.getChildren()
|
|
108
|
-
.filter(child => child.kind === ts.SyntaxKind.StringLiteral)
|
|
109
|
-
.map(n => (n as ts.StringLiteral).text);
|
|
110
|
-
|
|
111
|
-
return importFiles.filter(file => file === fileName).length === 1;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (relevantImports.length > 0) {
|
|
115
|
-
let importsAsterisk = false;
|
|
116
|
-
// imports from import file
|
|
117
|
-
const imports: ts.Node[] = [];
|
|
118
|
-
relevantImports.forEach(n => {
|
|
119
|
-
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
|
120
|
-
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
121
|
-
importsAsterisk = true;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// if imports * from fileName, don't add symbolName
|
|
126
|
-
if (importsAsterisk) {
|
|
127
|
-
return new NoopChange();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
|
|
131
|
-
|
|
132
|
-
// insert import if it's not there
|
|
133
|
-
if (importTextNodes.length === 0) {
|
|
134
|
-
const fallbackPos =
|
|
135
|
-
findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
136
|
-
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
137
|
-
|
|
138
|
-
return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return new NoopChange();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// no such import declaration exists
|
|
145
|
-
const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
146
|
-
.filter((n: ts.StringLiteral) => n.text === 'use strict');
|
|
147
|
-
let fallbackPos = 0;
|
|
148
|
-
if (useStrict.length > 0) {
|
|
149
|
-
fallbackPos = useStrict[0].end;
|
|
150
|
-
}
|
|
151
|
-
const open = isDefault ? '' : '{ ';
|
|
152
|
-
const close = isDefault ? '' : ' }';
|
|
153
|
-
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
|
154
|
-
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
|
155
|
-
const separator = insertAtBeginning ? '' : ';\n';
|
|
156
|
-
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
|
157
|
-
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
158
|
-
|
|
159
|
-
return insertAfterLastOccurrence(
|
|
160
|
-
allImports,
|
|
161
|
-
toInsert,
|
|
162
|
-
fileToEdit,
|
|
163
|
-
fallbackPos,
|
|
164
|
-
ts.SyntaxKind.StringLiteral,
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
function getSourceFile(host: Tree, path: string): ts.SourceFile {
|
|
171
|
-
const buffer = host.read(path);
|
|
172
|
-
if (!buffer) {
|
|
173
|
-
throw new SchematicsException(`Could not find ${path}.`);
|
|
174
|
-
}
|
|
175
|
-
const content = buffer.toString();
|
|
176
|
-
const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
|
|
177
|
-
|
|
178
|
-
return source;
|
|
179
|
-
}
|
|
180
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import * as ts from 'typescript';
|
|
9
|
+
import { findNode, findNodes, insertAfterLastOccurrence } from "./ast-utils";
|
|
10
|
+
import { Change, InsertChange, NoopChange } from "./change";
|
|
11
|
+
import {SchematicsException, Tree} from "@angular-devkit/schematics";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Add Import `import { symbolName } from fileName` if the import doesn't exit
|
|
16
|
+
* already. Assumes fileToEdit can be resolved and accessed.
|
|
17
|
+
* @param fileToEdit (file we want to add import to)
|
|
18
|
+
* @param symbolName (item to import)
|
|
19
|
+
* @param fileName (path to the file)
|
|
20
|
+
* @param isDefault (if true, import follows style for importing default exports)
|
|
21
|
+
* @return Change
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function insertImport2(
|
|
25
|
+
source : ts.SourceFile,
|
|
26
|
+
fileToEdit : string,
|
|
27
|
+
symbolName : string,
|
|
28
|
+
asSymbolName: string,
|
|
29
|
+
fileName : string,
|
|
30
|
+
isDefault = false): Change {
|
|
31
|
+
const rootNode = source;
|
|
32
|
+
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
33
|
+
|
|
34
|
+
// get nodes that map to import statements from the file fileName
|
|
35
|
+
const relevantImports = allImports.filter(node => {
|
|
36
|
+
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
37
|
+
const importFiles = node.getChildren()
|
|
38
|
+
.filter(child => child.kind === ts.SyntaxKind.StringLiteral)
|
|
39
|
+
.map(n => (n as ts.StringLiteral).text);
|
|
40
|
+
|
|
41
|
+
return importFiles.filter(file => file === fileName).length === 1;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (relevantImports.length > 0) {
|
|
45
|
+
let importsAsterisk = false;
|
|
46
|
+
// imports from import file
|
|
47
|
+
const imports: ts.Node[] = [];
|
|
48
|
+
relevantImports.forEach(n => {
|
|
49
|
+
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
|
50
|
+
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
51
|
+
importsAsterisk = true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// if imports * from fileName, don't add symbolName
|
|
56
|
+
if (importsAsterisk) {
|
|
57
|
+
return new NoopChange();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
|
|
61
|
+
|
|
62
|
+
// insert import if it's not there
|
|
63
|
+
if (importTextNodes.length === 0) {
|
|
64
|
+
const fallbackPos =
|
|
65
|
+
findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
66
|
+
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
67
|
+
|
|
68
|
+
return insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return new NoopChange();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// no such import declaration exists
|
|
75
|
+
const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
76
|
+
.filter((n: ts.StringLiteral) => n.text === 'use strict');
|
|
77
|
+
let fallbackPos = 0;
|
|
78
|
+
if (useStrict.length > 0) {
|
|
79
|
+
fallbackPos = useStrict[0].end;
|
|
80
|
+
}
|
|
81
|
+
const open = isDefault ? '' : '{ ';
|
|
82
|
+
const close = isDefault ? '' : ' }';
|
|
83
|
+
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
|
84
|
+
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
|
85
|
+
const separator = insertAtBeginning ? '' : ';\n';
|
|
86
|
+
const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +
|
|
87
|
+
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
88
|
+
|
|
89
|
+
return insertAfterLastOccurrence(
|
|
90
|
+
allImports,
|
|
91
|
+
toInsert,
|
|
92
|
+
fileToEdit,
|
|
93
|
+
fallbackPos,
|
|
94
|
+
ts.SyntaxKind.StringLiteral,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string,
|
|
100
|
+
fileName: string, isDefault = false): Change {
|
|
101
|
+
const rootNode = source;
|
|
102
|
+
const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
103
|
+
|
|
104
|
+
// get nodes that map to import statements from the file fileName
|
|
105
|
+
const relevantImports = allImports.filter(node => {
|
|
106
|
+
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
107
|
+
const importFiles = node.getChildren()
|
|
108
|
+
.filter(child => child.kind === ts.SyntaxKind.StringLiteral)
|
|
109
|
+
.map(n => (n as ts.StringLiteral).text);
|
|
110
|
+
|
|
111
|
+
return importFiles.filter(file => file === fileName).length === 1;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (relevantImports.length > 0) {
|
|
115
|
+
let importsAsterisk = false;
|
|
116
|
+
// imports from import file
|
|
117
|
+
const imports: ts.Node[] = [];
|
|
118
|
+
relevantImports.forEach(n => {
|
|
119
|
+
Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));
|
|
120
|
+
if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
121
|
+
importsAsterisk = true;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// if imports * from fileName, don't add symbolName
|
|
126
|
+
if (importsAsterisk) {
|
|
127
|
+
return new NoopChange();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);
|
|
131
|
+
|
|
132
|
+
// insert import if it's not there
|
|
133
|
+
if (importTextNodes.length === 0) {
|
|
134
|
+
const fallbackPos =
|
|
135
|
+
findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
136
|
+
findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
137
|
+
|
|
138
|
+
return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return new NoopChange();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// no such import declaration exists
|
|
145
|
+
const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
146
|
+
.filter((n: ts.StringLiteral) => n.text === 'use strict');
|
|
147
|
+
let fallbackPos = 0;
|
|
148
|
+
if (useStrict.length > 0) {
|
|
149
|
+
fallbackPos = useStrict[0].end;
|
|
150
|
+
}
|
|
151
|
+
const open = isDefault ? '' : '{ ';
|
|
152
|
+
const close = isDefault ? '' : ' }';
|
|
153
|
+
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
|
154
|
+
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
|
155
|
+
const separator = insertAtBeginning ? '' : ';\n';
|
|
156
|
+
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
|
157
|
+
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
158
|
+
|
|
159
|
+
return insertAfterLastOccurrence(
|
|
160
|
+
allImports,
|
|
161
|
+
toInsert,
|
|
162
|
+
fileToEdit,
|
|
163
|
+
fallbackPos,
|
|
164
|
+
ts.SyntaxKind.StringLiteral,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
function getSourceFile(host: Tree, path: string): ts.SourceFile {
|
|
171
|
+
const buffer = host.read(path);
|
|
172
|
+
if (!buffer) {
|
|
173
|
+
throw new SchematicsException(`Could not find ${path}.`);
|
|
174
|
+
}
|
|
175
|
+
const content = buffer.toString();
|
|
176
|
+
const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
|
|
177
|
+
|
|
178
|
+
return source;
|
|
179
|
+
}
|
|
180
|
+
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function validateName(name: string): void;
|
|
1
|
+
export declare function validateName(name: string): void;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateName =
|
|
4
|
-
/**
|
|
5
|
-
* @license
|
|
6
|
-
* Copyright Google Inc. All Rights Reserved.
|
|
7
|
-
*
|
|
8
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
9
|
-
* found in the LICENSE file at https://angular.io/license
|
|
10
|
-
*/
|
|
11
|
-
const core_1 = require("@angular-devkit/core");
|
|
12
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
-
function validateName(name) {
|
|
14
|
-
if (name && /^\d/.test(name)) {
|
|
15
|
-
throw new schematics_1.SchematicsException(core_1.tags.oneLine `name (${name})
|
|
16
|
-
can not start with a digit.`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.validateName = validateName;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateName = validateName;
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
9
|
+
* found in the LICENSE file at https://angular.io/license
|
|
10
|
+
*/
|
|
11
|
+
const core_1 = require("@angular-devkit/core");
|
|
12
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
13
|
+
function validateName(name) {
|
|
14
|
+
if (name && /^\d/.test(name)) {
|
|
15
|
+
throw new schematics_1.SchematicsException(core_1.tags.oneLine `name (${name})
|
|
16
|
+
can not start with a digit.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
20
19
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["validation.ts"],"names":[],"mappings":";;AAUA,oCAKC;AAfD;;;;;;GAMG;AACH,+CAA4C;AAC5C,2DAAiE;AAEjE,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,gCAAmB,CAAC,WAAI,CAAC,OAAO,CAAA,SAAS,IAAI;oCACvB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","sourcesContent":["/**\r\n * @license\r\n * Copyright Google Inc. All Rights Reserved.\r\n *\r\n * Use of this source code is governed by an MIT-style license that can be\r\n * found in the LICENSE file at https://angular.io/license\r\n */\r\nimport { tags } from '@angular-devkit/core';\r\nimport { SchematicsException } from '@angular-devkit/schematics';\r\n\r\nexport function validateName(name: string): void {\r\n if (name && /^\\d/.test(name)) {\r\n throw new SchematicsException(tags.oneLine`name (${name})\r\n can not start with a digit.`);\r\n }\r\n}\r\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { tags } from '@angular-devkit/core';
|
|
9
|
-
import { SchematicsException } from '@angular-devkit/schematics';
|
|
10
|
-
|
|
11
|
-
export function validateName(name: string): void {
|
|
12
|
-
if (name && /^\d/.test(name)) {
|
|
13
|
-
throw new SchematicsException(tags.oneLine`name (${name})
|
|
14
|
-
can not start with a digit.`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import { tags } from '@angular-devkit/core';
|
|
9
|
+
import { SchematicsException } from '@angular-devkit/schematics';
|
|
10
|
+
|
|
11
|
+
export function validateName(name: string): void {
|
|
12
|
+
if (name && /^\d/.test(name)) {
|
|
13
|
+
throw new SchematicsException(tags.oneLine`name (${name})
|
|
14
|
+
can not start with a digit.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Tree } from '@angular-devkit/schematics';
|
|
2
|
-
import { Project } from './devkit-utils/config';
|
|
3
|
-
/**
|
|
4
|
-
* Parses the index.html file to get the HEAD tag position.
|
|
5
|
-
* @param host the tree we are traversing
|
|
6
|
-
* @param src the src path of the html file to parse
|
|
7
|
-
*/
|
|
8
|
-
export declare function getHeadTag(host: Tree, src: string): {
|
|
9
|
-
position: any;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Adds a link to the index.html head tag Example:
|
|
13
|
-
* `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
|
|
14
|
-
* @param host The tree we are updating
|
|
15
|
-
* @param project The project we're targeting.
|
|
16
|
-
* @param link html element string we are inserting.
|
|
17
|
-
*/
|
|
18
|
-
export declare function addHeadLink(host: Tree, project: Project, link: string): void;
|
|
1
|
+
import { Tree } from '@angular-devkit/schematics';
|
|
2
|
+
import { Project } from './devkit-utils/config';
|
|
3
|
+
/**
|
|
4
|
+
* Parses the index.html file to get the HEAD tag position.
|
|
5
|
+
* @param host the tree we are traversing
|
|
6
|
+
* @param src the src path of the html file to parse
|
|
7
|
+
*/
|
|
8
|
+
export declare function getHeadTag(host: Tree, src: string): {
|
|
9
|
+
position: any;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Adds a link to the index.html head tag Example:
|
|
13
|
+
* `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
|
|
14
|
+
* @param host The tree we are updating
|
|
15
|
+
* @param project The project we're targeting.
|
|
16
|
+
* @param link html element string we are inserting.
|
|
17
|
+
*/
|
|
18
|
+
export declare function addHeadLink(host: Tree, project: Project, link: string): void;
|
|
@@ -1,61 +1,60 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
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
|
-
* Adds a link to the index.html head tag Example:
|
|
40
|
-
* `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
|
|
41
|
-
* @param host The tree we are updating
|
|
42
|
-
* @param project The project we're targeting.
|
|
43
|
-
* @param link html element string we are inserting.
|
|
44
|
-
*/
|
|
45
|
-
function addHeadLink(host, project, link) {
|
|
46
|
-
const indexPath = (0, ast_1.getIndexHtmlPath)(host, project);
|
|
47
|
-
const buffer = host.read(indexPath);
|
|
48
|
-
if (!buffer) {
|
|
49
|
-
throw new schematics_1.SchematicsException(`Could not find file for path: ${indexPath}`);
|
|
50
|
-
}
|
|
51
|
-
const src = buffer.toString();
|
|
52
|
-
if (src.indexOf(link) === -1) {
|
|
53
|
-
const node = getHeadTag(host, src);
|
|
54
|
-
const insertion = new change_1.InsertChange(indexPath, node.position, link);
|
|
55
|
-
const recorder = host.beginUpdate(indexPath);
|
|
56
|
-
recorder.insertLeft(insertion.pos, insertion.toAdd);
|
|
57
|
-
host.commitUpdate(recorder);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.addHeadLink = addHeadLink;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHeadTag = getHeadTag;
|
|
4
|
+
exports.addHeadLink = addHeadLink;
|
|
5
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
|
+
const parse5 = require("parse5");
|
|
7
|
+
const ast_1 = require("./ast");
|
|
8
|
+
const change_1 = require("./devkit-utils/change");
|
|
9
|
+
/**
|
|
10
|
+
* Parses the index.html file to get the HEAD tag position.
|
|
11
|
+
* @param host the tree we are traversing
|
|
12
|
+
* @param src the src path of the html file to parse
|
|
13
|
+
*/
|
|
14
|
+
function getHeadTag(host, src) {
|
|
15
|
+
const document = parse5.parse(src, { locationInfo: true });
|
|
16
|
+
let head;
|
|
17
|
+
const visit = (nodes) => {
|
|
18
|
+
nodes.forEach(node => {
|
|
19
|
+
const element = node;
|
|
20
|
+
if (element.tagName === 'head') {
|
|
21
|
+
head = element;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (element.childNodes) {
|
|
25
|
+
visit(element.childNodes);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
visit(document.childNodes);
|
|
31
|
+
if (!head) {
|
|
32
|
+
throw new schematics_1.SchematicsException('Head element not found!');
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
position: head.__location.startTag.endOffset
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Adds a link to the index.html head tag Example:
|
|
40
|
+
* `<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`
|
|
41
|
+
* @param host The tree we are updating
|
|
42
|
+
* @param project The project we're targeting.
|
|
43
|
+
* @param link html element string we are inserting.
|
|
44
|
+
*/
|
|
45
|
+
function addHeadLink(host, project, link) {
|
|
46
|
+
const indexPath = (0, ast_1.getIndexHtmlPath)(host, project);
|
|
47
|
+
const buffer = host.read(indexPath);
|
|
48
|
+
if (!buffer) {
|
|
49
|
+
throw new schematics_1.SchematicsException(`Could not find file for path: ${indexPath}`);
|
|
50
|
+
}
|
|
51
|
+
const src = buffer.toString();
|
|
52
|
+
if (src.indexOf(link) === -1) {
|
|
53
|
+
const node = getHeadTag(host, src);
|
|
54
|
+
const insertion = new change_1.InsertChange(indexPath, node.position, link);
|
|
55
|
+
const recorder = host.beginUpdate(indexPath);
|
|
56
|
+
recorder.insertLeft(insertion.pos, insertion.toAdd);
|
|
57
|
+
host.commitUpdate(recorder);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
61
60
|
//# sourceMappingURL=html.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["html.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["html.ts"],"names":[],"mappings":";;AAWA,gCA2BC;AASD,kCAeC;AA9DD,2DAAqE;AACrE,iCAAiC;AACjC,+BAAuC;AACvC,kDAAmD;AAGnD;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAU,EAAE,GAAW;IAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAC/B,EAAC,YAAY,EAAE,IAAI,EAAC,CAAgC,CAAC;IAEvD,IAAI,IAAI,CAAC;IACT,MAAM,KAAK,GAAG,CAAC,KAAgC,EAAE,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACnB,MAAM,OAAO,GAA+B,IAAI,CAAC;YACjD,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;gBAC/B,IAAI,GAAG,OAAO,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACN,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;oBACvB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,gCAAmB,CAAC,yBAAyB,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS;KAC7C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,IAAU,EAAE,OAAgB,EAAE,IAAY;IACpE,MAAM,SAAS,GAAG,IAAA,sBAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,gCAAmB,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACnC,MAAM,SAAS,GAAG,IAAI,qBAAY,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC7C,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC","sourcesContent":["import {Tree, SchematicsException} from '@angular-devkit/schematics';\r\nimport * as parse5 from 'parse5';\r\nimport {getIndexHtmlPath} from './ast';\r\nimport {InsertChange} from './devkit-utils/change';\r\nimport {Project} from './devkit-utils/config';\r\n\r\n/**\r\n * Parses the index.html file to get the HEAD tag position.\r\n * @param host the tree we are traversing\r\n * @param src the src path of the html file to parse\r\n */\r\nexport function getHeadTag(host: Tree, src: string) {\r\n const document = parse5.parse(src,\r\n {locationInfo: true}) as parse5.AST.Default.Document;\r\n\r\n let head;\r\n const visit = (nodes: parse5.AST.Default.Node[]) => {\r\n nodes.forEach(node => {\r\n const element = <parse5.AST.Default.Element>node;\r\n if (element.tagName === 'head') {\r\n head = element;\r\n } else {\r\n if (element.childNodes) {\r\n visit(element.childNodes);\r\n }\r\n }\r\n });\r\n };\r\n\r\n visit(document.childNodes);\r\n\r\n if (!head) {\r\n throw new SchematicsException('Head element not found!');\r\n }\r\n\r\n return {\r\n position: head.__location.startTag.endOffset\r\n };\r\n}\r\n\r\n/**\r\n * Adds a link to the index.html head tag Example:\r\n * `<link href=\"https://fonts.googleapis.com/css?family=Roboto:300,400,500\" rel=\"stylesheet\">`\r\n * @param host The tree we are updating\r\n * @param project The project we're targeting.\r\n * @param link html element string we are inserting.\r\n */\r\nexport function addHeadLink(host: Tree, project: Project, link: string) {\r\n const indexPath = getIndexHtmlPath(host, project);\r\n const buffer = host.read(indexPath);\r\n if (!buffer) {\r\n throw new SchematicsException(`Could not find file for path: ${indexPath}`);\r\n }\r\n\r\n const src = buffer.toString();\r\n if (src.indexOf(link) === -1) {\r\n const node = getHeadTag(host, src);\r\n const insertion = new InsertChange(indexPath, node.position, link);\r\n const recorder = host.beginUpdate(indexPath);\r\n recorder.insertLeft(insertion.pos, insertion.toAdd);\r\n host.commitUpdate(recorder);\r\n }\r\n}\r\n"]}
|