@rxdi/schematics 0.7.124 → 0.7.128
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/lib/application/application.factory.js +4 -4
- package/lib/application/application.factory.test.ts +88 -0
- package/lib/application/application.factory.ts +54 -0
- package/lib/application/application.schema.d.ts +34 -0
- package/lib/application/files/js/.babelrc +4 -0
- package/lib/application/files/js/.prettierrc +4 -0
- package/lib/application/files/js/README.md +37 -0
- package/lib/application/files/js/index.js +3 -0
- package/lib/application/files/js/jsconfig.json +9 -0
- package/lib/application/files/js/nest-cli.json +5 -0
- package/lib/application/files/js/nodemon.json +6 -0
- package/lib/application/files/js/package.json +46 -0
- package/lib/application/files/js/test/app.e2e-spec.js +23 -0
- package/lib/application/files/js/test/jest-e2e.json +5 -0
- package/lib/application/files/ts/.prettierrc +4 -0
- package/lib/application/files/ts/README.md +75 -0
- package/lib/application/files/ts/nest-cli.json +5 -0
- package/lib/application/files/ts/nodemon-debug.json +6 -0
- package/lib/application/files/ts/nodemon.json +6 -0
- package/lib/application/files/ts/package.json +58 -0
- package/lib/application/files/ts/test/app.e2e-spec.ts +23 -0
- package/lib/application/files/ts/test/jest-e2e.json +9 -0
- package/lib/application/files/ts/tsconfig.build.json +4 -0
- package/lib/application/schema.json +49 -0
- package/lib/class/class.factory.js +6 -6
- package/lib/class/class.factory.test.ts +100 -0
- package/lib/class/class.factory.ts +54 -0
- package/lib/class/class.schema.d.ts +28 -0
- package/lib/class/files/js/__name__.js +1 -0
- package/lib/class/files/js/__name__.spec.js +7 -0
- package/lib/class/files/ts/__name__.spec.ts +7 -0
- package/lib/class/files/ts/__name__.ts +1 -0
- package/lib/class/schema.json +39 -0
- package/lib/client-app/angular/angular.factory.js +9 -9
- package/lib/client-app/angular/angular.factory.ts +139 -0
- package/lib/client-app/angular/angular.schema.d.ts +32 -0
- package/lib/client-app/angular/files/angular.constants.ts +4 -0
- package/lib/client-app/angular/files/angular.module.ts +41 -0
- package/lib/client-app/angular/files/angular.providers.ts +27 -0
- package/lib/client-app/angular/files/angular.utils.ts +19 -0
- package/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
- package/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
- package/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
- package/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
- package/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
- package/lib/client-app/angular/schema.json +24 -0
- package/lib/component/component.factory.js +8 -8
- package/lib/component/component.factory.test.ts +191 -0
- package/lib/component/component.factory.ts +91 -0
- package/lib/component/component.schema.d.ts +44 -0
- package/lib/component/files/js/__name__.component.js +56 -0
- package/lib/component/files/js/__name__.component.spec.js +31 -0
- package/lib/component/files/ts/__name__.component.spec.ts +31 -0
- package/lib/component/files/ts/__name__.component.ts +56 -0
- package/lib/component/schema.json +47 -0
- package/lib/configuration/configuration.factory.js +4 -4
- package/lib/configuration/configuration.factory.test.ts +60 -0
- package/lib/configuration/configuration.factory.ts +35 -0
- package/lib/configuration/configuration.schema.d.ts +18 -0
- package/lib/configuration/files/js/nest-cli.json +5 -0
- package/lib/configuration/files/ts/nest-cli.json +5 -0
- package/lib/controller/controller.factory.js +8 -8
- package/lib/controller/controller.factory.test.ts +191 -0
- package/lib/controller/controller.factory.ts +91 -0
- package/lib/controller/controller.schema.d.ts +44 -0
- package/lib/controller/files/js/__name__.controller.js +24 -0
- package/lib/controller/files/js/__name__.controller.spec.js +61 -0
- package/lib/controller/files/ts/__name__.controller.spec.ts +61 -0
- package/lib/controller/files/ts/__name__.controller.ts +24 -0
- package/lib/controller/schema.json +47 -0
- package/lib/decorator/decorator.factory.js +5 -5
- package/lib/decorator/decorator.factory.test.ts +111 -0
- package/lib/decorator/decorator.factory.ts +48 -0
- package/lib/decorator/decorator.schema.d.ts +24 -0
- package/lib/decorator/files/js/__name__.decorator.js +3 -0
- package/lib/decorator/files/ts/__name__.decorator.ts +3 -0
- package/lib/decorator/schema.json +35 -0
- package/lib/defaults.ts +6 -0
- package/lib/effect/effect.factory.js +9 -9
- package/lib/effect/effect.factory.test.ts +190 -0
- package/lib/effect/effect.factory.ts +91 -0
- package/lib/effect/effect.schema.d.ts +44 -0
- package/lib/effect/files/js/__name__.effect.js +11 -0
- package/lib/effect/files/js/__name__.effect.spec.js +17 -0
- package/lib/effect/files/ts/__name__.effect.spec.ts +17 -0
- package/lib/effect/files/ts/__name__.effect.ts +11 -0
- package/lib/effect/schema.json +39 -0
- package/lib/filter/files/js/__name__.filter.js +6 -0
- package/lib/filter/files/js/__name__.filter.spec.js +7 -0
- package/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
- package/lib/filter/files/ts/__name__.filter.ts +6 -0
- package/lib/filter/filter.factory.js +6 -6
- package/lib/filter/filter.factory.test.ts +147 -0
- package/lib/filter/filter.factory.ts +51 -0
- package/lib/filter/filter.schema.d.ts +28 -0
- package/lib/filter/schema.json +39 -0
- package/lib/gateway/files/js/__name__.gateway.js +9 -0
- package/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
- package/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
- package/lib/gateway/files/ts/__name__.gateway.ts +9 -0
- package/lib/gateway/gateway.factory.js +8 -8
- package/lib/gateway/gateway.factory.test.ts +147 -0
- package/lib/gateway/gateway.factory.ts +92 -0
- package/lib/gateway/gateway.schema.d.ts +36 -0
- package/lib/gateway/schema.json +39 -0
- package/lib/guard/files/js/__name__.guard.js +17 -0
- package/lib/guard/files/js/__name__.guard.spec.js +7 -0
- package/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
- package/lib/guard/files/ts/__name__.guard.ts +17 -0
- package/lib/guard/guard.factory.js +6 -6
- package/lib/guard/guard.factory.test.ts +156 -0
- package/lib/guard/guard.factory.ts +51 -0
- package/lib/guard/guard.schema.d.ts +28 -0
- package/lib/guard/schema.json +39 -0
- package/lib/interceptor/files/js/__name__.interceptor.js +18 -0
- package/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
- package/lib/interceptor/files/ts/__name__.interceptor.spec.ts +7 -0
- package/lib/interceptor/files/ts/__name__.interceptor.ts +19 -0
- package/lib/interceptor/interceptor.factory.js +6 -6
- package/lib/interceptor/interceptor.factory.test.ts +146 -0
- package/lib/interceptor/interceptor.factory.ts +51 -0
- package/lib/interceptor/interceptor.schema.d.ts +28 -0
- package/lib/interceptor/schema.json +39 -0
- package/lib/interface/files/__name__.interface.ts +1 -0
- package/lib/interface/interface.factory.js +5 -5
- package/lib/interface/interface.factory.test.ts +84 -0
- package/lib/interface/interface.factory.ts +47 -0
- package/lib/interface/interface.schema.d.ts +20 -0
- package/lib/interface/schema.json +31 -0
- package/lib/library/files/js/.babelrc +4 -0
- package/lib/library/files/js/jsconfig.json +9 -0
- package/lib/library/files/js/package.json +8 -0
- package/lib/library/files/js/src/__name__.module.js +8 -0
- package/lib/library/files/js/src/__name__.service.js +4 -0
- package/lib/library/files/js/src/__name__.service.spec.js +18 -0
- package/lib/library/files/js/src/index.js +2 -0
- package/lib/library/files/ts/package.json +8 -0
- package/lib/library/files/ts/src/__name__.module.ts +8 -0
- package/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
- package/lib/library/files/ts/src/__name__.service.ts +4 -0
- package/lib/library/files/ts/src/index.ts +2 -0
- package/lib/library/files/ts/tsconfig.lib.json +5 -0
- package/lib/library/library.factory.js +12 -12
- package/lib/library/library.factory.test.ts +68 -0
- package/lib/library/library.factory.ts +158 -0
- package/lib/library/library.schema.d.ts +24 -0
- package/lib/library/schema.json +37 -0
- package/lib/module/files/js/__name__.module.js +4 -0
- package/lib/module/files/ts/__name__.module.ts +4 -0
- package/lib/module/module.factory.js +7 -7
- package/lib/module/module.factory.test.ts +165 -0
- package/lib/module/module.factory.ts +79 -0
- package/lib/module/module.schema.d.ts +36 -0
- package/lib/module/schema.json +40 -0
- package/lib/pipe/files/js/__name__.pipe.js +8 -0
- package/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
- package/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
- package/lib/pipe/files/ts/__name__.pipe.ts +8 -0
- package/lib/pipe/pipe.factory.js +6 -6
- package/lib/pipe/pipe.factory.test.ts +141 -0
- package/lib/pipe/pipe.factory.ts +51 -0
- package/lib/pipe/pipe.schema.d.ts +28 -0
- package/lib/pipe/schema.json +39 -0
- package/lib/plugin/files/js/__name__.plugin.js +28 -0
- package/lib/plugin/files/js/__name__.plugin.spec.js +7 -0
- package/lib/plugin/files/ts/__name__.plugin.spec.ts +7 -0
- package/lib/plugin/files/ts/__name__.plugin.ts +28 -0
- package/lib/plugin/plugin.factory.d.ts +2 -2
- package/lib/plugin/plugin.factory.js +1 -2
- package/lib/plugin/plugin.factory.test.ts +191 -0
- package/lib/plugin/plugin.factory.ts +91 -0
- package/lib/plugin/plugin.schema.d.ts +44 -0
- package/lib/plugin/schema.json +52 -0
- package/lib/provider/files/js/__name__.js +4 -0
- package/lib/provider/files/js/__name__.spec.js +17 -0
- package/lib/provider/files/ts/__name__.spec.ts +17 -0
- package/lib/provider/files/ts/__name__.ts +4 -0
- package/lib/provider/provider.factory.js +1 -2
- package/lib/provider/provider.factory.test.ts +151 -0
- package/lib/provider/provider.factory.ts +89 -0
- package/lib/provider/provider.schema.d.ts +44 -0
- package/lib/provider/schema.json +39 -0
- package/lib/resolver/files/js/__name__.resolver.js +4 -0
- package/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
- package/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
- package/lib/resolver/files/ts/__name__.resolver.ts +4 -0
- package/lib/resolver/resolver.factory.js +8 -8
- package/lib/resolver/resolver.factory.test.ts +117 -0
- package/lib/resolver/resolver.factory.ts +92 -0
- package/lib/resolver/resolver.schema.d.ts +36 -0
- package/lib/resolver/schema.json +39 -0
- package/lib/service/files/js/__name__.service.js +4 -0
- package/lib/service/files/js/__name__.service.spec.js +17 -0
- package/lib/service/files/ts/__name__.service.spec.ts +17 -0
- package/lib/service/files/ts/__name__.service.ts +4 -0
- package/lib/service/schema.json +39 -0
- package/lib/service/service.factory.js +9 -9
- package/lib/service/service.factory.test.ts +190 -0
- package/lib/service/service.factory.ts +91 -0
- package/lib/service/service.schema.d.ts +44 -0
- package/lib/type/files/js/__name__.type.js +10 -0
- package/lib/type/files/ts/__name__.type.ts +10 -0
- package/lib/type/schema.json +43 -0
- package/lib/type/type.factory.d.ts +1 -1
- package/lib/type/type.factory.js +1 -2
- package/lib/type/type.factory.test.ts +191 -0
- package/lib/type/type.factory.ts +91 -0
- package/lib/type/type.schema.d.ts +44 -0
- package/package.json +2 -2
- package/utils/metadata.manager.js +1 -1
- package/utils/metadata.manager.ts +219 -0
- package/utils/module-import.declarator.js +2 -2
- package/utils/module-import.declarator.ts +41 -0
- package/utils/module-metadata.declarator.ts +14 -0
- package/utils/module.declarator.js +2 -2
- package/utils/module.declarator.ts +41 -0
- package/utils/module.finder.js +1 -1
- package/utils/module.finder.ts +32 -0
- package/utils/name.parser.js +3 -3
- package/utils/name.parser.ts +29 -0
- package/utils/path.solver.js +2 -2
- package/utils/path.solver.ts +17 -0
- package/utils/source-root.helpers.js +2 -2
- package/utils/source-root.helpers.ts +30 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrayLiteralExpression,
|
|
3
|
+
CallExpression,
|
|
4
|
+
createSourceFile,
|
|
5
|
+
Decorator,
|
|
6
|
+
Expression,
|
|
7
|
+
Identifier,
|
|
8
|
+
Node,
|
|
9
|
+
NodeArray,
|
|
10
|
+
ObjectLiteralElement,
|
|
11
|
+
ObjectLiteralExpression,
|
|
12
|
+
PropertyAssignment,
|
|
13
|
+
ScriptTarget,
|
|
14
|
+
SourceFile,
|
|
15
|
+
StringLiteral,
|
|
16
|
+
SyntaxKind,
|
|
17
|
+
} from 'typescript';
|
|
18
|
+
import { DeclarationOptions } from './module.declarator';
|
|
19
|
+
|
|
20
|
+
export class MetadataManager {
|
|
21
|
+
constructor(private content: string) {}
|
|
22
|
+
|
|
23
|
+
public insert(
|
|
24
|
+
metadata: string,
|
|
25
|
+
symbol: string,
|
|
26
|
+
staticOptions?: DeclarationOptions['staticOptions'],
|
|
27
|
+
): string {
|
|
28
|
+
const source: SourceFile = createSourceFile(
|
|
29
|
+
'filename.ts',
|
|
30
|
+
this.content,
|
|
31
|
+
ScriptTarget.ES2017,
|
|
32
|
+
);
|
|
33
|
+
const decoratorNodes: Node[] = this.getDecoratorMetadata(source, '@Module');
|
|
34
|
+
const node: Node = decoratorNodes[0];
|
|
35
|
+
const matchingProperties: ObjectLiteralElement[] = (node as ObjectLiteralExpression).properties
|
|
36
|
+
.filter(prop => prop.kind === SyntaxKind.PropertyAssignment)
|
|
37
|
+
.filter((prop: PropertyAssignment) => {
|
|
38
|
+
const name = prop.name;
|
|
39
|
+
switch (name.kind) {
|
|
40
|
+
case SyntaxKind.Identifier:
|
|
41
|
+
return (name as Identifier).getText(source) === metadata;
|
|
42
|
+
case SyntaxKind.StringLiteral:
|
|
43
|
+
return (name as StringLiteral).text === metadata;
|
|
44
|
+
default:
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
symbol = this.mergeSymbolAndExpr(symbol, staticOptions);
|
|
50
|
+
const addBlankLinesIfDynamic = () => {
|
|
51
|
+
symbol = staticOptions ? this.addBlankLines(symbol) : symbol;
|
|
52
|
+
};
|
|
53
|
+
if (matchingProperties.length === 0) {
|
|
54
|
+
const expr = node as ObjectLiteralExpression;
|
|
55
|
+
if (expr.properties.length === 0) {
|
|
56
|
+
addBlankLinesIfDynamic();
|
|
57
|
+
return this.insertMetadataToEmptyModuleDecorator(
|
|
58
|
+
expr,
|
|
59
|
+
metadata,
|
|
60
|
+
symbol,
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
addBlankLinesIfDynamic();
|
|
64
|
+
return this.insertNewMetadataToDecorator(
|
|
65
|
+
expr,
|
|
66
|
+
source,
|
|
67
|
+
metadata,
|
|
68
|
+
symbol,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
return this.insertSymbolToMetadata(
|
|
73
|
+
source,
|
|
74
|
+
matchingProperties,
|
|
75
|
+
symbol,
|
|
76
|
+
staticOptions,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private getDecoratorMetadata(source: SourceFile, identifier: string): Node[] {
|
|
82
|
+
return this.getSourceNodes(source)
|
|
83
|
+
.filter(
|
|
84
|
+
node =>
|
|
85
|
+
node.kind === SyntaxKind.Decorator &&
|
|
86
|
+
(node as Decorator).expression.kind === SyntaxKind.CallExpression,
|
|
87
|
+
)
|
|
88
|
+
.map(node => (node as Decorator).expression as CallExpression)
|
|
89
|
+
.filter(
|
|
90
|
+
expr =>
|
|
91
|
+
expr.arguments[0] &&
|
|
92
|
+
expr.arguments[0].kind === SyntaxKind.ObjectLiteralExpression,
|
|
93
|
+
)
|
|
94
|
+
.map(expr => expr.arguments[0] as ObjectLiteralExpression);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private getSourceNodes(sourceFile: SourceFile): Node[] {
|
|
98
|
+
const nodes: Node[] = [sourceFile];
|
|
99
|
+
const result = [];
|
|
100
|
+
while (nodes.length > 0) {
|
|
101
|
+
const node = nodes.shift();
|
|
102
|
+
if (node) {
|
|
103
|
+
result.push(node);
|
|
104
|
+
if (node.getChildCount(sourceFile) >= 0) {
|
|
105
|
+
nodes.unshift(...node.getChildren());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private insertMetadataToEmptyModuleDecorator(
|
|
113
|
+
expr: ObjectLiteralExpression,
|
|
114
|
+
metadata: string,
|
|
115
|
+
symbol: string,
|
|
116
|
+
): string {
|
|
117
|
+
const position = expr.getEnd() - 1;
|
|
118
|
+
const toInsert = ` ${metadata}: [${symbol}]`;
|
|
119
|
+
return this.content.split('').reduce((content, char, index) => {
|
|
120
|
+
if (index === position) {
|
|
121
|
+
return `${content}\n${toInsert}\n${char}`;
|
|
122
|
+
} else {
|
|
123
|
+
return `${content}${char}`;
|
|
124
|
+
}
|
|
125
|
+
}, '');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private insertNewMetadataToDecorator(
|
|
129
|
+
expr: ObjectLiteralExpression,
|
|
130
|
+
source: SourceFile,
|
|
131
|
+
metadata: string,
|
|
132
|
+
symbol: string,
|
|
133
|
+
): string {
|
|
134
|
+
const node = expr.properties[expr.properties.length - 1];
|
|
135
|
+
const position = node.getEnd();
|
|
136
|
+
const text = node.getFullText(source);
|
|
137
|
+
const matches = text.match(/^\r?\n\s*/);
|
|
138
|
+
let toInsert: string;
|
|
139
|
+
if (matches.length > 0) {
|
|
140
|
+
toInsert = `,${matches[0]}${metadata}: [${symbol}]`;
|
|
141
|
+
} else {
|
|
142
|
+
toInsert = `, ${metadata}: [${symbol}]`;
|
|
143
|
+
}
|
|
144
|
+
return this.content.split('').reduce((content, char, index) => {
|
|
145
|
+
if (index === position) {
|
|
146
|
+
return `${content}${toInsert}${char}`;
|
|
147
|
+
} else {
|
|
148
|
+
return `${content}${char}`;
|
|
149
|
+
}
|
|
150
|
+
}, '');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private insertSymbolToMetadata(
|
|
154
|
+
source: SourceFile,
|
|
155
|
+
matchingProperties: ObjectLiteralElement[],
|
|
156
|
+
symbol: string,
|
|
157
|
+
staticOptions?: DeclarationOptions['staticOptions'],
|
|
158
|
+
): string {
|
|
159
|
+
const assignment = matchingProperties[0] as PropertyAssignment;
|
|
160
|
+
let node: Node | NodeArray<Expression>;
|
|
161
|
+
const arrLiteral = assignment.initializer as ArrayLiteralExpression;
|
|
162
|
+
if (arrLiteral.elements.length === 0) {
|
|
163
|
+
node = arrLiteral;
|
|
164
|
+
} else {
|
|
165
|
+
node = arrLiteral.elements;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(node)) {
|
|
168
|
+
const nodeArray = (node as {}) as Node[];
|
|
169
|
+
const symbolsArray = nodeArray.map(childNode =>
|
|
170
|
+
childNode.getText(source),
|
|
171
|
+
);
|
|
172
|
+
if (symbolsArray.includes(symbol)) {
|
|
173
|
+
return this.content;
|
|
174
|
+
}
|
|
175
|
+
node = node[node.length - 1];
|
|
176
|
+
}
|
|
177
|
+
let toInsert: string;
|
|
178
|
+
let position = (node as Node).getEnd();
|
|
179
|
+
|
|
180
|
+
if ((node as Node).kind === SyntaxKind.ArrayLiteralExpression) {
|
|
181
|
+
position--;
|
|
182
|
+
toInsert = staticOptions ? this.addBlankLines(symbol) : `${symbol}`;
|
|
183
|
+
} else {
|
|
184
|
+
const text = (node as Node).getFullText(source);
|
|
185
|
+
if (text.match(/^\r?\n/)) {
|
|
186
|
+
toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbol}`;
|
|
187
|
+
} else {
|
|
188
|
+
toInsert = `, ${symbol}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return this.content.split('').reduce((content, char, index) => {
|
|
192
|
+
if (index === position) {
|
|
193
|
+
return `${content}${toInsert}${char}`;
|
|
194
|
+
} else {
|
|
195
|
+
return `${content}${char}`;
|
|
196
|
+
}
|
|
197
|
+
}, '');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private mergeSymbolAndExpr(
|
|
201
|
+
symbol: string,
|
|
202
|
+
staticOptions?: DeclarationOptions['staticOptions'],
|
|
203
|
+
): string {
|
|
204
|
+
if (!staticOptions) {
|
|
205
|
+
return symbol;
|
|
206
|
+
}
|
|
207
|
+
const spacing = 6;
|
|
208
|
+
let options = JSON.stringify(staticOptions.value, null, spacing);
|
|
209
|
+
options = options.replace(/\"([^(\")"]+)\":/g, '$1:');
|
|
210
|
+
options = options.replace(/\"/g, `'`);
|
|
211
|
+
options = options.slice(0, options.length - 1) + ' }';
|
|
212
|
+
symbol += `.${staticOptions.name}(${options})`;
|
|
213
|
+
return symbol;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private addBlankLines(expr: string): string {
|
|
217
|
+
return `\n ${expr}\n `;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -26,10 +26,10 @@ class ModuleImportDeclarator {
|
|
|
26
26
|
computeRelativePath(options) {
|
|
27
27
|
let importModulePath;
|
|
28
28
|
if (options.type !== undefined) {
|
|
29
|
-
importModulePath = core_1.normalize(`/${options.path}/${options.name}.${options.type}`);
|
|
29
|
+
importModulePath = (0, core_1.normalize)(`/${options.path}/${options.name}.${options.type}`);
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
importModulePath = core_1.normalize(`/${options.path}/${options.name}`);
|
|
32
|
+
importModulePath = (0, core_1.normalize)(`/${options.path}/${options.name}`);
|
|
33
33
|
}
|
|
34
34
|
return this.solver.relative(options.module, importModulePath);
|
|
35
35
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { normalize, Path } from '@angular-devkit/core';
|
|
2
|
+
import { DeclarationOptions } from './module.declarator';
|
|
3
|
+
import { PathSolver } from './path.solver';
|
|
4
|
+
|
|
5
|
+
export class ModuleImportDeclarator {
|
|
6
|
+
constructor(private solver: PathSolver = new PathSolver()) {}
|
|
7
|
+
|
|
8
|
+
public declare(content: string, options: DeclarationOptions): string {
|
|
9
|
+
const toInsert: string = this.buildLineToInsert(options);
|
|
10
|
+
const importLines: string[] = this.findImports(content);
|
|
11
|
+
const otherLines: string[] = this.findOtherLines(content, importLines);
|
|
12
|
+
importLines.push(toInsert);
|
|
13
|
+
return importLines.join('\n').concat(otherLines.join('\n'));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private findImports(content: string): string[] {
|
|
17
|
+
return content.split('\n').filter(line => line.match(/import {/));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private findOtherLines(content: string, importLines: string[]) {
|
|
21
|
+
return content.split('\n').filter(line => importLines.indexOf(line) < 0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private buildLineToInsert(options: DeclarationOptions): string {
|
|
25
|
+
return `import { ${options.symbol} } from '${this.computeRelativePath(
|
|
26
|
+
options,
|
|
27
|
+
)}';\n`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private computeRelativePath(options: DeclarationOptions): string {
|
|
31
|
+
let importModulePath: Path;
|
|
32
|
+
if (options.type !== undefined) {
|
|
33
|
+
importModulePath = normalize(
|
|
34
|
+
`/${options.path}/${options.name}.${options.type}`,
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
importModulePath = normalize(`/${options.path}/${options.name}`);
|
|
38
|
+
}
|
|
39
|
+
return this.solver.relative(options.module, importModulePath);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MetadataManager } from './metadata.manager';
|
|
2
|
+
import { DeclarationOptions } from './module.declarator';
|
|
3
|
+
|
|
4
|
+
export class ModuleMetadataDeclarator {
|
|
5
|
+
public declare(content: string, options: DeclarationOptions): string {
|
|
6
|
+
const manager = new MetadataManager(content);
|
|
7
|
+
const inserted = manager.insert(
|
|
8
|
+
options.metadata,
|
|
9
|
+
options.symbol,
|
|
10
|
+
options.staticOptions,
|
|
11
|
+
);
|
|
12
|
+
return inserted;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -18,10 +18,10 @@ class ModuleDeclarator {
|
|
|
18
18
|
computeSymbol(options) {
|
|
19
19
|
const target = Object.assign({}, options);
|
|
20
20
|
if (options.type !== undefined) {
|
|
21
|
-
target.symbol = strings_1.classify(options.name).concat(strings_1.capitalize(options.type));
|
|
21
|
+
target.symbol = (0, strings_1.classify)(options.name).concat((0, strings_1.capitalize)(options.type));
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
|
-
target.symbol = strings_1.classify(options.name);
|
|
24
|
+
target.symbol = (0, strings_1.classify)(options.name);
|
|
25
25
|
}
|
|
26
26
|
return target;
|
|
27
27
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Path } from '@angular-devkit/core';
|
|
2
|
+
import { capitalize, classify } from '@angular-devkit/core/src/utils/strings';
|
|
3
|
+
import { ModuleImportDeclarator } from './module-import.declarator';
|
|
4
|
+
import { ModuleMetadataDeclarator } from './module-metadata.declarator';
|
|
5
|
+
|
|
6
|
+
export interface DeclarationOptions {
|
|
7
|
+
metadata: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
path: Path;
|
|
11
|
+
module: Path;
|
|
12
|
+
symbol?: string;
|
|
13
|
+
staticOptions?: {
|
|
14
|
+
name: string;
|
|
15
|
+
value: Record<string, any>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class ModuleDeclarator {
|
|
20
|
+
constructor(
|
|
21
|
+
private imports: ModuleImportDeclarator = new ModuleImportDeclarator(),
|
|
22
|
+
private metadata: ModuleMetadataDeclarator = new ModuleMetadataDeclarator(),
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
public declare(content: string, options: DeclarationOptions): string {
|
|
26
|
+
options = this.computeSymbol(options);
|
|
27
|
+
content = this.imports.declare(content, options);
|
|
28
|
+
content = this.metadata.declare(content, options);
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private computeSymbol(options: DeclarationOptions): DeclarationOptions {
|
|
33
|
+
const target = Object.assign({}, options);
|
|
34
|
+
if (options.type !== undefined) {
|
|
35
|
+
target.symbol = classify(options.name).concat(capitalize(options.type));
|
|
36
|
+
} else {
|
|
37
|
+
target.symbol = classify(options.name);
|
|
38
|
+
}
|
|
39
|
+
return target;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/utils/module.finder.js
CHANGED
|
@@ -17,7 +17,7 @@ class ModuleFinder {
|
|
|
17
17
|
}
|
|
18
18
|
const moduleFilename = directory.subfiles.find(filename => /\.module\.(t|j)s/.test(filename));
|
|
19
19
|
return moduleFilename !== undefined
|
|
20
|
-
? core_1.join(directory.path, moduleFilename.valueOf())
|
|
20
|
+
? (0, core_1.join)(directory.path, moduleFilename.valueOf())
|
|
21
21
|
: this.findIn(directory.parent);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { join, Path, PathFragment } from '@angular-devkit/core';
|
|
2
|
+
import { DirEntry, Tree } from '@angular-devkit/schematics';
|
|
3
|
+
|
|
4
|
+
export interface FindOptions {
|
|
5
|
+
name?: string;
|
|
6
|
+
path: Path;
|
|
7
|
+
kind?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class ModuleFinder {
|
|
11
|
+
constructor(private tree: Tree) {}
|
|
12
|
+
|
|
13
|
+
public find(options: FindOptions): Path | null {
|
|
14
|
+
const generatedDirectoryPath: Path = options.path;
|
|
15
|
+
const generatedDirectory: DirEntry = this.tree.getDir(
|
|
16
|
+
generatedDirectoryPath,
|
|
17
|
+
);
|
|
18
|
+
return this.findIn(generatedDirectory);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private findIn(directory: DirEntry): Path | null {
|
|
22
|
+
if (!directory) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const moduleFilename: PathFragment = directory.subfiles.find(filename =>
|
|
26
|
+
/\.module\.(t|j)s/.test(filename),
|
|
27
|
+
);
|
|
28
|
+
return moduleFilename !== undefined
|
|
29
|
+
? join(directory.path, moduleFilename.valueOf())
|
|
30
|
+
: this.findIn(directory.parent);
|
|
31
|
+
}
|
|
32
|
+
}
|
package/utils/name.parser.js
CHANGED
|
@@ -5,15 +5,15 @@ const core_1 = require("@angular-devkit/core");
|
|
|
5
5
|
class NameParser {
|
|
6
6
|
constructor() { }
|
|
7
7
|
parse(options) {
|
|
8
|
-
const nameWithoutPath = core_1.basename(options.name);
|
|
9
|
-
const namePath = core_1.dirname((options.path === undefined
|
|
8
|
+
const nameWithoutPath = (0, core_1.basename)(options.name);
|
|
9
|
+
const namePath = (0, core_1.dirname)((options.path === undefined
|
|
10
10
|
? ''
|
|
11
11
|
: options.path)
|
|
12
12
|
.concat('/')
|
|
13
13
|
.concat(options.name));
|
|
14
14
|
return {
|
|
15
15
|
name: nameWithoutPath,
|
|
16
|
-
path: core_1.normalize('/'.concat(namePath)),
|
|
16
|
+
path: (0, core_1.normalize)('/'.concat(namePath)),
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { basename, dirname, normalize, Path } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export interface ParseOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Location {
|
|
9
|
+
name: string;
|
|
10
|
+
path: Path;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class NameParser {
|
|
14
|
+
constructor() {}
|
|
15
|
+
|
|
16
|
+
public parse(options: ParseOptions): Location {
|
|
17
|
+
const nameWithoutPath: string = basename(options.name as Path);
|
|
18
|
+
const namePath: string = dirname((options.path === undefined
|
|
19
|
+
? ''
|
|
20
|
+
: options.path
|
|
21
|
+
)
|
|
22
|
+
.concat('/')
|
|
23
|
+
.concat(options.name) as Path);
|
|
24
|
+
return {
|
|
25
|
+
name: nameWithoutPath,
|
|
26
|
+
path: normalize('/'.concat(namePath)),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
package/utils/path.solver.js
CHANGED
|
@@ -6,10 +6,10 @@ class PathSolver {
|
|
|
6
6
|
constructor() { }
|
|
7
7
|
relative(from, to) {
|
|
8
8
|
const placeholder = '/placeholder';
|
|
9
|
-
const relativeDir = core_1.relative(core_1.dirname((placeholder + from)), core_1.dirname((placeholder + to)));
|
|
9
|
+
const relativeDir = (0, core_1.relative)((0, core_1.dirname)((placeholder + from)), (0, core_1.dirname)((placeholder + to)));
|
|
10
10
|
return (relativeDir.startsWith('.')
|
|
11
11
|
? relativeDir
|
|
12
|
-
: './' + relativeDir).concat(relativeDir.length === 0 ? core_1.basename(to) : '/' + core_1.basename(to));
|
|
12
|
+
: './' + relativeDir).concat(relativeDir.length === 0 ? (0, core_1.basename)(to) : '/' + (0, core_1.basename)(to));
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.PathSolver = PathSolver;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { basename, dirname, Path, relative } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export class PathSolver {
|
|
4
|
+
constructor() {}
|
|
5
|
+
|
|
6
|
+
public relative(from: Path, to: Path): string {
|
|
7
|
+
const placeholder = '/placeholder';
|
|
8
|
+
const relativeDir = relative(
|
|
9
|
+
dirname((placeholder + from) as Path),
|
|
10
|
+
dirname((placeholder + to) as Path),
|
|
11
|
+
);
|
|
12
|
+
return (relativeDir.startsWith('.')
|
|
13
|
+
? relativeDir
|
|
14
|
+
: './' + relativeDir
|
|
15
|
+
).concat(relativeDir.length === 0 ? basename(to) : '/' + basename(to));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -17,8 +17,8 @@ function mergeSourceRoot(options) {
|
|
|
17
17
|
const defaultSourceRoot = options.sourceRoot !== undefined ? options.sourceRoot : defaults_1.DEFAULT_PATH_NAME;
|
|
18
18
|
options.path =
|
|
19
19
|
options.path !== undefined
|
|
20
|
-
? core_1.join(core_1.normalize(defaultSourceRoot), options.path)
|
|
21
|
-
: core_1.normalize(defaultSourceRoot);
|
|
20
|
+
? (0, core_1.join)((0, core_1.normalize)(defaultSourceRoot), options.path)
|
|
21
|
+
: (0, core_1.normalize)(defaultSourceRoot);
|
|
22
22
|
return host;
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { join, normalize } from '@angular-devkit/core';
|
|
2
|
+
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
3
|
+
import { DEFAULT_PATH_NAME } from '../lib/defaults';
|
|
4
|
+
|
|
5
|
+
export function isInRootDirectory(
|
|
6
|
+
host: Tree,
|
|
7
|
+
extraFiles: string[] = [],
|
|
8
|
+
): boolean {
|
|
9
|
+
const files = ['nest-cli.json', 'nest.json'].concat(extraFiles || []);
|
|
10
|
+
return files.map(file => host.exists(file)).some(isPresent => isPresent);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function mergeSourceRoot<
|
|
14
|
+
T extends { sourceRoot?: string; path?: string } = any
|
|
15
|
+
>(options: T): Rule {
|
|
16
|
+
return (host: Tree) => {
|
|
17
|
+
const isInRoot = isInRootDirectory(host, ['tsconfig.json', 'package.json']);
|
|
18
|
+
if (!isInRoot) {
|
|
19
|
+
return host;
|
|
20
|
+
}
|
|
21
|
+
const defaultSourceRoot =
|
|
22
|
+
options.sourceRoot !== undefined ? options.sourceRoot : DEFAULT_PATH_NAME;
|
|
23
|
+
|
|
24
|
+
options.path =
|
|
25
|
+
options.path !== undefined
|
|
26
|
+
? join(normalize(defaultSourceRoot), options.path)
|
|
27
|
+
: normalize(defaultSourceRoot);
|
|
28
|
+
return host;
|
|
29
|
+
};
|
|
30
|
+
}
|