@abp/ng.schematics 5.0.1 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/README.md +3 -3
  2. package/collection.json +29 -29
  3. package/commands/api/files-enum/proxy/__namespace@dir__/__name@kebab__.enum.ts.template +8 -8
  4. package/commands/api/files-model/proxy/__namespace@dir__/models.ts.template +9 -9
  5. package/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template +25 -25
  6. package/commands/api/index.d.ts +2 -2
  7. package/commands/api/index.js +112 -112
  8. package/commands/api/schema.json +45 -45
  9. package/commands/proxy-add/index.d.ts +2 -2
  10. package/commands/proxy-add/index.js +41 -41
  11. package/commands/proxy-add/schema.json +45 -45
  12. package/commands/proxy-index/index.d.ts +4 -4
  13. package/commands/proxy-index/index.js +14 -14
  14. package/commands/proxy-index/schema.json +18 -18
  15. package/commands/proxy-refresh/index.d.ts +3 -3
  16. package/commands/proxy-refresh/index.js +27 -27
  17. package/commands/proxy-refresh/schema.json +45 -45
  18. package/commands/proxy-remove/index.d.ts +3 -3
  19. package/commands/proxy-remove/index.js +33 -33
  20. package/commands/proxy-remove/schema.json +45 -45
  21. package/constants/api.d.ts +1 -1
  22. package/constants/api.js +4 -4
  23. package/constants/index.d.ts +4 -4
  24. package/constants/index.js +16 -16
  25. package/constants/proxy.d.ts +4 -4
  26. package/constants/proxy.js +24 -24
  27. package/constants/system-types.d.ts +1 -1
  28. package/constants/system-types.js +27 -27
  29. package/constants/volo.d.ts +1 -1
  30. package/constants/volo.js +4 -4
  31. package/enums/binding-source-id.d.ts +6 -6
  32. package/enums/binding-source-id.js +10 -10
  33. package/enums/exception.d.ts +16 -16
  34. package/enums/exception.js +2 -2
  35. package/enums/import-keyword.d.ts +4 -4
  36. package/enums/import-keyword.js +8 -8
  37. package/enums/index.d.ts +4 -4
  38. package/enums/index.js +16 -16
  39. package/enums/method-modifier.d.ts +6 -6
  40. package/enums/method-modifier.js +10 -10
  41. package/index.d.ts +1 -1
  42. package/index.js +2 -2
  43. package/models/api-definition.d.ts +72 -72
  44. package/models/api-definition.js +2 -2
  45. package/models/generate-proxy-schema.d.ts +18 -18
  46. package/models/generate-proxy-schema.js +2 -2
  47. package/models/import.d.ts +11 -11
  48. package/models/import.js +13 -13
  49. package/models/index.d.ts +10 -10
  50. package/models/index.js +22 -22
  51. package/models/method.d.ts +31 -31
  52. package/models/method.js +61 -61
  53. package/models/model.d.ts +48 -48
  54. package/models/model.js +71 -71
  55. package/models/project.d.ts +5 -5
  56. package/models/project.js +2 -2
  57. package/models/proxy-config.d.ts +4 -4
  58. package/models/proxy-config.js +2 -2
  59. package/models/service.d.ts +21 -21
  60. package/models/service.js +11 -11
  61. package/models/tree.d.ts +1 -1
  62. package/models/tree.js +2 -2
  63. package/models/util.d.ts +7 -7
  64. package/models/util.js +2 -2
  65. package/package.json +1 -1
  66. package/test-setup.d.ts +1 -1
  67. package/test-setup.js +3 -3
  68. package/utils/angular/ast-utils.d.ts +115 -115
  69. package/utils/angular/ast-utils.js +598 -598
  70. package/utils/angular/change.d.ts +66 -66
  71. package/utils/angular/change.js +96 -96
  72. package/utils/angular/config.d.ts +455 -455
  73. package/utils/angular/config.js +70 -70
  74. package/utils/angular/dependencies.d.ts +23 -23
  75. package/utils/angular/dependencies.js +58 -58
  76. package/utils/angular/find-module.d.ts +35 -35
  77. package/utils/angular/find-module.js +105 -105
  78. package/utils/angular/index.d.ts +17 -17
  79. package/utils/angular/index.js +29 -29
  80. package/utils/angular/json-file.d.ts +23 -23
  81. package/utils/angular/json-file.js +61 -61
  82. package/utils/angular/json-utils.d.ts +14 -14
  83. package/utils/angular/json-utils.js +158 -158
  84. package/utils/angular/latest-versions.d.ts +18 -18
  85. package/utils/angular/latest-versions.js +26 -26
  86. package/utils/angular/lint-fix.d.ts +9 -9
  87. package/utils/angular/lint-fix.js +41 -41
  88. package/utils/angular/ng-ast-utils.d.ts +5 -5
  89. package/utils/angular/ng-ast-utils.js +75 -75
  90. package/utils/angular/parse-name.d.ts +13 -13
  91. package/utils/angular/parse-name.js +21 -21
  92. package/utils/angular/paths.d.ts +8 -8
  93. package/utils/angular/paths.js +21 -21
  94. package/utils/angular/project-targets.d.ts +9 -9
  95. package/utils/angular/project-targets.js +15 -15
  96. package/utils/angular/tsconfig.d.ts +16 -16
  97. package/utils/angular/tsconfig.js +62 -62
  98. package/utils/angular/validation.d.ts +4 -4
  99. package/utils/angular/validation.js +73 -73
  100. package/utils/angular/workspace-models.d.ts +159 -159
  101. package/utils/angular/workspace-models.js +29 -29
  102. package/utils/angular/workspace.d.ts +18 -18
  103. package/utils/angular/workspace.js +75 -75
  104. package/utils/api.d.ts +2 -2
  105. package/utils/api.js +8 -8
  106. package/utils/ast.d.ts +4 -4
  107. package/utils/ast.js +23 -23
  108. package/utils/barrel.d.ts +4 -4
  109. package/utils/barrel.js +92 -92
  110. package/utils/common.d.ts +6 -6
  111. package/utils/common.js +33 -33
  112. package/utils/enum.d.ts +18 -18
  113. package/utils/enum.js +40 -40
  114. package/utils/file.d.ts +2 -2
  115. package/utils/file.js +9 -9
  116. package/utils/generics.d.ts +24 -24
  117. package/utils/generics.js +87 -87
  118. package/utils/import.d.ts +3 -3
  119. package/utils/import.js +11 -11
  120. package/utils/index.d.ts +19 -19
  121. package/utils/index.js +31 -31
  122. package/utils/model.d.ts +11 -11
  123. package/utils/model.js +141 -141
  124. package/utils/namespace.d.ts +1 -1
  125. package/utils/namespace.js +18 -18
  126. package/utils/path.d.ts +2 -2
  127. package/utils/path.js +36 -36
  128. package/utils/rule.d.ts +4 -4
  129. package/utils/rule.js +27 -27
  130. package/utils/service.d.ts +6 -6
  131. package/utils/service.js +82 -82
  132. package/utils/source.d.ts +13 -13
  133. package/utils/source.js +162 -162
  134. package/utils/text.d.ts +9 -9
  135. package/utils/text.js +46 -46
  136. package/utils/tree.d.ts +13 -13
  137. package/utils/tree.js +56 -56
  138. package/utils/type.d.ts +12 -12
  139. package/utils/type.js +102 -102
  140. package/utils/workspace.d.ts +8 -8
  141. package/utils/workspace.js +66 -66
@@ -1,30 +1,30 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./ast-utils"), exports);
14
- __exportStar(require("./change"), exports);
15
- __exportStar(require("./config"), exports);
16
- __exportStar(require("./dependencies"), exports);
17
- __exportStar(require("./find-module"), exports);
18
- __exportStar(require("./json-file"), exports);
19
- __exportStar(require("./json-utils"), exports);
20
- __exportStar(require("./latest-versions"), exports);
21
- __exportStar(require("./lint-fix"), exports);
22
- __exportStar(require("./ng-ast-utils"), exports);
23
- __exportStar(require("./parse-name"), exports);
24
- __exportStar(require("./paths"), exports);
25
- __exportStar(require("./project-targets"), exports);
26
- __exportStar(require("./tsconfig"), exports);
27
- __exportStar(require("./validation"), exports);
28
- __exportStar(require("./workspace"), exports);
29
- __exportStar(require("./workspace-models"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./ast-utils"), exports);
14
+ __exportStar(require("./change"), exports);
15
+ __exportStar(require("./config"), exports);
16
+ __exportStar(require("./dependencies"), exports);
17
+ __exportStar(require("./find-module"), exports);
18
+ __exportStar(require("./json-file"), exports);
19
+ __exportStar(require("./json-utils"), exports);
20
+ __exportStar(require("./latest-versions"), exports);
21
+ __exportStar(require("./lint-fix"), exports);
22
+ __exportStar(require("./ng-ast-utils"), exports);
23
+ __exportStar(require("./parse-name"), exports);
24
+ __exportStar(require("./paths"), exports);
25
+ __exportStar(require("./project-targets"), exports);
26
+ __exportStar(require("./tsconfig"), exports);
27
+ __exportStar(require("./validation"), exports);
28
+ __exportStar(require("./workspace"), exports);
29
+ __exportStar(require("./workspace-models"), exports);
30
30
  //# sourceMappingURL=index.js.map
@@ -1,23 +1,23 @@
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 { JsonValue } from '@angular-devkit/core';
9
- import { Tree } from '@angular-devkit/schematics';
10
- export declare type JSONPath = (string | number)[];
11
- /** @internal */
12
- export declare class JSONFile {
13
- private readonly host;
14
- private readonly path;
15
- private content;
16
- error: undefined | Error;
17
- constructor(host: Tree, path: string);
18
- private _jsonAst;
19
- private get JsonAst();
20
- get(jsonPath: JSONPath): unknown;
21
- modify(jsonPath: JSONPath, value: JsonValue | undefined, getInsertionIndex?: (properties: string[]) => number): void;
22
- remove(jsonPath: JSONPath): void;
23
- }
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 { JsonValue } from '@angular-devkit/core';
9
+ import { Tree } from '@angular-devkit/schematics';
10
+ export declare type JSONPath = (string | number)[];
11
+ /** @internal */
12
+ export declare class JSONFile {
13
+ private readonly host;
14
+ private readonly path;
15
+ private content;
16
+ error: undefined | Error;
17
+ constructor(host: Tree, path: string);
18
+ private _jsonAst;
19
+ private get JsonAst();
20
+ get(jsonPath: JSONPath): unknown;
21
+ modify(jsonPath: JSONPath, value: JsonValue | undefined, getInsertionIndex?: (properties: string[]) => number): void;
22
+ remove(jsonPath: JSONPath): void;
23
+ }
@@ -1,62 +1,62 @@
1
- "use strict";
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
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.JSONFile = void 0;
11
- const jsonc_parser_1 = require("jsonc-parser");
12
- /** @internal */
13
- class JSONFile {
14
- constructor(host, path) {
15
- this.host = host;
16
- this.path = path;
17
- const buffer = this.host.read(this.path);
18
- if (buffer) {
19
- this.content = buffer.toString();
20
- }
21
- else {
22
- this.error = new Error(`Could not read ${path}.`);
23
- }
24
- }
25
- get JsonAst() {
26
- if (this._jsonAst) {
27
- return this._jsonAst;
28
- }
29
- this._jsonAst = jsonc_parser_1.parseTree(this.content);
30
- return this._jsonAst;
31
- }
32
- get(jsonPath) {
33
- if (jsonPath.length === 0) {
34
- return jsonc_parser_1.getNodeValue(this.JsonAst);
35
- }
36
- const node = jsonc_parser_1.findNodeAtLocation(this.JsonAst, jsonPath);
37
- return node === undefined ? undefined : jsonc_parser_1.getNodeValue(node);
38
- }
39
- modify(jsonPath, value, getInsertionIndex) {
40
- if (!getInsertionIndex) {
41
- const property = jsonPath.slice(-1)[0];
42
- getInsertionIndex = properties => [...properties, property].sort().findIndex(p => p === property);
43
- }
44
- const edits = jsonc_parser_1.modify(this.content, jsonPath, value, {
45
- getInsertionIndex,
46
- formattingOptions: {
47
- insertSpaces: true,
48
- tabSize: 2,
49
- },
50
- });
51
- this.content = jsonc_parser_1.applyEdits(this.content, edits);
52
- this.host.overwrite(this.path, this.content);
53
- this._jsonAst = undefined;
54
- }
55
- remove(jsonPath) {
56
- if (this.get(jsonPath) !== undefined) {
57
- this.modify(jsonPath, undefined);
58
- }
59
- }
60
- }
61
- exports.JSONFile = JSONFile;
1
+ "use strict";
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
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.JSONFile = void 0;
11
+ const jsonc_parser_1 = require("jsonc-parser");
12
+ /** @internal */
13
+ class JSONFile {
14
+ constructor(host, path) {
15
+ this.host = host;
16
+ this.path = path;
17
+ const buffer = this.host.read(this.path);
18
+ if (buffer) {
19
+ this.content = buffer.toString();
20
+ }
21
+ else {
22
+ this.error = new Error(`Could not read ${path}.`);
23
+ }
24
+ }
25
+ get JsonAst() {
26
+ if (this._jsonAst) {
27
+ return this._jsonAst;
28
+ }
29
+ this._jsonAst = jsonc_parser_1.parseTree(this.content);
30
+ return this._jsonAst;
31
+ }
32
+ get(jsonPath) {
33
+ if (jsonPath.length === 0) {
34
+ return jsonc_parser_1.getNodeValue(this.JsonAst);
35
+ }
36
+ const node = jsonc_parser_1.findNodeAtLocation(this.JsonAst, jsonPath);
37
+ return node === undefined ? undefined : jsonc_parser_1.getNodeValue(node);
38
+ }
39
+ modify(jsonPath, value, getInsertionIndex) {
40
+ if (!getInsertionIndex) {
41
+ const property = jsonPath.slice(-1)[0];
42
+ getInsertionIndex = properties => [...properties, property].sort().findIndex(p => p === property);
43
+ }
44
+ const edits = jsonc_parser_1.modify(this.content, jsonPath, value, {
45
+ getInsertionIndex,
46
+ formattingOptions: {
47
+ insertSpaces: true,
48
+ tabSize: 2,
49
+ },
50
+ });
51
+ this.content = jsonc_parser_1.applyEdits(this.content, edits);
52
+ this.host.overwrite(this.path, this.content);
53
+ this._jsonAst = undefined;
54
+ }
55
+ remove(jsonPath) {
56
+ if (this.get(jsonPath) !== undefined) {
57
+ this.modify(jsonPath, undefined);
58
+ }
59
+ }
60
+ }
61
+ exports.JSONFile = JSONFile;
62
62
  //# sourceMappingURL=json-file.js.map
@@ -1,14 +1,14 @@
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 { JsonAstArray, JsonAstNode, JsonAstObject, JsonValue } from '@angular-devkit/core';
9
- import { UpdateRecorder } from '@angular-devkit/schematics';
10
- export declare function appendPropertyInAstObject(recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, indent: number): void;
11
- export declare function insertPropertyInAstObjectInOrder(recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, indent: number): void;
12
- export declare function removePropertyInAstObject(recorder: UpdateRecorder, node: JsonAstObject, propertyName: string): void;
13
- export declare function appendValueInAstArray(recorder: UpdateRecorder, node: JsonAstArray, value: JsonValue, indent?: number): void;
14
- export declare function findPropertyInAstObject(node: JsonAstObject, propertyName: string): JsonAstNode | null;
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 { JsonAstArray, JsonAstNode, JsonAstObject, JsonValue } from '@angular-devkit/core';
9
+ import { UpdateRecorder } from '@angular-devkit/schematics';
10
+ export declare function appendPropertyInAstObject(recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, indent: number): void;
11
+ export declare function insertPropertyInAstObjectInOrder(recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue, indent: number): void;
12
+ export declare function removePropertyInAstObject(recorder: UpdateRecorder, node: JsonAstObject, propertyName: string): void;
13
+ export declare function appendValueInAstArray(recorder: UpdateRecorder, node: JsonAstArray, value: JsonValue, indent?: number): void;
14
+ export declare function findPropertyInAstObject(node: JsonAstObject, propertyName: string): JsonAstNode | null;
@@ -1,159 +1,159 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findPropertyInAstObject = exports.appendValueInAstArray = exports.removePropertyInAstObject = exports.insertPropertyInAstObjectInOrder = exports.appendPropertyInAstObject = void 0;
4
- function appendPropertyInAstObject(recorder, node, propertyName, value, indent) {
5
- const indentStr = _buildIndent(indent);
6
- let index = node.start.offset + 1;
7
- if (node.properties.length > 0) {
8
- // Insert comma.
9
- const last = node.properties[node.properties.length - 1];
10
- const { text, end } = last;
11
- const commaIndex = text.endsWith('\n') ? end.offset - 1 : end.offset;
12
- recorder.insertRight(commaIndex, ',');
13
- index = end.offset;
14
- }
15
- const content = _stringifyContent(value, indentStr);
16
- recorder.insertRight(index, (node.properties.length === 0 && indent ? '\n' : '') +
17
- ' '.repeat(indent) +
18
- `"${propertyName}":${indent ? ' ' : ''}${content}` +
19
- indentStr.slice(0, -indent));
20
- }
21
- exports.appendPropertyInAstObject = appendPropertyInAstObject;
22
- function insertPropertyInAstObjectInOrder(recorder, node, propertyName, value, indent) {
23
- if (node.properties.length === 0) {
24
- appendPropertyInAstObject(recorder, node, propertyName, value, indent);
25
- return;
26
- }
27
- // Find insertion info.
28
- let insertAfterProp = null;
29
- let prev = null;
30
- let isLastProp = false;
31
- const last = node.properties[node.properties.length - 1];
32
- for (const prop of node.properties) {
33
- if (prop.key.value > propertyName) {
34
- if (prev) {
35
- insertAfterProp = prev;
36
- }
37
- break;
38
- }
39
- if (prop === last) {
40
- isLastProp = true;
41
- insertAfterProp = last;
42
- }
43
- prev = prop;
44
- }
45
- if (isLastProp) {
46
- appendPropertyInAstObject(recorder, node, propertyName, value, indent);
47
- return;
48
- }
49
- const indentStr = _buildIndent(indent);
50
- const insertIndex = insertAfterProp === null ? node.start.offset + 1 : insertAfterProp.end.offset + 1;
51
- const content = _stringifyContent(value, indentStr);
52
- recorder.insertRight(insertIndex, indentStr + `"${propertyName}":${indent ? ' ' : ''}${content}` + ',');
53
- }
54
- exports.insertPropertyInAstObjectInOrder = insertPropertyInAstObjectInOrder;
55
- function removePropertyInAstObject(recorder, node, propertyName) {
56
- // Find the property inside the object.
57
- const propIdx = node.properties.findIndex(prop => prop.key.value === propertyName);
58
- if (propIdx === -1) {
59
- // There's nothing to remove.
60
- return;
61
- }
62
- if (node.properties.length === 1) {
63
- // This is a special case. Everything should be removed, including indentation.
64
- recorder.remove(node.start.offset, node.end.offset - node.start.offset);
65
- recorder.insertRight(node.start.offset, '{}');
66
- return;
67
- }
68
- // The AST considers commas and indentation to be part of the preceding property.
69
- // To get around messy comma and identation management, we can work over the range between
70
- // two properties instead.
71
- const previousProp = node.properties[propIdx - 1];
72
- const targetProp = node.properties[propIdx];
73
- const nextProp = node.properties[propIdx + 1];
74
- let start, end;
75
- if (previousProp) {
76
- // Given the object below, and intending to remove the `m` property:
77
- // "{\n \"a\": \"a\",\n \"m\": \"m\",\n \"z\": \"z\"\n}"
78
- // ^---------------^
79
- // Removing the range above results in:
80
- // "{\n \"a\": \"a\",\n \"z\": \"z\"\n}"
81
- start = previousProp.end;
82
- end = targetProp.end;
83
- }
84
- else {
85
- // If there's no previousProp there is a nextProp, since we've specialcased the 1 length case.
86
- // Given the object below, and intending to remove the `a` property:
87
- // "{\n \"a\": \"a\",\n \"m\": \"m\",\n \"z\": \"z\"\n}"
88
- // ^---------------^
89
- // Removing the range above results in:
90
- // "{\n \"m\": \"m\",\n \"z\": \"z\"\n}"
91
- start = targetProp.start;
92
- end = nextProp.start;
93
- }
94
- recorder.remove(start.offset, end.offset - start.offset);
95
- if (!nextProp) {
96
- recorder.insertRight(start.offset, '\n');
97
- }
98
- }
99
- exports.removePropertyInAstObject = removePropertyInAstObject;
100
- function appendValueInAstArray(recorder, node, value, indent = 4) {
101
- let indentStr = _buildIndent(indent);
102
- let index = node.start.offset + 1;
103
- let newNodes;
104
- if (node.elements.length > 0) {
105
- // Insert comma.
106
- const { end } = node.elements[node.elements.length - 1];
107
- const isClosingOnSameLine = node.end.offset - end.offset === 1;
108
- if (isClosingOnSameLine && indent) {
109
- // Reformat the entire array
110
- recorder.remove(node.start.offset, node.end.offset - node.start.offset);
111
- newNodes = [...node.elements.map(({ value }) => value), value];
112
- index = node.start.offset;
113
- // In case we are generating the entire node we need to reduce the spacing as
114
- // otherwise we'd end up having incorrect double spacing
115
- indent = indent - 2;
116
- indentStr = _buildIndent(indent);
117
- }
118
- else {
119
- recorder.insertRight(end.offset, ',');
120
- index = end.offset;
121
- }
122
- }
123
- recorder.insertRight(index, (newNodes ? '' : indentStr) +
124
- _stringifyContent(newNodes || value, indentStr) +
125
- (node.elements.length === 0 && indent ? indentStr.substr(0, -indent) + '\n' : ''));
126
- }
127
- exports.appendValueInAstArray = appendValueInAstArray;
128
- function findPropertyInAstObject(node, propertyName) {
129
- let maybeNode = null;
130
- for (const property of node.properties) {
131
- if (property.key.value == propertyName) {
132
- maybeNode = property.value;
133
- }
134
- }
135
- return maybeNode;
136
- }
137
- exports.findPropertyInAstObject = findPropertyInAstObject;
138
- function _buildIndent(count) {
139
- return count ? '\n' + ' '.repeat(count) : '';
140
- }
141
- function _stringifyContent(value, indentStr) {
142
- // TODO: Add snapshot tests
143
- // The 'space' value is 2, because we want to add 2 additional
144
- // indents from the 'key' node.
145
- // If we use the indent provided we will have double indents:
146
- // "budgets": [
147
- // {
148
- // "type": "initial",
149
- // "maximumWarning": "2mb",
150
- // "maximumError": "5mb"
151
- // },
152
- // {
153
- // "type": "anyComponentStyle",
154
- // 'maximumWarning": "5kb"
155
- // }
156
- // ]
157
- return JSON.stringify(value, null, 2).replace(/\n/g, indentStr);
158
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findPropertyInAstObject = exports.appendValueInAstArray = exports.removePropertyInAstObject = exports.insertPropertyInAstObjectInOrder = exports.appendPropertyInAstObject = void 0;
4
+ function appendPropertyInAstObject(recorder, node, propertyName, value, indent) {
5
+ const indentStr = _buildIndent(indent);
6
+ let index = node.start.offset + 1;
7
+ if (node.properties.length > 0) {
8
+ // Insert comma.
9
+ const last = node.properties[node.properties.length - 1];
10
+ const { text, end } = last;
11
+ const commaIndex = text.endsWith('\n') ? end.offset - 1 : end.offset;
12
+ recorder.insertRight(commaIndex, ',');
13
+ index = end.offset;
14
+ }
15
+ const content = _stringifyContent(value, indentStr);
16
+ recorder.insertRight(index, (node.properties.length === 0 && indent ? '\n' : '') +
17
+ ' '.repeat(indent) +
18
+ `"${propertyName}":${indent ? ' ' : ''}${content}` +
19
+ indentStr.slice(0, -indent));
20
+ }
21
+ exports.appendPropertyInAstObject = appendPropertyInAstObject;
22
+ function insertPropertyInAstObjectInOrder(recorder, node, propertyName, value, indent) {
23
+ if (node.properties.length === 0) {
24
+ appendPropertyInAstObject(recorder, node, propertyName, value, indent);
25
+ return;
26
+ }
27
+ // Find insertion info.
28
+ let insertAfterProp = null;
29
+ let prev = null;
30
+ let isLastProp = false;
31
+ const last = node.properties[node.properties.length - 1];
32
+ for (const prop of node.properties) {
33
+ if (prop.key.value > propertyName) {
34
+ if (prev) {
35
+ insertAfterProp = prev;
36
+ }
37
+ break;
38
+ }
39
+ if (prop === last) {
40
+ isLastProp = true;
41
+ insertAfterProp = last;
42
+ }
43
+ prev = prop;
44
+ }
45
+ if (isLastProp) {
46
+ appendPropertyInAstObject(recorder, node, propertyName, value, indent);
47
+ return;
48
+ }
49
+ const indentStr = _buildIndent(indent);
50
+ const insertIndex = insertAfterProp === null ? node.start.offset + 1 : insertAfterProp.end.offset + 1;
51
+ const content = _stringifyContent(value, indentStr);
52
+ recorder.insertRight(insertIndex, indentStr + `"${propertyName}":${indent ? ' ' : ''}${content}` + ',');
53
+ }
54
+ exports.insertPropertyInAstObjectInOrder = insertPropertyInAstObjectInOrder;
55
+ function removePropertyInAstObject(recorder, node, propertyName) {
56
+ // Find the property inside the object.
57
+ const propIdx = node.properties.findIndex(prop => prop.key.value === propertyName);
58
+ if (propIdx === -1) {
59
+ // There's nothing to remove.
60
+ return;
61
+ }
62
+ if (node.properties.length === 1) {
63
+ // This is a special case. Everything should be removed, including indentation.
64
+ recorder.remove(node.start.offset, node.end.offset - node.start.offset);
65
+ recorder.insertRight(node.start.offset, '{}');
66
+ return;
67
+ }
68
+ // The AST considers commas and indentation to be part of the preceding property.
69
+ // To get around messy comma and identation management, we can work over the range between
70
+ // two properties instead.
71
+ const previousProp = node.properties[propIdx - 1];
72
+ const targetProp = node.properties[propIdx];
73
+ const nextProp = node.properties[propIdx + 1];
74
+ let start, end;
75
+ if (previousProp) {
76
+ // Given the object below, and intending to remove the `m` property:
77
+ // "{\n \"a\": \"a\",\n \"m\": \"m\",\n \"z\": \"z\"\n}"
78
+ // ^---------------^
79
+ // Removing the range above results in:
80
+ // "{\n \"a\": \"a\",\n \"z\": \"z\"\n}"
81
+ start = previousProp.end;
82
+ end = targetProp.end;
83
+ }
84
+ else {
85
+ // If there's no previousProp there is a nextProp, since we've specialcased the 1 length case.
86
+ // Given the object below, and intending to remove the `a` property:
87
+ // "{\n \"a\": \"a\",\n \"m\": \"m\",\n \"z\": \"z\"\n}"
88
+ // ^---------------^
89
+ // Removing the range above results in:
90
+ // "{\n \"m\": \"m\",\n \"z\": \"z\"\n}"
91
+ start = targetProp.start;
92
+ end = nextProp.start;
93
+ }
94
+ recorder.remove(start.offset, end.offset - start.offset);
95
+ if (!nextProp) {
96
+ recorder.insertRight(start.offset, '\n');
97
+ }
98
+ }
99
+ exports.removePropertyInAstObject = removePropertyInAstObject;
100
+ function appendValueInAstArray(recorder, node, value, indent = 4) {
101
+ let indentStr = _buildIndent(indent);
102
+ let index = node.start.offset + 1;
103
+ let newNodes;
104
+ if (node.elements.length > 0) {
105
+ // Insert comma.
106
+ const { end } = node.elements[node.elements.length - 1];
107
+ const isClosingOnSameLine = node.end.offset - end.offset === 1;
108
+ if (isClosingOnSameLine && indent) {
109
+ // Reformat the entire array
110
+ recorder.remove(node.start.offset, node.end.offset - node.start.offset);
111
+ newNodes = [...node.elements.map(({ value }) => value), value];
112
+ index = node.start.offset;
113
+ // In case we are generating the entire node we need to reduce the spacing as
114
+ // otherwise we'd end up having incorrect double spacing
115
+ indent = indent - 2;
116
+ indentStr = _buildIndent(indent);
117
+ }
118
+ else {
119
+ recorder.insertRight(end.offset, ',');
120
+ index = end.offset;
121
+ }
122
+ }
123
+ recorder.insertRight(index, (newNodes ? '' : indentStr) +
124
+ _stringifyContent(newNodes || value, indentStr) +
125
+ (node.elements.length === 0 && indent ? indentStr.substr(0, -indent) + '\n' : ''));
126
+ }
127
+ exports.appendValueInAstArray = appendValueInAstArray;
128
+ function findPropertyInAstObject(node, propertyName) {
129
+ let maybeNode = null;
130
+ for (const property of node.properties) {
131
+ if (property.key.value == propertyName) {
132
+ maybeNode = property.value;
133
+ }
134
+ }
135
+ return maybeNode;
136
+ }
137
+ exports.findPropertyInAstObject = findPropertyInAstObject;
138
+ function _buildIndent(count) {
139
+ return count ? '\n' + ' '.repeat(count) : '';
140
+ }
141
+ function _stringifyContent(value, indentStr) {
142
+ // TODO: Add snapshot tests
143
+ // The 'space' value is 2, because we want to add 2 additional
144
+ // indents from the 'key' node.
145
+ // If we use the indent provided we will have double indents:
146
+ // "budgets": [
147
+ // {
148
+ // "type": "initial",
149
+ // "maximumWarning": "2mb",
150
+ // "maximumError": "5mb"
151
+ // },
152
+ // {
153
+ // "type": "anyComponentStyle",
154
+ // 'maximumWarning": "5kb"
155
+ // }
156
+ // ]
157
+ return JSON.stringify(value, null, 2).replace(/\n/g, indentStr);
158
+ }
159
159
  //# sourceMappingURL=json-utils.js.map
@@ -1,18 +1,18 @@
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
- export declare const latestVersions: {
9
- Angular: string;
10
- RxJs: string;
11
- ZoneJs: string;
12
- TypeScript: string;
13
- TsLib: string;
14
- DevkitBuildAngular: string;
15
- DevkitBuildNgPackagr: string;
16
- DevkitBuildWebpack: string;
17
- ngPackagr: string;
18
- };
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
+ export declare const latestVersions: {
9
+ Angular: string;
10
+ RxJs: string;
11
+ ZoneJs: string;
12
+ TypeScript: string;
13
+ TsLib: string;
14
+ DevkitBuildAngular: string;
15
+ DevkitBuildNgPackagr: string;
16
+ DevkitBuildWebpack: string;
17
+ ngPackagr: string;
18
+ };