@typeix/schematics 8.8.0 → 8.9.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.
- package/README.md +0 -1
- package/dist/lib/application/files/js/typeix-cli.json +1 -1
- package/dist/lib/application/files/ts/package.json +1 -1
- package/dist/utils/json-file.util.d.ts +5 -2
- package/dist/utils/json-file.util.js +28 -23
- package/dist/utils/metadata.manager.d.ts +7 -2
- package/dist/utils/metadata.manager.js +77 -136
- package/dist/utils/module-import.declarator.d.ts +4 -2
- package/dist/utils/module-import.declarator.js +17 -19
- package/dist/utils/module-metadata.declarator.d.ts +2 -1
- package/dist/utils/module-metadata.declarator.js +5 -3
- package/dist/utils/module.declarator.d.ts +3 -0
- package/dist/utils/module.declarator.js +17 -14
- package/dist/utils/module.finder.d.ts +2 -1
- package/dist/utils/module.finder.js +10 -7
- package/dist/utils/name.parser.d.ts +2 -0
- package/dist/utils/name.parser.js +11 -6
- package/dist/utils/path.solver.d.ts +2 -0
- package/dist/utils/path.solver.js +8 -5
- package/dist/utils/source-root.helpers.d.ts +1 -1
- package/dist/utils/source-root.helpers.js +10 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -30,7 +30,6 @@ Typeix is an MIT-licensed open source project. It can grow thanks to the sponsor
|
|
|
30
30
|
If you'd like to join them, please [read more here](https://docs.typeix.com/support).
|
|
31
31
|
|
|
32
32
|
## Stay in touch
|
|
33
|
-
* Author - [Igor Ivanovic](https://twitter.com/igorzg1987)
|
|
34
33
|
* Website - [https://typeix.com](https://typeix.com)
|
|
35
34
|
* Twitter - [@typeixframework](https://twitter.com/typeixframework)
|
|
36
35
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@typeix/cli": "^<%= version %>",
|
|
28
28
|
"@typeix/schematics": "^<%= version %>",
|
|
29
29
|
"@types/jest": "~29.5.12",
|
|
30
|
-
"@types/node": "~18.19.
|
|
30
|
+
"@types/node": "~18.19.70",
|
|
31
31
|
"@typescript-eslint/eslint-plugin": "~7.13.0",
|
|
32
32
|
"@typescript-eslint/eslint-plugin-tslint": "~7.0.2",
|
|
33
33
|
"eslint": "~8.57.0",
|
|
@@ -6,10 +6,13 @@ export declare class JSONFile {
|
|
|
6
6
|
private readonly host;
|
|
7
7
|
private readonly path;
|
|
8
8
|
content: string;
|
|
9
|
-
constructor(host: Tree, path: string);
|
|
10
9
|
private _jsonAst;
|
|
11
|
-
private
|
|
10
|
+
private readonly formattingOptions;
|
|
11
|
+
constructor(host: Tree, path: string);
|
|
12
|
+
private get jsonAst();
|
|
12
13
|
get(jsonPath: JSONPath): unknown;
|
|
13
14
|
modify(jsonPath: JSONPath, value: JsonValue | undefined, insertInOrder?: InsertionIndex | false): void;
|
|
14
15
|
remove(jsonPath: JSONPath): void;
|
|
16
|
+
private _initializeContent;
|
|
17
|
+
private _resolveInsertionIndex;
|
|
15
18
|
}
|
|
@@ -6,15 +6,13 @@ class JSONFile {
|
|
|
6
6
|
constructor(host, path) {
|
|
7
7
|
this.host = host;
|
|
8
8
|
this.path = path;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
throw new Error(`Could not read '${path}'.`);
|
|
15
|
-
}
|
|
9
|
+
this.formattingOptions = {
|
|
10
|
+
insertSpaces: true,
|
|
11
|
+
tabSize: 2
|
|
12
|
+
};
|
|
13
|
+
this.content = this._initializeContent();
|
|
16
14
|
}
|
|
17
|
-
get
|
|
15
|
+
get jsonAst() {
|
|
18
16
|
if (this._jsonAst) {
|
|
19
17
|
return this._jsonAst;
|
|
20
18
|
}
|
|
@@ -29,7 +27,7 @@ class JSONFile {
|
|
|
29
27
|
return this._jsonAst;
|
|
30
28
|
}
|
|
31
29
|
get(jsonPath) {
|
|
32
|
-
const jsonAstNode = this.
|
|
30
|
+
const jsonAstNode = this.jsonAst;
|
|
33
31
|
if (!jsonAstNode) {
|
|
34
32
|
return undefined;
|
|
35
33
|
}
|
|
@@ -40,29 +38,36 @@ class JSONFile {
|
|
|
40
38
|
return node === undefined ? undefined : (0, jsonc_parser_1.getNodeValue)(node);
|
|
41
39
|
}
|
|
42
40
|
modify(jsonPath, value, insertInOrder) {
|
|
43
|
-
|
|
44
|
-
if (insertInOrder === undefined) {
|
|
45
|
-
const property = jsonPath.slice(-1)[0];
|
|
46
|
-
getInsertionIndex = (properties) => [...properties, property].sort().findIndex((p) => p === property);
|
|
47
|
-
}
|
|
48
|
-
else if (insertInOrder !== false) {
|
|
49
|
-
getInsertionIndex = insertInOrder;
|
|
50
|
-
}
|
|
41
|
+
const getInsertionIndex = this._resolveInsertionIndex(jsonPath, insertInOrder);
|
|
51
42
|
const edits = (0, jsonc_parser_1.modify)(this.content, jsonPath, value, {
|
|
52
43
|
getInsertionIndex,
|
|
53
|
-
formattingOptions:
|
|
54
|
-
insertSpaces: true,
|
|
55
|
-
tabSize: 2
|
|
56
|
-
}
|
|
44
|
+
formattingOptions: this.formattingOptions
|
|
57
45
|
});
|
|
58
46
|
this.content = (0, jsonc_parser_1.applyEdits)(this.content, edits);
|
|
59
47
|
this.host.overwrite(this.path, this.content);
|
|
60
48
|
this._jsonAst = undefined;
|
|
61
49
|
}
|
|
62
50
|
remove(jsonPath) {
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
this.modify(jsonPath, undefined);
|
|
52
|
+
}
|
|
53
|
+
_initializeContent() {
|
|
54
|
+
const buffer = this.host.read(this.path);
|
|
55
|
+
if (buffer) {
|
|
56
|
+
return buffer.toString();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`Could not read '${this.path}'.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_resolveInsertionIndex(jsonPath, insertInOrder) {
|
|
63
|
+
if (insertInOrder === undefined) {
|
|
64
|
+
const property = jsonPath.slice(-1)[0];
|
|
65
|
+
return (properties) => [...properties, property].sort().findIndex((p) => p === property);
|
|
66
|
+
}
|
|
67
|
+
else if (insertInOrder !== false) {
|
|
68
|
+
return insertInOrder;
|
|
65
69
|
}
|
|
70
|
+
return undefined;
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
exports.JSONFile = JSONFile;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { DeclarationOptions } from "./module.declarator";
|
|
2
2
|
export declare class MetadataManager {
|
|
3
3
|
private content;
|
|
4
|
+
private static readonly PROPERTY_KIND;
|
|
5
|
+
private readonly source;
|
|
4
6
|
constructor(content: string);
|
|
5
7
|
insert(metadata: string, symbol: string, staticOptions?: DeclarationOptions["staticOptions"]): string | undefined;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
+
private findModuleDecorator;
|
|
9
|
+
private findMatchingMetadataProperties;
|
|
10
|
+
private findDecoratorMetadata;
|
|
8
11
|
private insertMetadataToEmptyModuleDecorator;
|
|
9
12
|
private insertNewMetadataToDecorator;
|
|
10
13
|
private insertSymbolToMetadata;
|
|
11
14
|
private mergeSymbolAndExpr;
|
|
12
15
|
private addBlankLines;
|
|
16
|
+
private getSourceNodes;
|
|
17
|
+
private insertTextAtPosition;
|
|
13
18
|
}
|
|
@@ -5,171 +5,112 @@ const typescript_1 = require("typescript");
|
|
|
5
5
|
class MetadataManager {
|
|
6
6
|
constructor(content) {
|
|
7
7
|
this.content = content;
|
|
8
|
+
this.source = (0, typescript_1.createSourceFile)("filename.ts", this.content, typescript_1.ScriptTarget.ES2017);
|
|
8
9
|
}
|
|
9
10
|
insert(metadata, symbol, staticOptions) {
|
|
10
|
-
|
|
11
|
-
const source = (0, typescript_1.createSourceFile)("filename.ts", this.content, typescript_1.ScriptTarget.ES2017);
|
|
12
|
-
const moduleDecoratorNode = (_a = this.findFirstDecoratorMetadata(source, "Module")) !== null && _a !== void 0 ? _a : this.findFirstDecoratorMetadata(source, "RootModule");
|
|
11
|
+
const moduleDecoratorNode = this.findModuleDecorator();
|
|
13
12
|
if (!moduleDecoratorNode) {
|
|
14
|
-
return;
|
|
13
|
+
return undefined;
|
|
15
14
|
}
|
|
16
|
-
const matchingProperties = moduleDecoratorNode
|
|
17
|
-
.filter((prop) => prop.kind === typescript_1.SyntaxKind.PropertyAssignment)
|
|
18
|
-
.filter((prop) => {
|
|
19
|
-
const name = prop.name;
|
|
20
|
-
switch (name.kind) {
|
|
21
|
-
case typescript_1.SyntaxKind.Identifier:
|
|
22
|
-
return name.getText(source) === metadata;
|
|
23
|
-
case typescript_1.SyntaxKind.StringLiteral:
|
|
24
|
-
return name.text === metadata;
|
|
25
|
-
default:
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
15
|
+
const matchingProperties = this.findMatchingMetadataProperties(moduleDecoratorNode, metadata);
|
|
29
16
|
symbol = this.mergeSymbolAndExpr(symbol, staticOptions);
|
|
30
|
-
const addBlankLinesIfDynamic = () => {
|
|
31
|
-
symbol = staticOptions ? this.addBlankLines(symbol) : symbol;
|
|
32
|
-
};
|
|
33
17
|
if (matchingProperties.length === 0) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return this.insertMetadataToEmptyModuleDecorator(expr, metadata, symbol);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
addBlankLinesIfDynamic();
|
|
41
|
-
return this.insertNewMetadataToDecorator(expr, source, metadata, symbol);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
return this.insertSymbolToMetadata(source, matchingProperties, symbol, staticOptions);
|
|
18
|
+
return moduleDecoratorNode.properties.length === 0
|
|
19
|
+
? this.insertMetadataToEmptyModuleDecorator(moduleDecoratorNode, metadata, symbol, staticOptions)
|
|
20
|
+
: this.insertNewMetadataToDecorator(moduleDecoratorNode, metadata, symbol, staticOptions);
|
|
46
21
|
}
|
|
22
|
+
return this.insertSymbolToMetadata(matchingProperties, symbol, staticOptions);
|
|
47
23
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
continue;
|
|
24
|
+
findModuleDecorator() {
|
|
25
|
+
return (this.findDecoratorMetadata(this.source, "Module") ||
|
|
26
|
+
this.findDecoratorMetadata(this.source, "RootModule"));
|
|
27
|
+
}
|
|
28
|
+
findMatchingMetadataProperties(node, key) {
|
|
29
|
+
return node.properties
|
|
30
|
+
.filter((prop) => prop.kind === MetadataManager.PROPERTY_KIND)
|
|
31
|
+
.filter((prop) => {
|
|
32
|
+
const name = prop.name;
|
|
33
|
+
if (name.kind === typescript_1.SyntaxKind.Identifier) {
|
|
34
|
+
return name.getText(this.source) === key;
|
|
60
35
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
const isTargetIdentifier = escapedText
|
|
64
|
-
? escapedText.toLowerCase() === identifier.toLowerCase()
|
|
65
|
-
: true;
|
|
66
|
-
if (isTargetIdentifier) {
|
|
67
|
-
return expr.arguments[0];
|
|
68
|
-
}
|
|
36
|
+
if (name.kind === typescript_1.SyntaxKind.StringLiteral) {
|
|
37
|
+
return name.text === key;
|
|
69
38
|
}
|
|
70
|
-
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
71
41
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
findDecoratorMetadata(source, identifier) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
for (const node of this.getSourceNodes(source)) {
|
|
45
|
+
if (node.kind === typescript_1.SyntaxKind.Decorator && node.expression.kind === typescript_1.SyntaxKind.CallExpression) {
|
|
46
|
+
const expr = node.expression;
|
|
47
|
+
if (((_a = expr.arguments[0]) === null || _a === void 0 ? void 0 : _a.kind) === typescript_1.SyntaxKind.ObjectLiteralExpression) {
|
|
48
|
+
const exprText = (_b = expr.expression.escapedText) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase();
|
|
49
|
+
if (identifier.toLowerCase() === exprText) {
|
|
50
|
+
return expr.arguments[0];
|
|
51
|
+
}
|
|
81
52
|
}
|
|
82
53
|
}
|
|
83
54
|
}
|
|
84
|
-
return
|
|
55
|
+
return undefined;
|
|
85
56
|
}
|
|
86
|
-
insertMetadataToEmptyModuleDecorator(expr, metadata, symbol) {
|
|
57
|
+
insertMetadataToEmptyModuleDecorator(expr, metadata, symbol, staticOptions) {
|
|
87
58
|
const position = expr.getEnd() - 1;
|
|
59
|
+
symbol = staticOptions ? this.addBlankLines(symbol) : symbol;
|
|
88
60
|
const toInsert = ` ${metadata}: [${symbol}]`;
|
|
89
|
-
return this.
|
|
90
|
-
if (index === position) {
|
|
91
|
-
return `${content}\n${toInsert}\n${char}`;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return `${content}${char}`;
|
|
95
|
-
}
|
|
96
|
-
}, "");
|
|
61
|
+
return this.insertTextAtPosition(this.content, position, `\n${toInsert}\n`);
|
|
97
62
|
}
|
|
98
|
-
insertNewMetadataToDecorator(expr,
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
toInsert = `, ${metadata}: [${symbol}]`;
|
|
109
|
-
}
|
|
110
|
-
return this.content.split("").reduce((content, char, index) => {
|
|
111
|
-
if (index === position) {
|
|
112
|
-
return `${content}${toInsert}${char}`;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return `${content}${char}`;
|
|
116
|
-
}
|
|
117
|
-
}, "");
|
|
63
|
+
insertNewMetadataToDecorator(expr, metadata, symbol, staticOptions) {
|
|
64
|
+
var _a;
|
|
65
|
+
const lastProperty = expr.properties[expr.properties.length - 1];
|
|
66
|
+
const position = lastProperty.getEnd();
|
|
67
|
+
symbol = staticOptions ? this.addBlankLines(symbol) : symbol;
|
|
68
|
+
const separator = ((_a = lastProperty.getFullText(this.source).match(/^\r?\n\s+/)) === null || _a === void 0 ? void 0 : _a[0]) || " ";
|
|
69
|
+
const toInsert = `,${separator}${metadata}: [${symbol}]`;
|
|
70
|
+
return this.insertTextAtPosition(this.content, position, toInsert);
|
|
118
71
|
}
|
|
119
|
-
insertSymbolToMetadata(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
72
|
+
insertSymbolToMetadata(properties, symbol, staticOptions) {
|
|
73
|
+
var _a;
|
|
74
|
+
const assignment = properties[0];
|
|
75
|
+
const arrayLiteral = assignment.initializer;
|
|
76
|
+
if (!arrayLiteral.elements) {
|
|
124
77
|
return this.content;
|
|
125
78
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (symbolsArray.includes(symbol)) {
|
|
136
|
-
return this.content;
|
|
137
|
-
}
|
|
138
|
-
node = node[node.length - 1];
|
|
139
|
-
}
|
|
140
|
-
let toInsert;
|
|
141
|
-
let position = node.getEnd();
|
|
142
|
-
if (node.kind === typescript_1.SyntaxKind.ArrayLiteralExpression) {
|
|
143
|
-
position--;
|
|
144
|
-
toInsert = staticOptions ? this.addBlankLines(symbol) : `${symbol}`;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
const text = node.getFullText(source);
|
|
148
|
-
const itemSeparator = (text.match(/^\r?\n(\r?)\s+/) ||
|
|
149
|
-
text.match(/^\r?\n/) ||
|
|
150
|
-
" ")[0];
|
|
151
|
-
toInsert = `,${itemSeparator}${symbol}`;
|
|
152
|
-
}
|
|
153
|
-
return this.content.split("").reduce((content, char, index) => {
|
|
154
|
-
if (index === position) {
|
|
155
|
-
return `${content}${toInsert}${char}`;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return `${content}${char}`;
|
|
159
|
-
}
|
|
160
|
-
}, "");
|
|
79
|
+
const lastElement = arrayLiteral.elements.length > 0
|
|
80
|
+
? arrayLiteral.elements[arrayLiteral.elements.length - 1]
|
|
81
|
+
: arrayLiteral;
|
|
82
|
+
const position = lastElement.getEnd() + (lastElement.kind === typescript_1.SyntaxKind.ArrayLiteralExpression ? -1 : 0);
|
|
83
|
+
const separator = ((_a = lastElement.getFullText(this.source).match(/^\r?\n\s+/)) === null || _a === void 0 ? void 0 : _a[0]) || " ";
|
|
84
|
+
const toInsert = arrayLiteral.elements.length === 0
|
|
85
|
+
? staticOptions ? this.addBlankLines(symbol) : `${symbol}`
|
|
86
|
+
: `,${separator}${symbol}`;
|
|
87
|
+
return this.insertTextAtPosition(this.content, position, toInsert);
|
|
161
88
|
}
|
|
162
89
|
mergeSymbolAndExpr(symbol, staticOptions) {
|
|
163
90
|
if (!staticOptions) {
|
|
164
91
|
return symbol;
|
|
165
92
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
symbol += `.${staticOptions.name}(${options})`;
|
|
169
|
-
return symbol;
|
|
93
|
+
const options = JSON.stringify(staticOptions.value, null, 2);
|
|
94
|
+
return `${symbol}.${staticOptions.name}(${options})`;
|
|
170
95
|
}
|
|
171
96
|
addBlankLines(expr) {
|
|
172
97
|
return `\n ${expr}\n `;
|
|
173
98
|
}
|
|
99
|
+
getSourceNodes(source) {
|
|
100
|
+
const nodes = [source];
|
|
101
|
+
const result = [];
|
|
102
|
+
while (nodes.length > 0) {
|
|
103
|
+
const node = nodes.shift();
|
|
104
|
+
if (node) {
|
|
105
|
+
result.push(node);
|
|
106
|
+
nodes.unshift(...node.getChildren(source));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
insertTextAtPosition(content, position, text) {
|
|
112
|
+
return content.substring(0, position) + text + content.substring(position);
|
|
113
|
+
}
|
|
174
114
|
}
|
|
175
115
|
exports.MetadataManager = MetadataManager;
|
|
116
|
+
MetadataManager.PROPERTY_KIND = typescript_1.SyntaxKind.PropertyAssignment;
|
|
@@ -2,9 +2,11 @@ import { DeclarationOptions } from "./module.declarator";
|
|
|
2
2
|
import { PathSolver } from "./path.solver";
|
|
3
3
|
export declare class ModuleImportDeclarator {
|
|
4
4
|
private solver;
|
|
5
|
+
private static readonly IMPORT_STATEMENT_REGEX;
|
|
5
6
|
constructor(solver?: PathSolver);
|
|
6
7
|
declare(content: string, options: DeclarationOptions): string;
|
|
7
|
-
private
|
|
8
|
-
private buildLineToInsert;
|
|
8
|
+
private buildImportStatement;
|
|
9
9
|
private computeRelativePath;
|
|
10
|
+
private normalizeImportModulePath;
|
|
11
|
+
private findLastImportIndex;
|
|
10
12
|
}
|
|
@@ -8,32 +8,30 @@ class ModuleImportDeclarator {
|
|
|
8
8
|
this.solver = solver;
|
|
9
9
|
}
|
|
10
10
|
declare(content, options) {
|
|
11
|
-
const
|
|
11
|
+
const importStatement = this.buildImportStatement(options);
|
|
12
12
|
const contentLines = content.split("\n");
|
|
13
|
-
const
|
|
14
|
-
contentLines.splice(
|
|
13
|
+
const lastImportIndex = this.findLastImportIndex(contentLines);
|
|
14
|
+
contentLines.splice(lastImportIndex + 1, 0, importStatement);
|
|
15
15
|
return contentLines.join("\n");
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
const reversedContent = Array.from(contentLines).reverse();
|
|
19
|
-
const reverseImports = reversedContent.filter(line => line.match(/\} from ('|")/));
|
|
20
|
-
if (reverseImports.length <= 0) {
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
return contentLines.indexOf(reverseImports[0]);
|
|
24
|
-
}
|
|
25
|
-
buildLineToInsert(options) {
|
|
17
|
+
buildImportStatement(options) {
|
|
26
18
|
return `import {${options.symbol}} from "${this.computeRelativePath(options)}";`;
|
|
27
19
|
}
|
|
28
20
|
computeRelativePath(options) {
|
|
29
|
-
|
|
30
|
-
if (options.type !== undefined) {
|
|
31
|
-
importModulePath = (0, core_1.normalize)(`/${options.path}/${options.name}.${options.type}`);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
importModulePath = (0, core_1.normalize)(`/${options.path}/${options.name}`);
|
|
35
|
-
}
|
|
21
|
+
const importModulePath = this.normalizeImportModulePath(options);
|
|
36
22
|
return this.solver.relative(options.module, importModulePath);
|
|
37
23
|
}
|
|
24
|
+
normalizeImportModulePath(options) {
|
|
25
|
+
const filePath = `/${options.path}/${options.name}`;
|
|
26
|
+
return (0, core_1.normalize)(options.type ? `${filePath}.${options.type}` : filePath);
|
|
27
|
+
}
|
|
28
|
+
findLastImportIndex(contentLines) {
|
|
29
|
+
const reverseImports = contentLines
|
|
30
|
+
.slice()
|
|
31
|
+
.reverse()
|
|
32
|
+
.find(line => ModuleImportDeclarator.IMPORT_STATEMENT_REGEX.test(line));
|
|
33
|
+
return reverseImports ? contentLines.indexOf(reverseImports) : 0;
|
|
34
|
+
}
|
|
38
35
|
}
|
|
39
36
|
exports.ModuleImportDeclarator = ModuleImportDeclarator;
|
|
37
|
+
ModuleImportDeclarator.IMPORT_STATEMENT_REGEX = /\} from ('|")/;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DeclarationOptions } from "./module.declarator";
|
|
2
2
|
export declare class ModuleMetadataDeclarator {
|
|
3
|
-
declare(
|
|
3
|
+
declare(moduleSource: string, declarationOpts: DeclarationOptions): string;
|
|
4
|
+
private insertMetadata;
|
|
4
5
|
}
|
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModuleMetadataDeclarator = void 0;
|
|
4
4
|
const metadata_manager_1 = require("./metadata.manager");
|
|
5
5
|
class ModuleMetadataDeclarator {
|
|
6
|
-
declare(
|
|
6
|
+
declare(moduleSource, declarationOpts) {
|
|
7
|
+
return this.insertMetadata(moduleSource, declarationOpts) || moduleSource;
|
|
8
|
+
}
|
|
9
|
+
insertMetadata(content, options) {
|
|
7
10
|
const manager = new metadata_manager_1.MetadataManager(content);
|
|
8
|
-
|
|
9
|
-
return inserted !== null && inserted !== void 0 ? inserted : content;
|
|
11
|
+
return manager.insert(options.metadata, options.symbol, options.staticOptions);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
exports.ModuleMetadataDeclarator = ModuleMetadataDeclarator;
|
|
@@ -17,7 +17,10 @@ export interface DeclarationOptions {
|
|
|
17
17
|
export declare class ModuleDeclarator {
|
|
18
18
|
private imports;
|
|
19
19
|
private metadata;
|
|
20
|
+
private static readonly DEFAULT_IMPORTS;
|
|
21
|
+
private static readonly DEFAULT_METADATA;
|
|
20
22
|
constructor(imports?: ModuleImportDeclarator, metadata?: ModuleMetadataDeclarator);
|
|
21
23
|
declare(content: string, options: DeclarationOptions): string;
|
|
22
24
|
private computeSymbol;
|
|
25
|
+
private determineSymbol;
|
|
23
26
|
}
|
|
@@ -5,28 +5,31 @@ const strings_1 = require("@angular-devkit/core/src/utils/strings");
|
|
|
5
5
|
const module_import_declarator_1 = require("./module-import.declarator");
|
|
6
6
|
const module_metadata_declarator_1 = require("./module-metadata.declarator");
|
|
7
7
|
class ModuleDeclarator {
|
|
8
|
-
constructor(imports =
|
|
8
|
+
constructor(imports = ModuleDeclarator.DEFAULT_IMPORTS, metadata = ModuleDeclarator.DEFAULT_METADATA) {
|
|
9
9
|
this.imports = imports;
|
|
10
10
|
this.metadata = metadata;
|
|
11
11
|
}
|
|
12
12
|
declare(content, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return content;
|
|
13
|
+
const enrichedOptions = this.computeSymbol(options);
|
|
14
|
+
const updatedContent = this.metadata.declare(this.imports.declare(content, enrichedOptions), enrichedOptions);
|
|
15
|
+
return updatedContent;
|
|
17
16
|
}
|
|
18
17
|
computeSymbol(options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
return {
|
|
19
|
+
...options,
|
|
20
|
+
symbol: this.determineSymbol(options)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
determineSymbol({ className, type, name }) {
|
|
24
|
+
if (className) {
|
|
25
|
+
return className;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (type !== undefined) {
|
|
28
|
+
return (0, strings_1.classify)(name).concat((0, strings_1.capitalize)(type));
|
|
28
29
|
}
|
|
29
|
-
return
|
|
30
|
+
return (0, strings_1.classify)(name);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
exports.ModuleDeclarator = ModuleDeclarator;
|
|
34
|
+
ModuleDeclarator.DEFAULT_IMPORTS = new module_import_declarator_1.ModuleImportDeclarator();
|
|
35
|
+
ModuleDeclarator.DEFAULT_METADATA = new module_metadata_declarator_1.ModuleMetadataDeclarator();
|
|
@@ -7,18 +7,21 @@ class ModuleFinder {
|
|
|
7
7
|
this.tree = tree;
|
|
8
8
|
}
|
|
9
9
|
find(options) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
return this.
|
|
10
|
+
const dirPath = options.path;
|
|
11
|
+
const directory = this.tree.getDir(dirPath);
|
|
12
|
+
return this.findModuleInDirectory(directory);
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
findModuleInDirectory(directory) {
|
|
15
15
|
if (!directory) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
-
const moduleFilename =
|
|
19
|
-
return moduleFilename
|
|
18
|
+
const moduleFilename = this.getModuleFilename(directory);
|
|
19
|
+
return moduleFilename
|
|
20
20
|
? (0, core_1.join)(directory.path, moduleFilename.valueOf())
|
|
21
|
-
: this.
|
|
21
|
+
: this.findModuleInDirectory(directory.parent);
|
|
22
|
+
}
|
|
23
|
+
getModuleFilename(directory) {
|
|
24
|
+
return directory.subfiles.find((filename) => /\.module\.(t|j)s$/.test(filename));
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
exports.ModuleFinder = ModuleFinder;
|
|
@@ -4,14 +4,19 @@ exports.NameParser = void 0;
|
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
class NameParser {
|
|
6
6
|
parse(options) {
|
|
7
|
-
const
|
|
8
|
-
const namePath =
|
|
9
|
-
.concat("/")
|
|
10
|
-
.concat(options.name));
|
|
7
|
+
const baseName = (0, core_1.basename)(options.name);
|
|
8
|
+
const namePath = this.constructNamePath(options);
|
|
11
9
|
return {
|
|
12
|
-
name:
|
|
13
|
-
path: (0, core_1.normalize)(
|
|
10
|
+
name: baseName,
|
|
11
|
+
path: (0, core_1.normalize)(NameParser.DEFAULT_PATH_SEPARATOR.concat(namePath))
|
|
14
12
|
};
|
|
15
13
|
}
|
|
14
|
+
constructNamePath(options) {
|
|
15
|
+
const combinedPath = (options.path || "")
|
|
16
|
+
.concat(NameParser.DEFAULT_PATH_SEPARATOR)
|
|
17
|
+
.concat(options.name);
|
|
18
|
+
return (0, core_1.dirname)(combinedPath);
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
exports.NameParser = NameParser;
|
|
22
|
+
NameParser.DEFAULT_PATH_SEPARATOR = "/";
|
|
@@ -4,11 +4,14 @@ exports.PathSolver = void 0;
|
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
class PathSolver {
|
|
6
6
|
relative(from, to) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const relativePath = this.getRelativeDirectory(from, to);
|
|
8
|
+
return `${relativePath.startsWith(".") ? relativePath : `./${relativePath}`}`.concat(relativePath.length === 0 ? "" : "/", (0, core_1.basename)(to));
|
|
9
|
+
}
|
|
10
|
+
getRelativeDirectory(from, to) {
|
|
11
|
+
const baseFrom = (0, core_1.dirname)((PathSolver.PLACEHOLDER + from));
|
|
12
|
+
const baseTo = (0, core_1.dirname)((PathSolver.PLACEHOLDER + to));
|
|
13
|
+
return (0, core_1.relative)(baseFrom, baseTo);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
exports.PathSolver = PathSolver;
|
|
17
|
+
PathSolver.PLACEHOLDER = "/placeholder";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Rule, Tree } from "@angular-devkit/schematics";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function doesTreeContainFiles(host: Tree, extraFiles?: string[]): boolean;
|
|
3
3
|
export declare function mergeSourceRoot<T extends {
|
|
4
4
|
sourceRoot?: string;
|
|
5
5
|
path?: string;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.doesTreeContainFiles = doesTreeContainFiles;
|
|
4
4
|
exports.mergeSourceRoot = mergeSourceRoot;
|
|
5
5
|
const core_1 = require("@angular-devkit/core");
|
|
6
6
|
const defaults_1 = require("../lib/defaults");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const DEFAULT_ROOT_FILES = ["typeix-cli.json", "typeix.json"];
|
|
8
|
+
function doesTreeContainFiles(host, extraFiles = []) {
|
|
9
|
+
const filesToCheck = [...DEFAULT_ROOT_FILES, ...extraFiles];
|
|
10
|
+
return filesToCheck.some(file => host.exists(file));
|
|
10
11
|
}
|
|
11
12
|
function mergeSourceRoot(options) {
|
|
13
|
+
const calculatePath = (sourceRoot, path) => path !== undefined ? (0, core_1.join)((0, core_1.normalize)(sourceRoot), path) : (0, core_1.normalize)(sourceRoot);
|
|
12
14
|
return (host) => {
|
|
13
|
-
|
|
15
|
+
var _a;
|
|
16
|
+
const isInRoot = doesTreeContainFiles(host, ["tsconfig.json", "package.json"]);
|
|
14
17
|
if (!isInRoot) {
|
|
15
18
|
return host;
|
|
16
19
|
}
|
|
17
|
-
const defaultSourceRoot = options.sourceRoot !==
|
|
18
|
-
options.path =
|
|
19
|
-
options.path !== undefined
|
|
20
|
-
? (0, core_1.join)((0, core_1.normalize)(defaultSourceRoot), options.path)
|
|
21
|
-
: (0, core_1.normalize)(defaultSourceRoot);
|
|
20
|
+
const defaultSourceRoot = (_a = options.sourceRoot) !== null && _a !== void 0 ? _a : defaults_1.DEFAULT_PATH_NAME;
|
|
21
|
+
options.path = calculatePath(defaultSourceRoot, options.path);
|
|
22
22
|
return host;
|
|
23
23
|
};
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typeix/schematics",
|
|
3
3
|
"testRunner": "jest-jasmine2",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.9.2",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*"
|
|
7
7
|
],
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@commitlint/cli": "~17.8.1",
|
|
24
24
|
"@commitlint/config-angular": "~17.8.1",
|
|
25
|
-
"@typeix/resty": "^8.
|
|
25
|
+
"@typeix/resty": "^8.9.2",
|
|
26
26
|
"@types/fs-extra": "~11.0.4",
|
|
27
27
|
"@types/jest": "~29.5.14",
|
|
28
28
|
"cpx": "~1.5.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"bugs": {
|
|
51
51
|
"url": "https://github.com/typeix/schematics/issues"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "a9b6917167aa18aac8b3cdf91ee989d51dcdadc3"
|
|
54
54
|
}
|