@ihk-gfi/lux-components-update 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +198 -0
- package/README.md +55 -0
- package/package.json +54 -0
- package/src/add-lux-components/files/app/app-routing.module.ts +19 -0
- package/src/add-lux-components/files/app/app.component.html +27 -0
- package/src/add-lux-components/files/app/app.component.spec.ts +19 -0
- package/src/add-lux-components/files/app/app.component.ts +13 -0
- package/src/add-lux-components/files/app/app.module.ts +56 -0
- package/src/add-lux-components/files/app/error/error.component.html +10 -0
- package/src/add-lux-components/files/app/error/error.component.scss +3 -0
- package/src/add-lux-components/files/app/error/error.component.spec.ts +49 -0
- package/src/add-lux-components/files/app/error/error.component.ts +17 -0
- package/src/add-lux-components/files/app/home/home.component.html +7 -0
- package/src/add-lux-components/files/app/home/home.component.scss +0 -0
- package/src/add-lux-components/files/app/home/home.component.ts +13 -0
- package/src/add-lux-components/files/app/profil/profil.component.html +1 -0
- package/src/add-lux-components/files/app/profil/profil.component.scss +0 -0
- package/src/add-lux-components/files/app/profil/profil.component.spec.ts +24 -0
- package/src/add-lux-components/files/app/profil/profil.component.ts +11 -0
- package/src/add-lux-components/files/environments/environment.prod.ts +4 -0
- package/src/add-lux-components/files/environments/environment.ts +17 -0
- package/src/add-lux-components/files/locale/messages.en.xlf +948 -0
- package/src/add-lux-components/files/locale/messages.xlf +822 -0
- package/src/add-lux-components/files/scripts/.browserslistrc +17 -0
- package/src/add-lux-components/files/src/polyfills.ts +68 -0
- package/src/add-lux-components/index.d.ts +10 -0
- package/src/add-lux-components/index.js +143 -0
- package/src/add-lux-components/index.js.map +1 -0
- package/src/add-lux-components/index.ts +183 -0
- package/src/add-lux-components/index_spec.d.ts +1 -0
- package/src/add-lux-components/index_spec.js +51 -0
- package/src/add-lux-components/index_spec.js.map +1 -0
- package/src/add-lux-components/index_spec.ts +55 -0
- package/src/add-lux-components/schema.json +23 -0
- package/src/collection.json +55 -0
- package/src/migrate-to-eslint/files/.eslintrc.json +68 -0
- package/src/migrate-to-eslint/files/.prettierrc +25 -0
- package/src/migrate-to-eslint/index.d.ts +6 -0
- package/src/migrate-to-eslint/index.js +149 -0
- package/src/migrate-to-eslint/index.js.map +1 -0
- package/src/migrate-to-eslint/index.ts +181 -0
- package/src/migrate-to-eslint/index_spec.d.ts +1 -0
- package/src/migrate-to-eslint/index_spec.js +129 -0
- package/src/migrate-to-eslint/index_spec.js.map +1 -0
- package/src/migrate-to-eslint/index_spec.ts +152 -0
- package/src/migrate-to-eslint/schema.json +23 -0
- package/src/migrate-to-webcomponent/index.d.ts +10 -0
- package/src/migrate-to-webcomponent/index.js +278 -0
- package/src/migrate-to-webcomponent/index.js.map +1 -0
- package/src/migrate-to-webcomponent/index.ts +331 -0
- package/src/migrate-to-webcomponent/index_spec.d.ts +1 -0
- package/src/migrate-to-webcomponent/index_spec.js +580 -0
- package/src/migrate-to-webcomponent/index_spec.js.map +1 -0
- package/src/migrate-to-webcomponent/index_spec.ts +703 -0
- package/src/migrate-to-webcomponent/schema.json +23 -0
- package/src/update/files/locale/messages.en.xlf +940 -0
- package/src/update/files/locale/messages.xlf +815 -0
- package/src/update/files/scripts/move-de-files.js +15 -0
- package/src/update/index.d.ts +23 -0
- package/src/update/index.js +635 -0
- package/src/update/index.js.map +1 -0
- package/src/update/index.ts +712 -0
- package/src/update/index_spec.d.ts +1 -0
- package/src/update/index_spec.js +990 -0
- package/src/update/index_spec.js.map +1 -0
- package/src/update/index_spec.ts +1145 -0
- package/src/update/schema.json +23 -0
- package/src/update-dependencies/index.d.ts +5 -0
- package/src/update-dependencies/index.js +113 -0
- package/src/update-dependencies/index.js.map +1 -0
- package/src/update-dependencies/index.ts +114 -0
- package/src/update-dependencies/schema.json +23 -0
- package/src/update110001/index.d.ts +2 -0
- package/src/update110001/index.js +42 -0
- package/src/update110001/index.js.map +1 -0
- package/src/update110001/index.ts +40 -0
- package/src/update110001/index_spec.d.ts +1 -0
- package/src/update110001/index_spec.js +67 -0
- package/src/update110001/index_spec.js.map +1 -0
- package/src/update110001/index_spec.ts +72 -0
- package/src/update110001/schema.json +23 -0
- package/src/update110100/index.d.ts +2 -0
- package/src/update110100/index.js +27 -0
- package/src/update110100/index.js.map +1 -0
- package/src/update110100/index.ts +24 -0
- package/src/update110100/index_spec.d.ts +1 -0
- package/src/update110100/index_spec.js +69 -0
- package/src/update110100/index_spec.js.map +1 -0
- package/src/update110100/index_spec.ts +73 -0
- package/src/update110100/schema.json +23 -0
- package/src/update110101/index.d.ts +2 -0
- package/src/update110101/index.js +24 -0
- package/src/update110101/index.js.map +1 -0
- package/src/update110101/index.ts +21 -0
- package/src/update110101/index_spec.d.ts +1 -0
- package/src/update110101/index_spec.js +65 -0
- package/src/update110101/index_spec.js.map +1 -0
- package/src/update110101/index_spec.ts +69 -0
- package/src/update110101/schema.json +23 -0
- package/src/update110200/index.d.ts +2 -0
- package/src/update110200/index.js +24 -0
- package/src/update110200/index.js.map +1 -0
- package/src/update110200/index.ts +21 -0
- package/src/update110200/index_spec.d.ts +1 -0
- package/src/update110200/index_spec.js +65 -0
- package/src/update110200/index_spec.js.map +1 -0
- package/src/update110200/index_spec.ts +69 -0
- package/src/update110200/schema.json +23 -0
- package/src/update110300/index.d.ts +2 -0
- package/src/update110300/index.js +133 -0
- package/src/update110300/index.js.map +1 -0
- package/src/update110300/index.ts +148 -0
- package/src/update110300/index_spec.d.ts +1 -0
- package/src/update110300/index_spec.js +121 -0
- package/src/update110300/index_spec.js.map +1 -0
- package/src/update110300/index_spec.ts +139 -0
- package/src/update110300/schema.json +23 -0
- package/src/utility/dependencies.d.ts +39 -0
- package/src/utility/dependencies.js +96 -0
- package/src/utility/dependencies.js.map +1 -0
- package/src/utility/dependencies.ts +116 -0
- package/src/utility/files.d.ts +60 -0
- package/src/utility/files.js +299 -0
- package/src/utility/files.js.map +1 -0
- package/src/utility/files.ts +355 -0
- package/src/utility/html.d.ts +49 -0
- package/src/utility/html.js +183 -0
- package/src/utility/html.js.map +1 -0
- package/src/utility/html.ts +212 -0
- package/src/utility/json.d.ts +34 -0
- package/src/utility/json.js +70 -0
- package/src/utility/json.js.map +1 -0
- package/src/utility/json.ts +70 -0
- package/src/utility/logging.d.ts +32 -0
- package/src/utility/logging.js +82 -0
- package/src/utility/logging.js.map +1 -0
- package/src/utility/logging.ts +80 -0
- package/src/utility/test.d.ts +10 -0
- package/src/utility/test.js +24 -0
- package/src/utility/test.js.map +1 -0
- package/src/utility/test.ts +24 -0
- package/src/utility/typescript.d.ts +22 -0
- package/src/utility/typescript.js +521 -0
- package/src/utility/typescript.js.map +1 -0
- package/src/utility/typescript.ts +598 -0
- package/src/utility/typescript_spec.d.ts +1 -0
- package/src/utility/typescript_spec.js +1006 -0
- package/src/utility/typescript_spec.js.map +1 -0
- package/src/utility/typescript_spec.ts +1267 -0
- package/src/utility/util.d.ts +33 -0
- package/src/utility/util.js +139 -0
- package/src/utility/util.js.map +1 -0
- package/src/utility/util.ts +140 -0
- package/src/utility/validation.d.ts +11 -0
- package/src/utility/validation.js +44 -0
- package/src/utility/validation.js.map +1 -0
- package/src/utility/validation.ts +49 -0
- package/tsconfig.json +37 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { SchematicsException, Tree } from '@angular-devkit/schematics';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import { logInfo } from './logging';
|
|
4
|
+
|
|
5
|
+
export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
|
|
6
|
+
const nodes: ts.Node[] = [sourceFile];
|
|
7
|
+
const result: ts.Node[] = [];
|
|
8
|
+
|
|
9
|
+
while (nodes.length > 0) {
|
|
10
|
+
const node = nodes.shift();
|
|
11
|
+
|
|
12
|
+
if (node) {
|
|
13
|
+
result.push(node);
|
|
14
|
+
if (node.getChildCount(sourceFile) >= 0) {
|
|
15
|
+
nodes.unshift(...node.getChildren());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function addInterface(tree: Tree, filePath: string, interfaceName: string, logMessage = true) {
|
|
24
|
+
const content = (tree.read(filePath) as Buffer).toString();
|
|
25
|
+
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
|
|
26
|
+
const sourceFile = ts.createSourceFile(`${ fileName }`, content, ts.ScriptTarget.Latest, true);
|
|
27
|
+
const nodes = getSourceNodes(sourceFile);
|
|
28
|
+
|
|
29
|
+
const classNode = nodes.find((n) => n.kind === ts.SyntaxKind.ClassDeclaration);
|
|
30
|
+
if (classNode) {
|
|
31
|
+
const implementsNode = findChild(classNode, ts.SyntaxKind.FirstFutureReservedWord, 'implements');
|
|
32
|
+
const extendsNode = findChild(classNode, ts.SyntaxKind.ExtendsKeyword, 'extends');
|
|
33
|
+
|
|
34
|
+
if (implementsNode) {
|
|
35
|
+
const syntaxListNode = findChild(implementsNode.parent, ts.SyntaxKind.SyntaxList);
|
|
36
|
+
|
|
37
|
+
if (syntaxListNode) {
|
|
38
|
+
const lastChild = syntaxListNode.getChildren()[syntaxListNode.getChildren().length - 1];
|
|
39
|
+
|
|
40
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
41
|
+
updateRecorder.insertLeft(lastChild.end, `, ${interfaceName}`);
|
|
42
|
+
tree.commitUpdate(updateRecorder);
|
|
43
|
+
if (logMessage) {
|
|
44
|
+
logInfo(`Interface ${interfaceName} hinzugefügt.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
if (extendsNode) {
|
|
49
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
50
|
+
updateRecorder.insertLeft(extendsNode.parent.end, ` implements ${interfaceName}`)
|
|
51
|
+
tree.commitUpdate(updateRecorder);
|
|
52
|
+
if (logMessage) {
|
|
53
|
+
logInfo(`Interface ${interfaceName} hinzugefügt.`);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
const classKeywordNode = findChild(classNode, ts.SyntaxKind.ClassKeyword);
|
|
57
|
+
|
|
58
|
+
if (!classKeywordNode) {
|
|
59
|
+
throw new SchematicsException(`Die Klasse ${ filePath } hat kein ClassKeyword.`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const classIdentifierNode = getNextSibling(classKeywordNode);
|
|
63
|
+
|
|
64
|
+
if (!classIdentifierNode) {
|
|
65
|
+
throw new SchematicsException(`Die Klasse ${ filePath } hat keinen Namen.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
69
|
+
updateRecorder.insertLeft(classIdentifierNode.end, ` implements ${interfaceName}`)
|
|
70
|
+
tree.commitUpdate(updateRecorder);
|
|
71
|
+
if (logMessage) {
|
|
72
|
+
logInfo(`Interface ${interfaceName} hinzugefügt.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function removeInterface(tree: Tree, filePath: string, interfaceName: string, logMessage = true) {
|
|
80
|
+
const content = (tree.read(filePath) as Buffer).toString();
|
|
81
|
+
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
|
|
82
|
+
const sourceFile = ts.createSourceFile(`${fileName}`, content, ts.ScriptTarget.Latest, true);
|
|
83
|
+
const nodes = getSourceNodes(sourceFile);
|
|
84
|
+
|
|
85
|
+
const classNode = nodes.find((n) => n.kind === ts.SyntaxKind.ClassDeclaration);
|
|
86
|
+
|
|
87
|
+
if (classNode) {
|
|
88
|
+
const syntaxListClassNodes = classNode.getChildren().filter((n) => n.kind === ts.SyntaxKind.SyntaxList);
|
|
89
|
+
|
|
90
|
+
if (syntaxListClassNodes) {
|
|
91
|
+
syntaxListClassNodes.forEach((syntaxListNode) => {
|
|
92
|
+
const heritageClauseNodes = syntaxListNode.getChildren().filter((n) => n.kind === ts.SyntaxKind.HeritageClause);
|
|
93
|
+
if (heritageClauseNodes) {
|
|
94
|
+
heritageClauseNodes.forEach((heritageClauseNode) => {
|
|
95
|
+
const wordNode = heritageClauseNode
|
|
96
|
+
.getChildren()
|
|
97
|
+
.find((n) => n.kind === ts.SyntaxKind.FirstFutureReservedWord);
|
|
98
|
+
if (wordNode && wordNode.getText() === 'implements') {
|
|
99
|
+
const interfaceSyntaxNode = heritageClauseNode
|
|
100
|
+
.getChildren()
|
|
101
|
+
.find((n) => n.kind === ts.SyntaxKind.SyntaxList);
|
|
102
|
+
if (interfaceSyntaxNode) {
|
|
103
|
+
const interfaceChildren = interfaceSyntaxNode.getChildren();
|
|
104
|
+
if (interfaceChildren) {
|
|
105
|
+
if (interfaceChildren.length === 1) {
|
|
106
|
+
if (interfaceChildren[0].getText() === interfaceName) {
|
|
107
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
108
|
+
updateRecorder.remove(
|
|
109
|
+
heritageClauseNode.pos,
|
|
110
|
+
heritageClauseNode.getChildren()[heritageClauseNode.getChildren().length - 1].end -
|
|
111
|
+
heritageClauseNode.pos
|
|
112
|
+
);
|
|
113
|
+
tree.commitUpdate(updateRecorder);
|
|
114
|
+
if (logMessage) {
|
|
115
|
+
logInfo(`Interface ${interfaceName} entfernt.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
for (let i = 0; i < interfaceChildren.length; i++) {
|
|
120
|
+
if (interfaceChildren[i].getText() === interfaceName) {
|
|
121
|
+
const prevSibling = getPrevSibling(interfaceChildren[i], ts.SyntaxKind.SyntaxList);
|
|
122
|
+
const nextSibling = getNextSibling(interfaceChildren[i], ts.SyntaxKind.SyntaxList);
|
|
123
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
124
|
+
if (nextSibling) {
|
|
125
|
+
updateRecorder.remove(interfaceChildren[i].pos, nextSibling.end - interfaceChildren[i].pos);
|
|
126
|
+
} else {
|
|
127
|
+
if (prevSibling) {
|
|
128
|
+
updateRecorder.remove(prevSibling.pos, interfaceChildren[i].end - prevSibling.pos);
|
|
129
|
+
} else {
|
|
130
|
+
updateRecorder.remove(
|
|
131
|
+
interfaceChildren[i].pos,
|
|
132
|
+
interfaceChildren[i].end - interfaceChildren[i].pos
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
tree.commitUpdate(updateRecorder);
|
|
137
|
+
if (logMessage) {
|
|
138
|
+
logInfo(`Interface ${interfaceName} entfernt.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function addImport(tree: Tree, filePath: string, packageName: string, importName?: string, logMessage = true) {
|
|
154
|
+
const content = (tree.read(filePath) as Buffer).toString();
|
|
155
|
+
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
|
|
156
|
+
const sourceFile = ts.createSourceFile(`${fileName}`, content, ts.ScriptTarget.Latest, true);
|
|
157
|
+
const nodes = getSourceNodes(sourceFile);
|
|
158
|
+
|
|
159
|
+
const importNodes = nodes.filter((n) => n.kind === ts.SyntaxKind.ImportDeclaration);
|
|
160
|
+
|
|
161
|
+
let importNode: ts.Node | undefined = undefined;
|
|
162
|
+
|
|
163
|
+
if (importNodes) {
|
|
164
|
+
importNodes.forEach((node) => {
|
|
165
|
+
const importDeclarationChildren = node.getChildren();
|
|
166
|
+
|
|
167
|
+
if (importDeclarationChildren) {
|
|
168
|
+
const importNameNode = importDeclarationChildren.find(
|
|
169
|
+
(n) =>
|
|
170
|
+
n.kind === ts.SyntaxKind.StringLiteral &&
|
|
171
|
+
(n.getText() === `'${packageName}'` || n.getText() === `"${packageName}"`)
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
if (importNameNode) {
|
|
175
|
+
importNode = node;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if(importNode) {
|
|
182
|
+
const importClauseNode = (importNode as ts.Node).getChildren().find((n) => n.kind === ts.SyntaxKind.ImportClause);
|
|
183
|
+
|
|
184
|
+
if (importClauseNode) {
|
|
185
|
+
const namedImportsNode = importClauseNode.getChildren().find((n) => n.kind === ts.SyntaxKind.NamedImports);
|
|
186
|
+
|
|
187
|
+
if (!namedImportsNode) {
|
|
188
|
+
throw new SchematicsException(`In der Datei ${ filePath } gibt es keine NamedImports.`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const syntaxListNode = namedImportsNode.getChildren().find((n) => n.kind === ts.SyntaxKind.SyntaxList);
|
|
192
|
+
|
|
193
|
+
if (!syntaxListNode) {
|
|
194
|
+
throw new SchematicsException(`In der Datei ${ filePath } gibt es keine SyntaxList für den Import.`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const importChildren = syntaxListNode.getChildren();
|
|
198
|
+
const foundNode = importName ? findChild(syntaxListNode, ts.SyntaxKind.Identifier, importName) : undefined;
|
|
199
|
+
if (!foundNode) {
|
|
200
|
+
const lastChildNode = importChildren[ syntaxListNode.getChildren().length - 1];
|
|
201
|
+
|
|
202
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
203
|
+
updateRecorder.insertLeft(lastChildNode.end, ', ' + importName);
|
|
204
|
+
tree.commitUpdate(updateRecorder);
|
|
205
|
+
if (logMessage) {
|
|
206
|
+
logInfo(`Import ${importName} hinzugefügt.`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
212
|
+
if (importName) {
|
|
213
|
+
updateRecorder.insertLeft(0, `import { ${importName} } from '${packageName}';\n`);
|
|
214
|
+
} else {
|
|
215
|
+
updateRecorder.insertLeft(0, `import '${packageName}';\n`);
|
|
216
|
+
}
|
|
217
|
+
tree.commitUpdate(updateRecorder);
|
|
218
|
+
if (logMessage) {
|
|
219
|
+
logInfo(`Import ${importName} hinzugefügt.`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function removeImport(
|
|
225
|
+
tree: Tree,
|
|
226
|
+
filePath: string,
|
|
227
|
+
packageName: string,
|
|
228
|
+
importName?: string,
|
|
229
|
+
logMessage = true
|
|
230
|
+
) {
|
|
231
|
+
const content = (tree.read(filePath) as Buffer).toString();
|
|
232
|
+
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
|
|
233
|
+
const sourceFile = ts.createSourceFile(`${fileName}`, content, ts.ScriptTarget.Latest, true);
|
|
234
|
+
const nodes = getSourceNodes(sourceFile);
|
|
235
|
+
|
|
236
|
+
const importNodes = nodes.filter((n) => n.kind === ts.SyntaxKind.ImportDeclaration);
|
|
237
|
+
|
|
238
|
+
if (importNodes) {
|
|
239
|
+
importNodes.forEach((importNode) => {
|
|
240
|
+
const importDeclarationChildren = importNode.getChildren();
|
|
241
|
+
|
|
242
|
+
if (!importDeclarationChildren) {
|
|
243
|
+
throw new SchematicsException(`In der Datei ${filePath} gibt es keine ImportDeclaration.`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const importNameNode = importDeclarationChildren.find(
|
|
247
|
+
(n) => n.kind === ts.SyntaxKind.StringLiteral && (n.getText() === `'${packageName}'` || n.getText() === `"${packageName}"`)
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
if (importNameNode) {
|
|
251
|
+
if (importName) {
|
|
252
|
+
const importClauseNode = importNode.getChildren().find((n) => n.kind === ts.SyntaxKind.ImportClause);
|
|
253
|
+
|
|
254
|
+
if (!importClauseNode) {
|
|
255
|
+
throw new SchematicsException(`In der Datei ${filePath} gibt es keine ImportClause.`);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const namedImportsNode = importClauseNode.getChildren().find((n) => n.kind === ts.SyntaxKind.NamedImports);
|
|
259
|
+
|
|
260
|
+
if (!namedImportsNode) {
|
|
261
|
+
throw new SchematicsException(`In der Datei ${filePath} gibt es keine NamedImports.`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const syntaxListNode = namedImportsNode.getChildren().find((n) => n.kind === ts.SyntaxKind.SyntaxList);
|
|
265
|
+
|
|
266
|
+
if (!syntaxListNode) {
|
|
267
|
+
throw new SchematicsException(`In der Datei ${filePath} gibt es keine SyntaxList.`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const importChildren = syntaxListNode.getChildren();
|
|
271
|
+
if (importChildren) {
|
|
272
|
+
if (importChildren.length === 1) {
|
|
273
|
+
if (importChildren[0].getText() === importName) {
|
|
274
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
275
|
+
updateRecorder.remove(
|
|
276
|
+
importNode.pos,
|
|
277
|
+
importNode.getChildren()[importNode.getChildren().length - 1].end - importNode.pos
|
|
278
|
+
);
|
|
279
|
+
tree.commitUpdate(updateRecorder);
|
|
280
|
+
if (logMessage) {
|
|
281
|
+
logInfo(`Import ${importName} entfernt.`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
for (let i = 0; i < importChildren.length; i++) {
|
|
286
|
+
if (importChildren[i].getText() === importName) {
|
|
287
|
+
const prevSibling = getPrevSibling(importChildren[i], ts.SyntaxKind.SyntaxList);
|
|
288
|
+
const nextSibling = getNextSibling(importChildren[i], ts.SyntaxKind.SyntaxList);
|
|
289
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
290
|
+
if (nextSibling) {
|
|
291
|
+
updateRecorder.remove(importChildren[i].pos, nextSibling.end - importChildren[i].pos);
|
|
292
|
+
} else {
|
|
293
|
+
if (prevSibling) {
|
|
294
|
+
updateRecorder.remove(prevSibling.pos, importChildren[i].end - prevSibling.pos);
|
|
295
|
+
} else {
|
|
296
|
+
updateRecorder.remove(importChildren[i].pos, importChildren[i].end - importChildren[i].pos);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
tree.commitUpdate(updateRecorder);
|
|
300
|
+
if (logMessage) {
|
|
301
|
+
logInfo(`Import ${importName} entfernt.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
309
|
+
updateRecorder.remove(importNode.pos, importNode.end - importNode.pos);
|
|
310
|
+
tree.commitUpdate(updateRecorder);
|
|
311
|
+
if (logMessage) {
|
|
312
|
+
logInfo(`Import ${importName} entfernt.`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function removeProvider(tree: Tree, filePath: string, providerName: string, logMessage = true) {
|
|
321
|
+
const content = (tree.read(filePath) as Buffer).toString();
|
|
322
|
+
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
|
|
323
|
+
const sourceFile = ts.createSourceFile(`${fileName}`, content, ts.ScriptTarget.Latest, true);
|
|
324
|
+
const nodes = getSourceNodes(sourceFile);
|
|
325
|
+
|
|
326
|
+
const providerIdentifierNode = nodes.find((n) => n.kind === ts.SyntaxKind.Identifier && n.getText() === 'providers');
|
|
327
|
+
|
|
328
|
+
if (providerIdentifierNode) {
|
|
329
|
+
const siblings = providerIdentifierNode.parent.getChildren();
|
|
330
|
+
|
|
331
|
+
if (siblings) {
|
|
332
|
+
const providerArrayNode = siblings.find((n) => n.kind === ts.SyntaxKind.ArrayLiteralExpression);
|
|
333
|
+
|
|
334
|
+
if (providerArrayNode) {
|
|
335
|
+
const providerNode = providerArrayNode.getChildren().find((n) => n.kind === ts.SyntaxKind.SyntaxList);
|
|
336
|
+
if (providerNode) {
|
|
337
|
+
const providerChildren = providerNode.getChildren();
|
|
338
|
+
|
|
339
|
+
if (providerChildren) {
|
|
340
|
+
for (let i = 0; i < providerChildren.length; i++) {
|
|
341
|
+
if (providerChildren[i].getText().indexOf(providerName) >= 0) {
|
|
342
|
+
const prevSibling = getPrevSibling(providerChildren[i], ts.SyntaxKind.SyntaxList);
|
|
343
|
+
const nextSibling = getNextSibling(providerChildren[i], ts.SyntaxKind.SyntaxList);
|
|
344
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
345
|
+
if (nextSibling) {
|
|
346
|
+
updateRecorder.remove(providerChildren[i].pos, nextSibling.end - providerChildren[i].pos);
|
|
347
|
+
} else {
|
|
348
|
+
if (prevSibling) {
|
|
349
|
+
updateRecorder.remove(prevSibling.pos, providerChildren[i].end - prevSibling.pos);
|
|
350
|
+
} else {
|
|
351
|
+
updateRecorder.remove(providerChildren[i].pos, providerChildren[i].end - providerChildren[i].pos);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
tree.commitUpdate(updateRecorder);
|
|
355
|
+
if (logMessage) {
|
|
356
|
+
logInfo(`Provider ${providerName} entfernt.`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export function getSiblings(node: ts.Node, childKind?: ts.SyntaxKind): ts.Node[] {
|
|
368
|
+
let result: ts.Node[] = [];
|
|
369
|
+
|
|
370
|
+
if (node && node.parent.getChildren()) {
|
|
371
|
+
if (childKind) {
|
|
372
|
+
const childNode = node.parent.getChildren().find((child) => child.kind === childKind);
|
|
373
|
+
|
|
374
|
+
if (!childNode) {
|
|
375
|
+
throw new SchematicsException(`Es konnte kein Knoten vom Typ ${childKind} gefunden werden.`);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
result = childNode.getChildren();
|
|
379
|
+
} else {
|
|
380
|
+
result = node.parent.getChildren();
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return result;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export function getPrevSibling(node: ts.Node, childKind?: ts.SyntaxKind): ts.Node | null {
|
|
388
|
+
let result: ts.Node | null = null;
|
|
389
|
+
|
|
390
|
+
if (node) {
|
|
391
|
+
let siblings: ts.Node[] = getSiblings(node, childKind);
|
|
392
|
+
|
|
393
|
+
if (siblings) {
|
|
394
|
+
const index = siblings.indexOf(node);
|
|
395
|
+
if (index > 0) {
|
|
396
|
+
result = siblings[index - 1];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function getNextSibling(node: ts.Node, childKind?: ts.SyntaxKind): ts.Node | null {
|
|
405
|
+
let result: ts.Node | null = null;
|
|
406
|
+
|
|
407
|
+
if (node) {
|
|
408
|
+
let siblings: ts.Node[] = getSiblings(node, childKind);
|
|
409
|
+
|
|
410
|
+
if (siblings) {
|
|
411
|
+
const index = siblings.indexOf(node);
|
|
412
|
+
if (index >= 0 && index < siblings.length - 1) {
|
|
413
|
+
result = siblings[index + 1];
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return result;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function getNextSiblings(node: ts.Node): ts.Node[] {
|
|
422
|
+
let result: ts.Node[] = [];
|
|
423
|
+
|
|
424
|
+
if (node) {
|
|
425
|
+
let siblings: ts.Node[] = getSiblings(node);
|
|
426
|
+
|
|
427
|
+
if (siblings) {
|
|
428
|
+
const index = siblings.indexOf(node);
|
|
429
|
+
if (index >= 0 && index < siblings.length - 1) {
|
|
430
|
+
result = siblings.slice(index + 1, siblings.length - 1);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export function showTree(node: ts.Node, indent: string = ' '): void {
|
|
439
|
+
console.log(indent + ts.SyntaxKind[node.kind]);
|
|
440
|
+
|
|
441
|
+
if (node.getChildCount() === 0) {
|
|
442
|
+
console.log(indent + ' Text: ' + node.getText());
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
for (let child of node.getChildren()) {
|
|
446
|
+
showTree(child, indent + ' ');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function findChild(node: ts.Node, kind: ts.SyntaxKind, text?: string, depth: number = 100): ts.Node | undefined {
|
|
451
|
+
if (node.kind === kind && (!text || node.getText() === text)) {
|
|
452
|
+
return node;
|
|
453
|
+
} else {
|
|
454
|
+
for (let child of node.getChildren()) {
|
|
455
|
+
const found = findChild(child, kind, text);
|
|
456
|
+
|
|
457
|
+
if (found) {
|
|
458
|
+
return found;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return undefined;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export function getSyntaxListOfClass(tree: Tree, filePath: string): ts.Node {
|
|
467
|
+
const content = (tree.read(filePath) as Buffer).toString();
|
|
468
|
+
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
|
|
469
|
+
const sourceFile = ts.createSourceFile(`${ fileName }`, content, ts.ScriptTarget.Latest, true);
|
|
470
|
+
const nodes = getSourceNodes(sourceFile);
|
|
471
|
+
|
|
472
|
+
const classNode = nodes.find((n) => n.kind === ts.SyntaxKind.ClassKeyword);
|
|
473
|
+
if (!classNode) {
|
|
474
|
+
throw new SchematicsException(`Die Klasse in der Datei ${ fileName } hat kein ClassKeyword.`);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const firstPunctuationNode = getNextSiblings(classNode).find(n => n.kind === ts.SyntaxKind.FirstPunctuation);
|
|
478
|
+
|
|
479
|
+
if (!firstPunctuationNode) {
|
|
480
|
+
throw new SchematicsException(`Die Klasse in der Datei ${ fileName } hat keine FirstPunctuation.`);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const syntaxListNode = getNextSibling(firstPunctuationNode);
|
|
484
|
+
|
|
485
|
+
if (!syntaxListNode) {
|
|
486
|
+
throw new SchematicsException(`Die Klasse in der Datei ${ fileName } hat keine SyntaxList.`);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return syntaxListNode;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export function getConstructor(tree: Tree, filePath: string) {
|
|
493
|
+
return findChild(getSyntaxListOfClass(tree, filePath), ts.SyntaxKind.Constructor);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export function getMethod(tree: Tree, filePath: string, methodeName): ts.Node | undefined {
|
|
497
|
+
return findChild(getSyntaxListOfClass(tree, filePath), ts.SyntaxKind.MethodDeclaration, methodeName);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export function addParameter(tree: Tree, filePath: string, syntaxListNode: ts.Node, service: string) {
|
|
501
|
+
const parameterNodes = syntaxListNode.getChildren();
|
|
502
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
503
|
+
if (parameterNodes.length == 0) {
|
|
504
|
+
// Constructor ohne Parameter
|
|
505
|
+
updateRecorder.insertLeft(syntaxListNode.pos, service);
|
|
506
|
+
} else if (parameterNodes.length > 0) {
|
|
507
|
+
// Constructor mit Parameter
|
|
508
|
+
updateRecorder.insertLeft(parameterNodes[ parameterNodes.length - 1 ].end, ', ' + service);
|
|
509
|
+
}
|
|
510
|
+
tree.commitUpdate(updateRecorder);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export function addMethod(tree: Tree, filePath: string, syntaxListNode: ts.Node, method: string) {
|
|
514
|
+
const syntaxList = getSyntaxListOfClass(tree, filePath);
|
|
515
|
+
const methodNodes = syntaxList.getChildren().filter(n => n.kind === ts.SyntaxKind.MethodDeclaration);
|
|
516
|
+
|
|
517
|
+
let startNode = syntaxList;
|
|
518
|
+
if (methodNodes && methodNodes.length > 0 ) {
|
|
519
|
+
startNode = methodNodes[methodNodes.length - 1];
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
523
|
+
updateRecorder.insertLeft(startNode.end, '\n' + method);
|
|
524
|
+
tree.commitUpdate(updateRecorder);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export function addConstructorParameter(tree: Tree, filePath: string, service: string) {
|
|
528
|
+
const constructorNode = getConstructor(tree, filePath);
|
|
529
|
+
if (constructorNode) {
|
|
530
|
+
addParameter(tree, filePath, findChild(constructorNode, ts.SyntaxKind.SyntaxList) as ts.Node, service);
|
|
531
|
+
logInfo(`Im Konstruktor den Parameter "${ service }" hinzugefügt.`);
|
|
532
|
+
} else {
|
|
533
|
+
const syntaxListNode = getSyntaxListOfClass(tree, filePath);
|
|
534
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
535
|
+
updateRecorder.insertLeft(syntaxListNode.pos, `\n constructor(${ service }) {}`);
|
|
536
|
+
tree.commitUpdate(updateRecorder);
|
|
537
|
+
logInfo(`constructor(${ service }) {} hinzugefügt.`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export function addClassProperty(tree: Tree, filePath: string, property: string) {
|
|
542
|
+
const syntaxListNode = getSyntaxListOfClass(tree, filePath);
|
|
543
|
+
|
|
544
|
+
if (!syntaxListNode) {
|
|
545
|
+
throw new SchematicsException(`Die Klasse in der Datei ${filePath} hat keine Syntaxlist.`);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const startNode =
|
|
549
|
+
syntaxListNode.getChildren() && syntaxListNode.getChildren().length > 0
|
|
550
|
+
? syntaxListNode.getChildren()[0]
|
|
551
|
+
: syntaxListNode;
|
|
552
|
+
|
|
553
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
554
|
+
updateRecorder.insertLeft(startNode.pos, '\n\n ' + property + '\n');
|
|
555
|
+
tree.commitUpdate(updateRecorder);
|
|
556
|
+
logInfo(`Die Property "${property}" wurde hinzugefügt.`);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export function addConstructorContent(tree: Tree, filePath: string, content: string, append: boolean) {
|
|
560
|
+
const constructorNode = getConstructor(tree, filePath);
|
|
561
|
+
|
|
562
|
+
if (constructorNode) {
|
|
563
|
+
const blockNode = constructorNode.getChildren().find(n => n.kind === ts.SyntaxKind.Block);
|
|
564
|
+
|
|
565
|
+
if (!blockNode) {
|
|
566
|
+
throw new SchematicsException(`Der Konstruktor in der Klasse ${ filePath } hat keinen Block.`);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const firstPunctuationNode = blockNode.getChildren().find(n => n.kind === ts.SyntaxKind.FirstPunctuation);
|
|
570
|
+
|
|
571
|
+
if (!firstPunctuationNode) {
|
|
572
|
+
throw new SchematicsException(`Der Konstruktor in der Klasse ${ filePath } hat keine FirstPunctuation.`);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const syntaxListNode = getNextSibling(firstPunctuationNode);
|
|
576
|
+
|
|
577
|
+
if (syntaxListNode && syntaxListNode.getChildren().length > 0) {
|
|
578
|
+
const start = append ? syntaxListNode.getChildren()[syntaxListNode.getChildren().length - 1].end : syntaxListNode.getChildren()[0].pos;
|
|
579
|
+
|
|
580
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
581
|
+
updateRecorder.insertLeft(start, '\n ' + content);
|
|
582
|
+
tree.commitUpdate(updateRecorder);
|
|
583
|
+
} else {
|
|
584
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
585
|
+
updateRecorder.insertLeft(firstPunctuationNode.end, '\n ' + content + '\n ');
|
|
586
|
+
tree.commitUpdate(updateRecorder);
|
|
587
|
+
}
|
|
588
|
+
logInfo(`Inhalt ${append ? 'am Ende' : 'am Anfang'} des Konstruktors hinzugefügt.`);
|
|
589
|
+
} else {
|
|
590
|
+
const syntaxListNode = getSyntaxListOfClass(tree, filePath);
|
|
591
|
+
const updateRecorder = tree.beginUpdate(filePath);
|
|
592
|
+
updateRecorder.insertLeft(syntaxListNode.pos, '\n\n' + ' constructor() {\n' + ' router.initialNavigation();\n' + ' }');
|
|
593
|
+
tree.commitUpdate(updateRecorder);
|
|
594
|
+
logInfo(`Konstruktor mit Inhalt hinzugefügt.`);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|