@magic-xpa/cli 4.1201.0 → 4.1201.1
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.js.map +1 -1
- package/index.ts +1 -1
- package/package.json +1 -1
- package/src/collection.json +75 -75
- package/src/public_api.js.map +1 -1
- package/src/public_api.ts +5 -5
- 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.js.map +1 -1
- package/src/schematics/magic-utils/env.ts +50 -50
- 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.js.map +1 -1
- package/src/schematics/magic-utils/metadata.class.ts +159 -159
- 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.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +360 -360
- 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/magic-option.scheme.js.map +1 -1
- package/src/schematics/magic-utils/rules/magic-option.scheme.ts +24 -24
- 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.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/magic-styles.css +131 -131
- package/src/schematics/mg-add/schema.json +29 -29
- 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.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.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.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.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-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/schema.json +14 -14
- package/src/schematics/mg-single-control/schema.json +24 -24
- 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.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils.ts +570 -570
- 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.js.map +1 -1
- package/src/schematics/utils/devkit-utils/change.ts +127 -127
- 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.js.map +1 -1
- package/src/schematics/utils/devkit-utils/config.ts +120 -120
- 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.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ng-ast-utils.ts +84 -84
- 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.js.map +1 -1
- package/src/schematics/utils/devkit-utils/route-utils.ts +180 -180
- package/src/schematics/utils/devkit-utils/validation.js +1 -1
- 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.js.map +1 -1
- package/src/schematics/utils/html.ts +63 -63
- package/src/schematics/utils/lib-versions.js.map +1 -1
- package/src/schematics/utils/lib-versions.ts +3 -3
- package/src/schematics/utils/package.js.map +1 -1
- package/src/schematics/utils/package.ts +22 -22
- package/src/schematics/utils/testing.js.map +1 -1
- package/src/schematics/utils/testing.ts +25 -25
- 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.js.map +1 -1
- package/src/types/enums/generated-file-types.enum.ts +6 -6
- 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.js.map +1 -1
- package/src/types/enums/themes.enum.ts +6 -6
- package/src/types/index.js.map +1 -1
- package/src/types/index.ts +8 -8
- package/src/types/interfaces/app.js.map +1 -1
- package/src/types/interfaces/app.ts +89 -89
- package/src/types/interfaces/control.js.map +1 -1
- package/src/types/interfaces/control.ts +106 -106
- 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 +16 -16
- 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 +136 -136
- package/templates/themes/basicHTML/Code/theme.module.ts +10 -10
- package/templates/themes/basicHTML/combobox.ejs +37 -37
- package/templates/themes/basicHTML/edit.ejs +169 -169
- 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/combobox.ejs +58 -58
- package/templates/themes/material/edit.ejs +204 -204
- package/templates/themes/material/group.ejs +3 -3
- package/templates/themes/material/listbox.ejs +22 -22
- 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/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/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,84 +1,84 @@
|
|
|
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 { normalize } from '@angular-devkit/core';
|
|
9
|
-
import { SchematicsException, Tree } from '@angular-devkit/schematics';
|
|
10
|
-
import { dirname } from 'path';
|
|
11
|
-
import * as ts from 'typescript';
|
|
12
|
-
import { findNode, getSourceNodes } from './ast-utils';
|
|
13
|
-
|
|
14
|
-
export function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallExpression | null {
|
|
15
|
-
const mainBuffer = host.read(mainPath);
|
|
16
|
-
if (!mainBuffer) {
|
|
17
|
-
throw new SchematicsException(`Main file (${mainPath}) not found`);
|
|
18
|
-
}
|
|
19
|
-
const mainText = mainBuffer.toString('utf-8');
|
|
20
|
-
const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
|
|
21
|
-
|
|
22
|
-
const allNodes = getSourceNodes(source);
|
|
23
|
-
|
|
24
|
-
let bootstrapCall: ts.CallExpression | null = null;
|
|
25
|
-
|
|
26
|
-
for (const node of allNodes) {
|
|
27
|
-
|
|
28
|
-
let bootstrapCallNode: ts.Node | null = null;
|
|
29
|
-
bootstrapCallNode = findNode(node, ts.SyntaxKind.Identifier, 'bootstrapModule');
|
|
30
|
-
|
|
31
|
-
// Walk up the parent until CallExpression is found.
|
|
32
|
-
while (bootstrapCallNode && bootstrapCallNode.parent
|
|
33
|
-
&& bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) {
|
|
34
|
-
|
|
35
|
-
bootstrapCallNode = bootstrapCallNode.parent;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (bootstrapCallNode !== null &&
|
|
39
|
-
bootstrapCallNode.parent !== undefined &&
|
|
40
|
-
bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression) {
|
|
41
|
-
bootstrapCall = bootstrapCallNode.parent as ts.CallExpression;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return bootstrapCall;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function findBootstrapModulePath(host: Tree, mainPath: string): string {
|
|
50
|
-
const bootstrapCall = findBootstrapModuleCall(host, mainPath);
|
|
51
|
-
if (!bootstrapCall) {
|
|
52
|
-
throw new SchematicsException('Bootstrap call not found');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const bootstrapModule = bootstrapCall.arguments[0];
|
|
56
|
-
|
|
57
|
-
const mainBuffer = host.read(mainPath);
|
|
58
|
-
if (!mainBuffer) {
|
|
59
|
-
throw new SchematicsException(`Client app main file (${mainPath}) not found`);
|
|
60
|
-
}
|
|
61
|
-
const mainText = mainBuffer.toString('utf-8');
|
|
62
|
-
const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
|
|
63
|
-
const allNodes = getSourceNodes(source);
|
|
64
|
-
const bootstrapModuleRelativePath = allNodes
|
|
65
|
-
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
|
|
66
|
-
.filter(imp => {
|
|
67
|
-
return findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
|
|
68
|
-
})
|
|
69
|
-
.map((imp: ts.ImportDeclaration) => {
|
|
70
|
-
const modulePathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;
|
|
71
|
-
|
|
72
|
-
return modulePathStringLiteral.text;
|
|
73
|
-
})[0];
|
|
74
|
-
|
|
75
|
-
return bootstrapModuleRelativePath;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function getAppModulePath(host: Tree, mainPath: string): string {
|
|
79
|
-
const moduleRelativePath = findBootstrapModulePath(host, mainPath);
|
|
80
|
-
const mainDir = dirname(mainPath);
|
|
81
|
-
const modulePath = normalize(`/${mainDir}/${moduleRelativePath}.ts`);
|
|
82
|
-
|
|
83
|
-
return modulePath;
|
|
84
|
-
}
|
|
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 { normalize } from '@angular-devkit/core';
|
|
9
|
+
import { SchematicsException, Tree } from '@angular-devkit/schematics';
|
|
10
|
+
import { dirname } from 'path';
|
|
11
|
+
import * as ts from 'typescript';
|
|
12
|
+
import { findNode, getSourceNodes } from './ast-utils';
|
|
13
|
+
|
|
14
|
+
export function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallExpression | null {
|
|
15
|
+
const mainBuffer = host.read(mainPath);
|
|
16
|
+
if (!mainBuffer) {
|
|
17
|
+
throw new SchematicsException(`Main file (${mainPath}) not found`);
|
|
18
|
+
}
|
|
19
|
+
const mainText = mainBuffer.toString('utf-8');
|
|
20
|
+
const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
|
|
21
|
+
|
|
22
|
+
const allNodes = getSourceNodes(source);
|
|
23
|
+
|
|
24
|
+
let bootstrapCall: ts.CallExpression | null = null;
|
|
25
|
+
|
|
26
|
+
for (const node of allNodes) {
|
|
27
|
+
|
|
28
|
+
let bootstrapCallNode: ts.Node | null = null;
|
|
29
|
+
bootstrapCallNode = findNode(node, ts.SyntaxKind.Identifier, 'bootstrapModule');
|
|
30
|
+
|
|
31
|
+
// Walk up the parent until CallExpression is found.
|
|
32
|
+
while (bootstrapCallNode && bootstrapCallNode.parent
|
|
33
|
+
&& bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) {
|
|
34
|
+
|
|
35
|
+
bootstrapCallNode = bootstrapCallNode.parent;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (bootstrapCallNode !== null &&
|
|
39
|
+
bootstrapCallNode.parent !== undefined &&
|
|
40
|
+
bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression) {
|
|
41
|
+
bootstrapCall = bootstrapCallNode.parent as ts.CallExpression;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return bootstrapCall;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function findBootstrapModulePath(host: Tree, mainPath: string): string {
|
|
50
|
+
const bootstrapCall = findBootstrapModuleCall(host, mainPath);
|
|
51
|
+
if (!bootstrapCall) {
|
|
52
|
+
throw new SchematicsException('Bootstrap call not found');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const bootstrapModule = bootstrapCall.arguments[0];
|
|
56
|
+
|
|
57
|
+
const mainBuffer = host.read(mainPath);
|
|
58
|
+
if (!mainBuffer) {
|
|
59
|
+
throw new SchematicsException(`Client app main file (${mainPath}) not found`);
|
|
60
|
+
}
|
|
61
|
+
const mainText = mainBuffer.toString('utf-8');
|
|
62
|
+
const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
|
|
63
|
+
const allNodes = getSourceNodes(source);
|
|
64
|
+
const bootstrapModuleRelativePath = allNodes
|
|
65
|
+
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
|
|
66
|
+
.filter(imp => {
|
|
67
|
+
return findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
|
|
68
|
+
})
|
|
69
|
+
.map((imp: ts.ImportDeclaration) => {
|
|
70
|
+
const modulePathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;
|
|
71
|
+
|
|
72
|
+
return modulePathStringLiteral.text;
|
|
73
|
+
})[0];
|
|
74
|
+
|
|
75
|
+
return bootstrapModuleRelativePath;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getAppModulePath(host: Tree, mainPath: string): string {
|
|
79
|
+
const moduleRelativePath = findBootstrapModulePath(host, mainPath);
|
|
80
|
+
const mainDir = dirname(mainPath);
|
|
81
|
+
const modulePath = normalize(`/${mainDir}/${moduleRelativePath}.ts`);
|
|
82
|
+
|
|
83
|
+
return modulePath;
|
|
84
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["parse-name.ts"],"names":[],"mappings":";;AAeA,8BAQC;AAtBD;;;;;;GAMG;AACH,+CAA0E;AAO1E,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,MAAM,eAAe,GAAG,IAAA,eAAQ,EAAC,IAAY,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAS,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,IAAA,gBAAS,EAAC,GAAG,GAAG,QAAQ,CAAC;KAChC,CAAC;AACJ,CAAC","sourcesContent":["\
|
|
1
|
+
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["parse-name.ts"],"names":[],"mappings":";;AAeA,8BAQC;AAtBD;;;;;;GAMG;AACH,+CAA0E;AAO1E,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,MAAM,eAAe,GAAG,IAAA,eAAQ,EAAC,IAAY,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAS,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,IAAA,gBAAS,EAAC,GAAG,GAAG,QAAQ,CAAC;KAChC,CAAC;AACJ,CAAC","sourcesContent":["\n/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { Path, basename, dirname, normalize } from '@angular-devkit/core';\n\nexport interface Location {\n name: string;\n path: Path;\n}\n\nexport function parseName(path: string, name: string): Location {\n const nameWithoutPath = basename(name as Path);\n const namePath = dirname((path + '/' + name) as Path);\n\n return {\n name: nameWithoutPath,\n path: normalize('/' + namePath),\n };\n}\n"]}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @license
|
|
4
|
-
* Copyright Google Inc. All Rights Reserved.
|
|
5
|
-
*
|
|
6
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
-
* found in the LICENSE file at https://angular.io/license
|
|
8
|
-
*/
|
|
9
|
-
import { Path, basename, dirname, normalize } from '@angular-devkit/core';
|
|
10
|
-
|
|
11
|
-
export interface Location {
|
|
12
|
-
name: string;
|
|
13
|
-
path: Path;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function parseName(path: string, name: string): Location {
|
|
17
|
-
const nameWithoutPath = basename(name as Path);
|
|
18
|
-
const namePath = dirname((path + '/' + name) as Path);
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
name: nameWithoutPath,
|
|
22
|
-
path: normalize('/' + namePath),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
import { Path, basename, dirname, normalize } from '@angular-devkit/core';
|
|
10
|
+
|
|
11
|
+
export interface Location {
|
|
12
|
+
name: string;
|
|
13
|
+
path: Path;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function parseName(path: string, name: string): Location {
|
|
17
|
+
const nameWithoutPath = basename(name as Path);
|
|
18
|
+
const namePath = dirname((path + '/' + name) as Path);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
name: nameWithoutPath,
|
|
22
|
+
path: normalize('/' + namePath),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
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,CAAC,aAAa,CAC5B,CAAC;AACJ,CAAC;AAID,SAAS,aAAa,CAAC,IAAU,EAAE,IAAY;IAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,gCAAmB,CAAC,kBAAkB,IAAI,GAAG,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEhF,OAAO,MAAM,CAAC;AAChB,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 * as ts from 'typescript';\r\nimport { findNode, findNodes, insertAfterLastOccurrence } from \"./ast-utils\";\r\nimport { Change, InsertChange, NoopChange } from \"./change\";\r\nimport {SchematicsException, Tree} from \"@angular-devkit/schematics\";\r\n\r\n\r\n/**\r\n* Add Import `import { symbolName } from fileName` if the import doesn't exit\r\n* already. Assumes fileToEdit can be resolved and accessed.\r\n* @param fileToEdit (file we want to add import to)\r\n* @param symbolName (item to import)\r\n* @param fileName (path to the file)\r\n* @param isDefault (if true, import follows style for importing default exports)\r\n* @return Change\r\n*/\r\n\r\nexport function insertImport2(\r\n source : ts.SourceFile,\r\n fileToEdit : string,\r\n symbolName : string,\r\n asSymbolName: string,\r\n fileName : string,\r\n isDefault = false): Change {\r\n const rootNode = source;\r\n const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);\r\n\r\n // get nodes that map to import statements from the file fileName\r\n const relevantImports = allImports.filter(node => {\r\n // StringLiteral of the ImportDeclaration is the import file (fileName in this case).\r\n const importFiles = node.getChildren()\r\n .filter(child => child.kind === ts.SyntaxKind.StringLiteral)\r\n .map(n => (n as ts.StringLiteral).text);\r\n\r\n return importFiles.filter(file => file === fileName).length === 1;\r\n });\r\n\r\n if (relevantImports.length > 0) {\r\n let importsAsterisk = false;\r\n // imports from import file\r\n const imports: ts.Node[] = [];\r\n relevantImports.forEach(n => {\r\n Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));\r\n if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {\r\n importsAsterisk = true;\r\n }\r\n });\r\n\r\n // if imports * from fileName, don't add symbolName\r\n if (importsAsterisk) {\r\n return new NoopChange();\r\n }\r\n\r\n const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);\r\n\r\n // insert import if it's not there\r\n if (importTextNodes.length === 0) {\r\n const fallbackPos =\r\n findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||\r\n findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();\r\n\r\n return insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);\r\n }\r\n\r\n return new NoopChange();\r\n }\r\n\r\n // no such import declaration exists\r\n const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)\r\n .filter((n: ts.StringLiteral) => n.text === 'use strict');\r\n let fallbackPos = 0;\r\n if (useStrict.length > 0) {\r\n fallbackPos = useStrict[0].end;\r\n }\r\n const open = isDefault ? '' : '{ ';\r\n const close = isDefault ? '' : ' }';\r\n // if there are no imports or 'use strict' statement, insert import at beginning of file\r\n const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;\r\n const separator = insertAtBeginning ? '' : ';\\n';\r\n const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +\r\n ` from '${fileName}'${insertAtBeginning ? ';\\n' : ''}`;\r\n\r\n return insertAfterLastOccurrence(\r\n allImports,\r\n toInsert,\r\n fileToEdit,\r\n fallbackPos,\r\n ts.SyntaxKind.StringLiteral,\r\n );\r\n}\r\n\r\n\r\nexport function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string,\r\n fileName: string, isDefault = false): Change {\r\n const rootNode = source;\r\n const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);\r\n\r\n // get nodes that map to import statements from the file fileName\r\n const relevantImports = allImports.filter(node => {\r\n // StringLiteral of the ImportDeclaration is the import file (fileName in this case).\r\n const importFiles = node.getChildren()\r\n .filter(child => child.kind === ts.SyntaxKind.StringLiteral)\r\n .map(n => (n as ts.StringLiteral).text);\r\n\r\n return importFiles.filter(file => file === fileName).length === 1;\r\n });\r\n\r\n if (relevantImports.length > 0) {\r\n let importsAsterisk = false;\r\n // imports from import file\r\n const imports: ts.Node[] = [];\r\n relevantImports.forEach(n => {\r\n Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));\r\n if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {\r\n importsAsterisk = true;\r\n }\r\n });\r\n\r\n // if imports * from fileName, don't add symbolName\r\n if (importsAsterisk) {\r\n return new NoopChange();\r\n }\r\n\r\n const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);\r\n\r\n // insert import if it's not there\r\n if (importTextNodes.length === 0) {\r\n const fallbackPos =\r\n findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||\r\n findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();\r\n\r\n return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);\r\n }\r\n\r\n return new NoopChange();\r\n }\r\n\r\n // no such import declaration exists\r\n const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)\r\n .filter((n: ts.StringLiteral) => n.text === 'use strict');\r\n let fallbackPos = 0;\r\n if (useStrict.length > 0) {\r\n fallbackPos = useStrict[0].end;\r\n }\r\n const open = isDefault ? '' : '{ ';\r\n const close = isDefault ? '' : ' }';\r\n // if there are no imports or 'use strict' statement, insert import at beginning of file\r\n const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;\r\n const separator = insertAtBeginning ? '' : ';\\n';\r\n const toInsert = `${separator}import ${open}${symbolName}${close}` +\r\n ` from '${fileName}'${insertAtBeginning ? ';\\n' : ''}`;\r\n\r\n return insertAfterLastOccurrence(\r\n allImports,\r\n toInsert,\r\n fileToEdit,\r\n fallbackPos,\r\n ts.SyntaxKind.StringLiteral,\r\n );\r\n}\r\n\r\n\r\n\r\nfunction getSourceFile(host: Tree, path: string): ts.SourceFile {\r\n const buffer = host.read(path);\r\n if (!buffer) {\r\n throw new SchematicsException(`Could not find ${path}.`);\r\n }\r\n const content = buffer.toString();\r\n const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);\r\n\r\n return source;\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"route-utils.js","sourceRoot":"","sources":["route-utils.ts"],"names":[],"mappings":";;AAuBA,sCAwEC;AAGD,oCAmEC;AArKD;;;;;;GAMG;AACH,iCAAiC;AACjC,2CAA6E;AAC7E,qCAA4D;AAC5D,2DAAqE;AAGrE;;;;;;;;EAQE;AAEF,SAAgB,aAAa,CAC3B,MAA2B,EAC3B,UAAoB,EACpB,UAAoB,EACpB,YAAoB,EACpB,QAAoB,EACpB,SAAS,GAAG,KAAK;IACjB,MAAM,QAAQ,GAAG,MAAM,CAAC;IACxB,MAAM,UAAU,GAAG,IAAA,qBAAS,EAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAExE,iEAAiE;IACjE,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QAC/C,qFAAqF;QACrF,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE;aACnC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;aAC3D,GAAG,CAAC,CAAC,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AAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACpC,wFAAwF;IACxF,MAAM,iBAAiB,GAAG,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAC5E,MAAM,SAAS,GAAG,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACjD,MAAM,QAAQ,GAAG,GAAG,SAAS,UAAU,IAAI,GAAG,UAAU,GAAG,KAAK,EAAE;QAChE,UAAU,QAAQ,IAAI,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEzD,OAAO,IAAA,qCAAyB,EAC9B,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,EACX,EAAE,CAAC,UAAU,CAAC,aAAa,CAC5B,CAAC;AACJ,CAAC;AAID,SAAS,aAAa,CAAC,IAAU,EAAE,IAAY;IAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,gCAAmB,CAAC,kBAAkB,IAAI,GAAG,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEhF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport * as ts from 'typescript';\nimport { findNode, findNodes, insertAfterLastOccurrence } from \"./ast-utils\";\nimport { Change, InsertChange, NoopChange } from \"./change\";\nimport {SchematicsException, Tree} from \"@angular-devkit/schematics\";\n\n\n/**\n* Add Import `import { symbolName } from fileName` if the import doesn't exit\n* already. Assumes fileToEdit can be resolved and accessed.\n* @param fileToEdit (file we want to add import to)\n* @param symbolName (item to import)\n* @param fileName (path to the file)\n* @param isDefault (if true, import follows style for importing default exports)\n* @return Change\n*/\n\nexport function insertImport2(\n source : ts.SourceFile,\n fileToEdit : string,\n symbolName : string,\n asSymbolName: string,\n fileName : string,\n isDefault = false): Change {\n const rootNode = source;\n const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);\n\n // get nodes that map to import statements from the file fileName\n const relevantImports = allImports.filter(node => {\n // StringLiteral of the ImportDeclaration is the import file (fileName in this case).\n const importFiles = node.getChildren()\n .filter(child => child.kind === ts.SyntaxKind.StringLiteral)\n .map(n => (n as ts.StringLiteral).text);\n\n return importFiles.filter(file => file === fileName).length === 1;\n });\n\n if (relevantImports.length > 0) {\n let importsAsterisk = false;\n // imports from import file\n const imports: ts.Node[] = [];\n relevantImports.forEach(n => {\n Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));\n if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {\n importsAsterisk = true;\n }\n });\n\n // if imports * from fileName, don't add symbolName\n if (importsAsterisk) {\n return new NoopChange();\n }\n\n const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);\n\n // insert import if it's not there\n if (importTextNodes.length === 0) {\n const fallbackPos =\n findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||\n findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();\n\n return insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);\n }\n\n return new NoopChange();\n }\n\n // no such import declaration exists\n const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)\n .filter((n: ts.StringLiteral) => n.text === 'use strict');\n let fallbackPos = 0;\n if (useStrict.length > 0) {\n fallbackPos = useStrict[0].end;\n }\n const open = isDefault ? '' : '{ ';\n const close = isDefault ? '' : ' }';\n // if there are no imports or 'use strict' statement, insert import at beginning of file\n const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;\n const separator = insertAtBeginning ? '' : ';\\n';\n const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +\n ` from '${fileName}'${insertAtBeginning ? ';\\n' : ''}`;\n\n return insertAfterLastOccurrence(\n allImports,\n toInsert,\n fileToEdit,\n fallbackPos,\n ts.SyntaxKind.StringLiteral,\n );\n}\n\n\nexport function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string,\n fileName: string, isDefault = false): Change {\n const rootNode = source;\n const allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);\n\n // get nodes that map to import statements from the file fileName\n const relevantImports = allImports.filter(node => {\n // StringLiteral of the ImportDeclaration is the import file (fileName in this case).\n const importFiles = node.getChildren()\n .filter(child => child.kind === ts.SyntaxKind.StringLiteral)\n .map(n => (n as ts.StringLiteral).text);\n\n return importFiles.filter(file => file === fileName).length === 1;\n });\n\n if (relevantImports.length > 0) {\n let importsAsterisk = false;\n // imports from import file\n const imports: ts.Node[] = [];\n relevantImports.forEach(n => {\n Array.prototype.push.apply(imports, findNodes(n, ts.SyntaxKind.Identifier));\n if (findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {\n importsAsterisk = true;\n }\n });\n\n // if imports * from fileName, don't add symbolName\n if (importsAsterisk) {\n return new NoopChange();\n }\n\n const importTextNodes = imports.filter(n => (n as ts.Identifier).text === symbolName);\n\n // insert import if it's not there\n if (importTextNodes.length === 0) {\n const fallbackPos =\n findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||\n findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();\n\n return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);\n }\n\n return new NoopChange();\n }\n\n // no such import declaration exists\n const useStrict = findNodes(rootNode, ts.SyntaxKind.StringLiteral)\n .filter((n: ts.StringLiteral) => n.text === 'use strict');\n let fallbackPos = 0;\n if (useStrict.length > 0) {\n fallbackPos = useStrict[0].end;\n }\n const open = isDefault ? '' : '{ ';\n const close = isDefault ? '' : ' }';\n // if there are no imports or 'use strict' statement, insert import at beginning of file\n const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;\n const separator = insertAtBeginning ? '' : ';\\n';\n const toInsert = `${separator}import ${open}${symbolName}${close}` +\n ` from '${fileName}'${insertAtBeginning ? ';\\n' : ''}`;\n\n return insertAfterLastOccurrence(\n allImports,\n toInsert,\n fileToEdit,\n fallbackPos,\n ts.SyntaxKind.StringLiteral,\n );\n}\n\n\n\nfunction getSourceFile(host: Tree, path: string): ts.SourceFile {\n const buffer = host.read(path);\n if (!buffer) {\n throw new SchematicsException(`Could not find ${path}.`);\n }\n const content = buffer.toString();\n const source = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);\n\n return source;\n}\n\n"]}
|
|
@@ -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
|
+
|