@ihk-gfi/lux-components-update 14.8.0 → 15.0.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/README.md +4 -2
- package/add-lux-components/files/app/app.component.html +34 -0
- package/{src/add-lux-components → add-lux-components}/files/app/app.component.spec.ts +4 -2
- package/{src/add-lux-components → add-lux-components}/files/app/app.component.ts +1 -1
- package/add-lux-components/files/src/main.ts +17 -0
- package/{src/add-lux-components → add-lux-components}/index.js +29 -30
- package/add-lux-components/schema.json +23 -0
- package/collection.json +35 -0
- package/package.json +27 -27
- package/{src/theme → theme}/change-theme-to-authentic/index.js +0 -1
- package/theme/change-theme-to-authentic/schema.json +23 -0
- package/{src/theme → theme}/change-to-lux-icons/index.js +0 -1
- package/theme/change-to-lux-icons/schema.json +23 -0
- package/{src/update-dependencies → update-dependencies}/index.d.ts +1 -0
- package/update-dependencies/index.js +92 -0
- package/update-dependencies/schema.json +23 -0
- package/{src/update-en-messages → update-en-messages}/index.js +0 -1
- package/update-en-messages/schema.json +23 -0
- package/updates/15.0.0/index.d.ts +8 -0
- package/updates/15.0.0/index.js +109 -0
- package/updates/15.0.0/schema.json +23 -0
- package/{src/utility → utility}/dependencies.js +0 -1
- package/{src/utility → utility}/files.js +0 -1
- package/{src/utility → utility}/html/hit.js +0 -1
- package/{src/utility → utility}/html/html-manipulator.js +0 -1
- package/{src/utility → utility}/html/manipulator-functions.js +0 -1
- package/{src/utility → utility}/json.d.ts +2 -0
- package/{src/utility → utility}/json.js +16 -8
- package/{src/utility → utility}/logging.js +0 -1
- package/{src/utility → utility}/test.js +0 -1
- package/{src/utility → utility}/typescript.js +0 -1
- package/{src/utility → utility}/util.js +0 -1
- package/{src/utility → utility}/validation.js +0 -1
- package/src/add-lux-components/files/app/app.component.html +0 -32
- package/src/add-lux-components/files/app/base/license-hint/license-hint.component.html +0 -7
- package/src/add-lux-components/files/app/base/license-hint/license-hint.component.ts +0 -18
- package/src/add-lux-components/files/app/error/error.component.html +0 -10
- package/src/add-lux-components/files/app/error/error.component.scss +0 -3
- package/src/add-lux-components/files/app/error/error.component.spec.ts +0 -49
- package/src/add-lux-components/files/app/error/error.component.ts +0 -17
- package/src/add-lux-components/files/app/home/home.component.html +0 -7
- package/src/add-lux-components/files/app/home/home.component.scss +0 -3
- package/src/add-lux-components/files/app/home/home.component.ts +0 -13
- package/src/add-lux-components/files/app/profil/profil.component.html +0 -1
- 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 +0 -24
- package/src/add-lux-components/files/app/profil/profil.component.ts +0 -11
- package/src/add-lux-components/files/assets/svg/Example.svg +0 -6
- package/src/add-lux-components/files/assets/svg/android.svg +0 -2
- package/src/add-lux-components/files/assets/svg/box.svg +0 -690
- package/src/add-lux-components/files/assets/svg/demoAppLogo.svg +0 -1
- package/src/add-lux-components/files/assets/svg/red_power_button.svg +0 -67
- package/src/add-lux-components/files/assets/svg/svg2009.svg +0 -57457
- package/src/add-lux-components/files/src/polyfills.ts +0 -58
- package/src/add-lux-components/index.js.map +0 -1
- package/src/add-lux-components/index.ts +0 -293
- package/src/add-lux-components/index_spec.d.ts +0 -1
- package/src/add-lux-components/index_spec.js +0 -51
- package/src/add-lux-components/index_spec.js.map +0 -1
- package/src/add-lux-components/index_spec.ts +0 -55
- package/src/add-lux-components/schema.json +0 -23
- package/src/collection.json +0 -75
- package/src/theme/change-theme-to-authentic/index.js.map +0 -1
- package/src/theme/change-theme-to-authentic/index.ts +0 -131
- package/src/theme/change-theme-to-authentic/index_spec.d.ts +0 -1
- package/src/theme/change-theme-to-authentic/index_spec.js +0 -300
- package/src/theme/change-theme-to-authentic/index_spec.js.map +0 -1
- package/src/theme/change-theme-to-authentic/index_spec.ts +0 -321
- package/src/theme/change-theme-to-authentic/schema.json +0 -23
- package/src/theme/change-to-lux-icons/index.js.map +0 -1
- package/src/theme/change-to-lux-icons/index.ts +0 -392
- package/src/theme/change-to-lux-icons/index_spec.d.ts +0 -1
- package/src/theme/change-to-lux-icons/index_spec.js +0 -128
- package/src/theme/change-to-lux-icons/index_spec.js.map +0 -1
- package/src/theme/change-to-lux-icons/index_spec.ts +0 -130
- package/src/theme/change-to-lux-icons/schema.json +0 -23
- package/src/update-dependencies/index.js +0 -88
- package/src/update-dependencies/index.js.map +0 -1
- package/src/update-dependencies/index.ts +0 -86
- package/src/update-dependencies/schema.json +0 -23
- package/src/update-en-messages/index.js.map +0 -1
- package/src/update-en-messages/index.ts +0 -83
- package/src/update-en-messages/index_spec.d.ts +0 -1
- package/src/update-en-messages/index_spec.js +0 -174
- package/src/update-en-messages/index_spec.js.map +0 -1
- package/src/update-en-messages/index_spec.ts +0 -182
- package/src/update-en-messages/schema.json +0 -23
- package/src/updates/update140000/files/src/polyfills.ts +0 -70
- package/src/updates/update140000/index.d.ts +0 -14
- package/src/updates/update140000/index.js +0 -95
- package/src/updates/update140000/index.js.map +0 -1
- package/src/updates/update140000/index.ts +0 -110
- package/src/updates/update140000/index_spec.d.ts +0 -1
- package/src/updates/update140000/index_spec.js +0 -165
- package/src/updates/update140000/index_spec.js.map +0 -1
- package/src/updates/update140000/index_spec.ts +0 -171
- package/src/updates/update140000/schema.json +0 -23
- package/src/updates/update140100/index.d.ts +0 -5
- package/src/updates/update140100/index.js +0 -62
- package/src/updates/update140100/index.js.map +0 -1
- package/src/updates/update140100/index.ts +0 -60
- package/src/updates/update140100/index_spec.d.ts +0 -1
- package/src/updates/update140100/index_spec.js +0 -124
- package/src/updates/update140100/index_spec.js.map +0 -1
- package/src/updates/update140100/index_spec.ts +0 -137
- package/src/updates/update140100/schema.json +0 -23
- package/src/updates/update140200/index.d.ts +0 -8
- package/src/updates/update140200/index.js +0 -40
- package/src/updates/update140200/index.js.map +0 -1
- package/src/updates/update140200/index.ts +0 -38
- package/src/updates/update140200/index_spec.d.ts +0 -1
- package/src/updates/update140200/index_spec.js +0 -75
- package/src/updates/update140200/index_spec.js.map +0 -1
- package/src/updates/update140200/index_spec.ts +0 -81
- package/src/updates/update140200/schema.json +0 -23
- package/src/updates/update140300/index.d.ts +0 -10
- package/src/updates/update140300/index.js +0 -85
- package/src/updates/update140300/index.js.map +0 -1
- package/src/updates/update140300/index.ts +0 -86
- package/src/updates/update140300/index_spec.d.ts +0 -1
- package/src/updates/update140300/index_spec.js +0 -145
- package/src/updates/update140300/index_spec.js.map +0 -1
- package/src/updates/update140300/index_spec.ts +0 -177
- package/src/updates/update140300/schema.json +0 -23
- package/src/updates/update140400/index.d.ts +0 -2
- package/src/updates/update140400/index.js +0 -22
- package/src/updates/update140400/index.js.map +0 -1
- package/src/updates/update140400/index.ts +0 -18
- package/src/updates/update140400/index_spec.d.ts +0 -1
- package/src/updates/update140400/index_spec.js +0 -75
- package/src/updates/update140400/index_spec.js.map +0 -1
- package/src/updates/update140400/index_spec.ts +0 -81
- package/src/updates/update140400/schema.json +0 -23
- package/src/updates/update140500/index.d.ts +0 -2
- package/src/updates/update140500/index.js +0 -21
- package/src/updates/update140500/index.js.map +0 -1
- package/src/updates/update140500/index.ts +0 -17
- package/src/updates/update140500/index_spec.d.ts +0 -1
- package/src/updates/update140500/index_spec.js +0 -73
- package/src/updates/update140500/index_spec.js.map +0 -1
- package/src/updates/update140500/index_spec.ts +0 -78
- package/src/updates/update140500/schema.json +0 -23
- package/src/updates/update140600/index.d.ts +0 -2
- package/src/updates/update140600/index.js +0 -39
- package/src/updates/update140600/index.js.map +0 -1
- package/src/updates/update140600/index.ts +0 -35
- package/src/updates/update140600/index_spec.d.ts +0 -1
- package/src/updates/update140600/index_spec.js +0 -71
- package/src/updates/update140600/index_spec.js.map +0 -1
- package/src/updates/update140600/index_spec.ts +0 -75
- package/src/updates/update140600/schema.json +0 -23
- package/src/updates/update140700/index.d.ts +0 -2
- package/src/updates/update140700/index.js +0 -22
- package/src/updates/update140700/index.js.map +0 -1
- package/src/updates/update140700/index.ts +0 -18
- package/src/updates/update140700/index_spec.d.ts +0 -1
- package/src/updates/update140700/index_spec.js +0 -75
- package/src/updates/update140700/index_spec.js.map +0 -1
- package/src/updates/update140700/index_spec.ts +0 -79
- package/src/updates/update140700/schema.json +0 -23
- package/src/updates/update140800/index.d.ts +0 -2
- package/src/updates/update140800/index.js +0 -22
- package/src/updates/update140800/index.js.map +0 -1
- package/src/updates/update140800/index.ts +0 -18
- package/src/updates/update140800/index_spec.d.ts +0 -1
- package/src/updates/update140800/index_spec.js +0 -76
- package/src/updates/update140800/index_spec.js.map +0 -1
- package/src/updates/update140800/index_spec.ts +0 -82
- package/src/updates/update140800/schema.json +0 -23
- package/src/utility/dependencies.js.map +0 -1
- package/src/utility/dependencies.ts +0 -144
- package/src/utility/files.js.map +0 -1
- package/src/utility/files.ts +0 -368
- package/src/utility/html/hit.js.map +0 -1
- package/src/utility/html/hit.ts +0 -28
- package/src/utility/html/html-manipulator.js.map +0 -1
- package/src/utility/html/html-manipulator.ts +0 -156
- package/src/utility/html/html_spec.d.ts +0 -1
- package/src/utility/html/html_spec.js +0 -692
- package/src/utility/html/html_spec.js.map +0 -1
- package/src/utility/html/html_spec.ts +0 -751
- package/src/utility/html/manipulator-functions.js.map +0 -1
- package/src/utility/html/manipulator-functions.ts +0 -149
- package/src/utility/json.js.map +0 -1
- package/src/utility/json.ts +0 -288
- package/src/utility/json_spec.d.ts +0 -1
- package/src/utility/json_spec.js +0 -326
- package/src/utility/json_spec.js.map +0 -1
- package/src/utility/json_spec.ts +0 -446
- package/src/utility/logging.js.map +0 -1
- package/src/utility/logging.ts +0 -80
- package/src/utility/test.js.map +0 -1
- package/src/utility/test.ts +0 -24
- package/src/utility/typescript.js.map +0 -1
- package/src/utility/typescript.ts +0 -598
- package/src/utility/typescript_spec.d.ts +0 -1
- package/src/utility/typescript_spec.js +0 -1005
- package/src/utility/typescript_spec.js.map +0 -1
- package/src/utility/typescript_spec.ts +0 -1265
- package/src/utility/util.js.map +0 -1
- package/src/utility/util.ts +0 -145
- package/src/utility/validation.js.map +0 -1
- package/src/utility/validation.ts +0 -48
- package/tsconfig.json +0 -35
- /package/{src/add-lux-components → add-lux-components}/files/app/app-routing.module.ts +0 -0
- /package/{src/add-lux-components → add-lux-components}/files/app/app.module.ts +0 -0
- /package/{src/add-lux-components → add-lux-components}/files/environments/environment.prod.ts +0 -0
- /package/{src/add-lux-components → add-lux-components}/files/environments/environment.ts +0 -0
- /package/{src/add-lux-components → add-lux-components}/files/locale/messages.en.xlf +0 -0
- /package/{src/add-lux-components → add-lux-components}/files/locale/messages.xlf +0 -0
- /package/{src/add-lux-components → add-lux-components}/files/src/index.html +0 -0
- /package/{src/add-lux-components → add-lux-components}/index.d.ts +0 -0
- /package/{src/theme → theme}/change-theme-to-authentic/index.d.ts +0 -0
- /package/{src/theme → theme}/change-to-lux-icons/index.d.ts +0 -0
- /package/{src/update-en-messages → update-en-messages}/index.d.ts +0 -0
- /package/{src/utility → utility}/dependencies.d.ts +0 -0
- /package/{src/utility → utility}/files.d.ts +0 -0
- /package/{src/utility → utility}/html/hit.d.ts +0 -0
- /package/{src/utility → utility}/html/html-manipulator.d.ts +0 -0
- /package/{src/utility → utility}/html/manipulator-functions.d.ts +0 -0
- /package/{src/utility → utility}/logging.d.ts +0 -0
- /package/{src/utility → utility}/test.d.ts +0 -0
- /package/{src/utility → utility}/typescript.d.ts +0 -0
- /package/{src/utility → utility}/util.d.ts +0 -0
- /package/{src/utility → utility}/validation.d.ts +0 -0
package/src/utility/files.ts
DELETED
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import { join, Path, strings } from '@angular-devkit/core';
|
|
2
|
-
import {
|
|
3
|
-
apply,
|
|
4
|
-
DirEntry,
|
|
5
|
-
forEach,
|
|
6
|
-
MergeStrategy,
|
|
7
|
-
mergeWith,
|
|
8
|
-
Rule,
|
|
9
|
-
SchematicContext,
|
|
10
|
-
template,
|
|
11
|
-
Tree,
|
|
12
|
-
url
|
|
13
|
-
} from '@angular-devkit/schematics';
|
|
14
|
-
import { logInfo, logInfoWithDescriptor, logSuccess } from './logging';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Entfernt eine Zeile aus der Datei, die den searchString beinhaltet.
|
|
18
|
-
* Gibt eine Log-Ausgabe aus, wenn die Datei nicht gefunden werden konnte.
|
|
19
|
-
* @param tree
|
|
20
|
-
* @param context
|
|
21
|
-
* @param filePath
|
|
22
|
-
* @param searchString
|
|
23
|
-
*/
|
|
24
|
-
export function deleteLineFromFile(tree: Tree, _context: SchematicContext, filePath: string, searchString: string, withLog = true) {
|
|
25
|
-
let changed = false;
|
|
26
|
-
|
|
27
|
-
const fileContent: Buffer | null = tree.read(filePath);
|
|
28
|
-
if (fileContent) {
|
|
29
|
-
// String der Datei erhalten
|
|
30
|
-
let content: string = fileContent.toString();
|
|
31
|
-
|
|
32
|
-
if (content.indexOf(searchString) !== -1) {
|
|
33
|
-
// Standard-Separator
|
|
34
|
-
let separator = '\r\n';
|
|
35
|
-
|
|
36
|
-
// Wenn nicht gefunden, nur \n als Separator nutzen
|
|
37
|
-
if (content.indexOf(separator) === -1) {
|
|
38
|
-
separator = '\n';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Alle Zeilen der Datei erhalten
|
|
42
|
-
const lines: string[] = content.split(separator);
|
|
43
|
-
|
|
44
|
-
// Lines iterieren und nach der dependency suchen
|
|
45
|
-
for (let i = 0; i < lines.length; i++) {
|
|
46
|
-
// Wenn gefunden, die Zeile entfernen
|
|
47
|
-
if (lines[i].indexOf(searchString) > -1) {
|
|
48
|
-
content = content.replace(lines[i], '');
|
|
49
|
-
|
|
50
|
-
// Sonderbehandlung für die .json-Dateien
|
|
51
|
-
// Wenn man aus einem Block die letzte Zeile entfernt,
|
|
52
|
-
// muss in der Zeile davor das Komma entfernt werden.
|
|
53
|
-
// Beispiel:
|
|
54
|
-
// "dependencies": {
|
|
55
|
-
// "@angular/common": "9.1.0",
|
|
56
|
-
// "lux-components": "1.8.3"
|
|
57
|
-
// },
|
|
58
|
-
// Entfernt man die Zeile "lux-components...",
|
|
59
|
-
// muss das Komma aus der Zeile "@angular/common..." ebenfalls
|
|
60
|
-
// entfernt werden, sonst ist dsa Json ungültig.
|
|
61
|
-
if (filePath.endsWith('.json') && i + 1 < lines.length) {
|
|
62
|
-
if (i > 0 && (lines[i + 1].trim() === '}' || lines[i + 1].trim() === '},')) {
|
|
63
|
-
content = content.replace(lines[i - 1], lines[i - 1].substring(0, lines[i - 1].lastIndexOf(',')));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Doppelte Zeilenumbrüche entfernen
|
|
69
|
-
content = content.replace(new RegExp('\r\n', 'g'), '\r\n');
|
|
70
|
-
content = content.replace(new RegExp('\r\n\r\n', 'g'), '\r\n');
|
|
71
|
-
|
|
72
|
-
tree.overwrite(filePath, content);
|
|
73
|
-
changed = true;
|
|
74
|
-
} else {
|
|
75
|
-
if (withLog) {
|
|
76
|
-
logInfo(`Die Datei "${ filePath }" enthält den String "${ searchString }" nicht.`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
if (withLog) {
|
|
81
|
-
logInfo(`Die Datei "${ filePath }" wurde nicht gefunden.`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return changed;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Schreibt die übergebenen Zeilen in die Datei.
|
|
90
|
-
* Wenn die Datei existiert, wird der neue Inhalt am Ende der Datei angehangen.
|
|
91
|
-
* Wenn die Datei nicht exitiert, wird diese mit dem Inhalt erstellt.
|
|
92
|
-
* @param tree
|
|
93
|
-
* @param context
|
|
94
|
-
* @param filePath
|
|
95
|
-
* @param lines
|
|
96
|
-
*/
|
|
97
|
-
export function writeLinesToFile(tree: Tree, _context: SchematicContext, filePath: string, ...lines: string[]) {
|
|
98
|
-
const fileContent: Buffer | null = tree.read(filePath);
|
|
99
|
-
let content: string = '';
|
|
100
|
-
|
|
101
|
-
lines.forEach((line: string) => {
|
|
102
|
-
if (fileContent && fileContent.toString().indexOf(line) === -1) {
|
|
103
|
-
content += line + '\r\n';
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (fileContent !== null) {
|
|
108
|
-
tree.overwrite(filePath, fileContent.toString() + '\r\n' + content);
|
|
109
|
-
logInfo(`Überschreibe die Datei "${filePath}".`);
|
|
110
|
-
} else {
|
|
111
|
-
tree.create(filePath, content);
|
|
112
|
-
logInfo(`Erstelle die Datei "${filePath}" und füge Inhalt hinzu.`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Iteriert über alle Dateien vom Root-Pfad aus.
|
|
118
|
-
* Über die filePathEndings lassen sich Einschränkungen bzgl. des Datei-Typs festlegen (z.B. .html).
|
|
119
|
-
* Wenn eine Datei die passende Endung und Inhalt hat, wird der Callback mit Pfad und Content aufgerufen.
|
|
120
|
-
* @param tree
|
|
121
|
-
* @param rootPath
|
|
122
|
-
* @param callback(filePath, content)
|
|
123
|
-
* @param filePathEndings Z.B. .html, .ts, src/styles.scss,...
|
|
124
|
-
*/
|
|
125
|
-
export function iterateFilesAndModifyContent(
|
|
126
|
-
tree: Tree,
|
|
127
|
-
rootPath: string = '',
|
|
128
|
-
callback: Function,
|
|
129
|
-
...filePathEndings: string[]
|
|
130
|
-
) {
|
|
131
|
-
tree.getDir(rootPath).visit((filePath: string) => {
|
|
132
|
-
// Ignoriere folende Odner
|
|
133
|
-
if (
|
|
134
|
-
filePath.startsWith('/node_modules/') ||
|
|
135
|
-
filePath.startsWith('/.idea/') ||
|
|
136
|
-
filePath.startsWith('/coverage/') ||
|
|
137
|
-
filePath.startsWith('/dist/')
|
|
138
|
-
) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Endung der Datei mit erlaubten Endungen abgleichen
|
|
143
|
-
let modifyFile: boolean = false;
|
|
144
|
-
for (let fileEnding of filePathEndings) {
|
|
145
|
-
if (filePath.endsWith(fileEnding)) {
|
|
146
|
-
modifyFile = true;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// Besitzt die Datei die richtige Endung?
|
|
151
|
-
if (!modifyFile) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
// Inhalt auslesen
|
|
155
|
-
const content = tree.read(filePath);
|
|
156
|
-
// Wenn die Datei keinen Inhalt hat, die nächste Datei aufrufen
|
|
157
|
-
if (!content) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Callback mit aktuellem Pfad + Inhalt der Datei aufrufen
|
|
162
|
-
callback(filePath, content.toString());
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Diese Methode ersetzt die angegebene Dateien. Sollten diese nicht existieren, werden sie neu angelegt.
|
|
168
|
-
*
|
|
169
|
-
* Beispiele:
|
|
170
|
-
* moveFilesToDirectory(options, 'files/locale', 'src/locale')
|
|
171
|
-
* moveFilesToDirectory(options, 'files/root', '/')
|
|
172
|
-
*
|
|
173
|
-
* @param options Die Optionen.
|
|
174
|
-
* @param sourcePath Ein Quellpfad (z.B. files/theming für alle Dateien unter /theming).
|
|
175
|
-
* @param targetPath Ein Zielpfad (z.B. src/theming/).
|
|
176
|
-
*/
|
|
177
|
-
export function moveFilesToDirectory(options: any, sourcePath: string, targetPath: string): Rule {
|
|
178
|
-
return (tree: Tree, _context: SchematicContext) => {
|
|
179
|
-
if (!targetPath.startsWith('/')) {
|
|
180
|
-
targetPath = '/' + targetPath;
|
|
181
|
-
}
|
|
182
|
-
if (!sourcePath.startsWith('/')) {
|
|
183
|
-
sourcePath = '/' + sourcePath;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
targetPath = (options.path ? options.path : '') + targetPath;
|
|
187
|
-
|
|
188
|
-
const templateSource = apply(url('.' + sourcePath), [
|
|
189
|
-
template({
|
|
190
|
-
...strings,
|
|
191
|
-
...options
|
|
192
|
-
}),
|
|
193
|
-
forEach((file) => {
|
|
194
|
-
let newTargetPath = targetPath + file.path;
|
|
195
|
-
newTargetPath = newTargetPath.replace('//', '/');
|
|
196
|
-
|
|
197
|
-
if (tree.exists(newTargetPath)) {
|
|
198
|
-
tree.overwrite(newTargetPath, file.content);
|
|
199
|
-
logInfo(`Datei '${newTargetPath}' aktualisiert.`);
|
|
200
|
-
} else {
|
|
201
|
-
tree.create(newTargetPath, file.content);
|
|
202
|
-
logInfo(`Datei '${newTargetPath}' angelegt.`);
|
|
203
|
-
}
|
|
204
|
-
return null;
|
|
205
|
-
})
|
|
206
|
-
]);
|
|
207
|
-
|
|
208
|
-
return mergeWith(templateSource, MergeStrategy.Overwrite);
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Diese Methode löscht die Dateien in dem angegebenen Ordner.
|
|
214
|
-
*
|
|
215
|
-
* @param options Die Optionen.
|
|
216
|
-
* @param path Der Pfad.
|
|
217
|
-
* @param exclude Ein Array mit Dateinamen, die nicht gelöscht werden sollen.
|
|
218
|
-
*/
|
|
219
|
-
export function deleteFilesInDirectory(options: any, path: string, exclude: string[]): Rule {
|
|
220
|
-
return (tree: Tree, _context: SchematicContext) => {
|
|
221
|
-
if (!path.startsWith('/')) {
|
|
222
|
-
path = '/' + path;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!path.endsWith('/')) {
|
|
226
|
-
path = path + '/';
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
path = (options.path ? options.path : '') + path;
|
|
230
|
-
|
|
231
|
-
const dir = tree.getDir(path);
|
|
232
|
-
if (dir) {
|
|
233
|
-
dir.subfiles.forEach((filePath) => {
|
|
234
|
-
if (!exclude.find((excludeFilePath) => excludeFilePath === filePath)) {
|
|
235
|
-
tree.delete(path + filePath);
|
|
236
|
-
logInfo(filePath + ' gelöscht.');
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return tree;
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function searchInComponentAndModifyModule(
|
|
246
|
-
tree: Tree,
|
|
247
|
-
rootPath: string,
|
|
248
|
-
searchStrings: string[],
|
|
249
|
-
callback: Function,
|
|
250
|
-
...filePathEndings: string[]
|
|
251
|
-
) {
|
|
252
|
-
tree.getDir(rootPath).visit((filePath: string) => {
|
|
253
|
-
// Ignoriere folende Odner
|
|
254
|
-
if (
|
|
255
|
-
filePath.startsWith('/node_modules/') ||
|
|
256
|
-
filePath.startsWith('/.idea/') ||
|
|
257
|
-
filePath.startsWith('/coverage/') ||
|
|
258
|
-
filePath.startsWith('/dist/') ||
|
|
259
|
-
filePath.endsWith('.spec.ts')
|
|
260
|
-
) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Endung der Datei mit erlaubten Endungen abgleichen
|
|
265
|
-
let modifyFile: boolean = false;
|
|
266
|
-
for (let fileEnding of filePathEndings) {
|
|
267
|
-
if (filePath.endsWith(fileEnding)) {
|
|
268
|
-
modifyFile = true;
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
// Besitzt die Datei die richtige Endung?
|
|
273
|
-
if (!modifyFile) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
// Inhalt auslesen
|
|
277
|
-
const content = tree.read(filePath);
|
|
278
|
-
// Wenn die Datei keinen Inhalt hat, die nächste Datei aufrufen
|
|
279
|
-
if (!content) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
let foundSearchString: string = '';
|
|
284
|
-
searchStrings.forEach((searchString: string) => {
|
|
285
|
-
if (!foundSearchString && content.toString().indexOf(searchString) > -1) {
|
|
286
|
-
foundSearchString = searchString;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
if (!foundSearchString) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// den Ordner der gefundenen Datei nehmen
|
|
295
|
-
const fileDir = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
296
|
-
const modulePath: Path = findModule(tree, fileDir);
|
|
297
|
-
let moduleContent = tree.read(modulePath);
|
|
298
|
-
if (moduleContent) {
|
|
299
|
-
// Callback mit aktuellem Pfad + Inhalt der Datei aufrufen
|
|
300
|
-
callback(modulePath, moduleContent.toString());
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Function to find the "closest" module to a generated file's path.
|
|
307
|
-
*
|
|
308
|
-
* Source: https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/utility/find-module.ts
|
|
309
|
-
*/
|
|
310
|
-
export function findModule(
|
|
311
|
-
host: Tree,
|
|
312
|
-
generateDir: string,
|
|
313
|
-
moduleExt = '.module.ts',
|
|
314
|
-
routingModuleExt = '-routing.module.ts'
|
|
315
|
-
): Path {
|
|
316
|
-
let dir: DirEntry | null = host.getDir('/' + generateDir);
|
|
317
|
-
let foundRoutingModule = false;
|
|
318
|
-
|
|
319
|
-
while (dir) {
|
|
320
|
-
const allMatches = dir.subfiles.filter((p) => p.endsWith(moduleExt));
|
|
321
|
-
const filteredMatches = allMatches.filter((p) => !p.endsWith(routingModuleExt));
|
|
322
|
-
|
|
323
|
-
foundRoutingModule = foundRoutingModule || allMatches.length !== filteredMatches.length;
|
|
324
|
-
|
|
325
|
-
if (filteredMatches.length == 1) {
|
|
326
|
-
return join(dir.path, filteredMatches[0]);
|
|
327
|
-
} else if (filteredMatches.length > 1) {
|
|
328
|
-
throw new Error(
|
|
329
|
-
'More than one module matches. Use skip-import option to skip importing ' +
|
|
330
|
-
'the component into the closest module.'
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
dir = dir.parent;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const errorMsg = foundRoutingModule
|
|
338
|
-
? 'Could not find a non Routing NgModule.' +
|
|
339
|
-
`\nModules with suffix '${routingModuleExt}' are strictly reserved for routing.` +
|
|
340
|
-
'\nUse the skip-import option to skip importing in NgModule.'
|
|
341
|
-
: 'Could not find an NgModule. Use the skip-import option to skip importing in NgModule.';
|
|
342
|
-
|
|
343
|
-
throw new Error(errorMsg);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Löscht die Datei aus dem gegebenen Pfad.
|
|
348
|
-
* @param options
|
|
349
|
-
* @param targetPath
|
|
350
|
-
*/
|
|
351
|
-
export function deleteFile(options: any, targetPath: string): Rule {
|
|
352
|
-
return (tree: Tree, _context: SchematicContext) => {
|
|
353
|
-
logInfoWithDescriptor('Lösche Datei ' + targetPath + '.');
|
|
354
|
-
if (!targetPath.startsWith('/')) {
|
|
355
|
-
targetPath = '/' + targetPath;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
targetPath = (options.path ? options.path : '') + targetPath;
|
|
359
|
-
|
|
360
|
-
if (tree.exists(targetPath)) {
|
|
361
|
-
tree.delete(targetPath);
|
|
362
|
-
logSuccess(targetPath + ' erfolgreich gelöscht.');
|
|
363
|
-
} else {
|
|
364
|
-
logSuccess(targetPath + ' konnte nicht gefunden werden.');
|
|
365
|
-
}
|
|
366
|
-
return tree;
|
|
367
|
-
};
|
|
368
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hit.js","sourceRoot":"","sources":["hit.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,GAAG;IAOd;;;;;;;;;OASG;IACH,YAAY,WAAmB,EAAE,QAAgB,EAAE,cAAsB,EAAE,OAAgB,EAAE,GAAW;QACtG,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAxBD,kBAwBC"}
|
package/src/utility/html/hit.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Die {@link Hit}-Klasse repräsentiert einen Treffer, der Anhand des verwendeten Selektors gefunden wurde.
|
|
3
|
-
*/
|
|
4
|
-
export class Hit {
|
|
5
|
-
placeholder: string;
|
|
6
|
-
selector: string;
|
|
7
|
-
row: number;
|
|
8
|
-
elementContent: string;
|
|
9
|
-
element: Element;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Der Konstruktor der {@link Hit}-Klasse.
|
|
13
|
-
*
|
|
14
|
-
* @param placeholder Der Platzhalter des Treffers. Im Nachgang wird der {@link HtmlManipulator} den Platzhalter des Treffers
|
|
15
|
-
* in der HTML-Ausgabe durch den transformierten HTML-Inhalt ersetzen.
|
|
16
|
-
* @param selector Der CSS-Selektor.
|
|
17
|
-
* @param elementContent Der HTML-Inhalt des Elements und NICHT des gesamten HTML-Templates.
|
|
18
|
-
* @param element Das {@link Element}.
|
|
19
|
-
* @param row Die Startzeile im HTML-Template.
|
|
20
|
-
*/
|
|
21
|
-
constructor(placeholder: string, selector: string, elementContent: string, element: Element, row: number) {
|
|
22
|
-
this.placeholder = placeholder;
|
|
23
|
-
this.elementContent = elementContent;
|
|
24
|
-
this.row = row;
|
|
25
|
-
this.selector = selector;
|
|
26
|
-
this.element = element;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html-manipulator.js","sourceRoot":"","sources":["html-manipulator.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,kCAAuC;AACvC,+BAA4B;AAGf,QAAA,kBAAkB,GAAG,wBAAwB,CAAC;AAC9C,QAAA,WAAW,GAAG,eAA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AK,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,0BAAkB,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAChH;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAhID,0CAgIC"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { JSDOM } from 'jsdom';
|
|
2
|
-
import { replaceFirst } from '../util';
|
|
3
|
-
import { Hit } from './hit';
|
|
4
|
-
import { ManipulatorFn } from './manipulator-functions';
|
|
5
|
-
|
|
6
|
-
export const ATTR_NOT_PROCESSED = 'data-lux-not-processed';
|
|
7
|
-
export const PLACEHOLDER = `@@@element@@@`;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Der {@link HtmlManipulator} ist für die Manipulation der HTML-Templates zuständig.
|
|
11
|
-
*
|
|
12
|
-
* Warum verwendet der {@link HtmlManipulator} eigene Funktionen, um den HTML-Inhalt anzupassen,
|
|
13
|
-
* anstatt die bereitgestellten Methoden von JSDOm (serialize()) bzw. Cheerio (xml() oder html() zu verwenden?
|
|
14
|
-
*
|
|
15
|
-
* Die serialize-Methode von JSDOM wandelt alle Attribute in Kleinschrift um, sodass die Angular-Attribute nicht mehr
|
|
16
|
-
* funktionieren. Cheerio kann konfiguriert werden, sodass die Camel-Case-Namen erhalten bleiben,
|
|
17
|
-
* aber dort werden z.B. die leeren Ent-Tags ersetzt. Zusätzlich bricht Cheerio manchmal in komplexeren Templates an Stellen um,
|
|
18
|
-
* sodass das Template im Anschluss nicht mehr kompiliert.
|
|
19
|
-
*
|
|
20
|
-
* @example JSDOM
|
|
21
|
-
* Input: <lux-input luxLabel="Lorem ipsum"></lux-input>
|
|
22
|
-
* Output: <lux-input luxlabel="Lorem ipsum"></lux-input>
|
|
23
|
-
*
|
|
24
|
-
* @example Cheerio
|
|
25
|
-
* Input: <lux-input></lux-input>
|
|
26
|
-
* Output: <lux-input/>
|
|
27
|
-
*/
|
|
28
|
-
export class HtmlManipulator {
|
|
29
|
-
private htmlContent: string;
|
|
30
|
-
private readonly selector: string;
|
|
31
|
-
private readonly manipulatorFNs: ManipulatorFn[];
|
|
32
|
-
|
|
33
|
-
private constructor(htmlContent: string, selector: string, manipulatorFns: ManipulatorFn[]) {
|
|
34
|
-
this.htmlContent = htmlContent;
|
|
35
|
-
this.selector = selector;
|
|
36
|
-
this.manipulatorFNs = manipulatorFns ?? [];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Diese Methode ermittelt alle betroffenen HTML-Elemente anhand des übergebenen Selektors und versieht diese mit dem temporären
|
|
41
|
-
* {@link ATTR_NOT_PROCESSED}-Attribut.
|
|
42
|
-
*
|
|
43
|
-
* @example Selektor - lux-card
|
|
44
|
-
* <div>
|
|
45
|
-
* <lux-card luxTitle="Test">
|
|
46
|
-
* <lux-card-content>
|
|
47
|
-
* <p>Lorem ipsum</p>
|
|
48
|
-
* </lux-card-content>
|
|
49
|
-
* </lux-card>
|
|
50
|
-
* </div>
|
|
51
|
-
*
|
|
52
|
-
* <div>
|
|
53
|
-
* <lux-card data-lux-not-processed luxTitle="Test">
|
|
54
|
-
* <lux-card-content>
|
|
55
|
-
* <p>Lorem ipsum</p>
|
|
56
|
-
* </lux-card-content>
|
|
57
|
-
* </lux-card>
|
|
58
|
-
* </div>
|
|
59
|
-
*
|
|
60
|
-
* @param htmlContent Der HTML-Inhalt.
|
|
61
|
-
* @param selector Der CSS-Selektor.
|
|
62
|
-
*/
|
|
63
|
-
static prepare(htmlContent: string, selector: string): string {
|
|
64
|
-
const dom = new JSDOM(htmlContent, { includeNodeLocations: true });
|
|
65
|
-
const elements = dom.window.document.querySelectorAll(selector);
|
|
66
|
-
|
|
67
|
-
let counter = 0;
|
|
68
|
-
elements.forEach((el) => {
|
|
69
|
-
const location = dom.nodeLocation(el);
|
|
70
|
-
const startIndex = location?.startOffset ?? -1;
|
|
71
|
-
const endIndex = location?.endOffset ?? -1;
|
|
72
|
-
|
|
73
|
-
htmlContent = this.addUnprocessedAttr(htmlContent, el.tagName, startIndex, endIndex, counter++);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return htmlContent;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Diese Methode transformiert den übergebenen HTML-Inhalt mit den Manipulator-Funktionen.
|
|
81
|
-
*
|
|
82
|
-
* @param htmlContent Der HTML-Inhalt.
|
|
83
|
-
* @param selector Der CSS-Selektor.
|
|
84
|
-
* @param manipulatorFns Die Funktionen manipulieren den HTML-Inhalt.
|
|
85
|
-
*/
|
|
86
|
-
static transform(htmlContent: string, selector: string, ...manipulatorFns: ManipulatorFn[]): string {
|
|
87
|
-
return new HtmlManipulator(htmlContent, selector, manipulatorFns).do();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Diese Methode liefert die Anzahl der mit dem Selektor gefundenen Elemente zurück.
|
|
92
|
-
*
|
|
93
|
-
* @param htmlContent Der HTML-Inhalt.
|
|
94
|
-
* @param selector Der CSS-Selektor.
|
|
95
|
-
*/
|
|
96
|
-
static count(htmlContent: string, selector: string): number {
|
|
97
|
-
return new JSDOM(htmlContent, { includeNodeLocations: false }).window.document.querySelectorAll(selector).length;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private do(): string {
|
|
101
|
-
this.htmlContent = HtmlManipulator.prepare(this.htmlContent, this.selector);
|
|
102
|
-
|
|
103
|
-
// Hier wird der erste Treffer gesetzt. Zusätzlich wird im Ergebnis-HTML anstelle des Elements ein Platzhalter eingesetzt.
|
|
104
|
-
// Dieser Platzhalter wird im Nachgang wieder durch das manipulierte HTML des Elements ersetzt.
|
|
105
|
-
let hit = this.next();
|
|
106
|
-
while (hit) {
|
|
107
|
-
// Hier wird der HTML-Inhalt des Elements über die Manipulator-Funktionen angepasst.
|
|
108
|
-
this.manipulatorFNs.forEach((fn) => fn(hit!));
|
|
109
|
-
|
|
110
|
-
// Jetzt muss das unprocessed-Attribut, das in der prepare-Methode gesetzt wurde, wieder entfernt werden.
|
|
111
|
-
const updatedHtml = replaceFirst(hit.elementContent, ' ' + ATTR_NOT_PROCESSED, '');
|
|
112
|
-
|
|
113
|
-
// Zum Schluss muss der veränderte HTML-Inhalt des Elements wieder an die Stelle des Platzhalters im Ergebnis-HTML eingesetzt werden.
|
|
114
|
-
// Der Platzhalter im Ergebnis wird durch die next-Methode gesetzt.
|
|
115
|
-
this.htmlContent = this.htmlContent.replace(hit.placeholder, updatedHtml);
|
|
116
|
-
|
|
117
|
-
// Hier wird der nächste Treffer gesetzt.
|
|
118
|
-
// Details siehe den next()-Aufruf weiter oben.
|
|
119
|
-
hit = this.next();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return this.htmlContent;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private next(): Hit | null {
|
|
126
|
-
const dom = new JSDOM(this.htmlContent, { includeNodeLocations: true });
|
|
127
|
-
const element = dom.window.document.querySelector(`*[${ATTR_NOT_PROCESSED}]`);
|
|
128
|
-
|
|
129
|
-
if (element) {
|
|
130
|
-
const location = dom.nodeLocation(element);
|
|
131
|
-
if (location && location.startOffset >= 0 && location.endOffset >= 0) {
|
|
132
|
-
const start = location.startOffset;
|
|
133
|
-
const end = location.endOffset;
|
|
134
|
-
|
|
135
|
-
// Der Hit auf denen die Manipulator-Funktionen arbeiten, bekommen nur den HTML-Inhalt des Elements und
|
|
136
|
-
// nicht den gesamten Inhalt.
|
|
137
|
-
const hitContent = this.htmlContent.slice(start, end);
|
|
138
|
-
|
|
139
|
-
// Für das HTML des Elements wird der Platzhalter eingesetzt.
|
|
140
|
-
this.htmlContent = this.htmlContent.slice(0, start) + PLACEHOLDER + this.htmlContent.slice(end, this.htmlContent.length);
|
|
141
|
-
|
|
142
|
-
return new Hit(PLACEHOLDER, this.selector, hitContent, element, location.startLine);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private static addUnprocessedAttr(htmlContent: string, tagName: string, startIndex: number, endIndex: number, counter: number) {
|
|
150
|
-
if (startIndex >= 0 && endIndex >= 0) {
|
|
151
|
-
const position = startIndex + (tagName.length + 1) + counter * (ATTR_NOT_PROCESSED.length + 1); /* +1 für die Leerzeichen */
|
|
152
|
-
htmlContent = [htmlContent.slice(0, position), ' ' + ATTR_NOT_PROCESSED, htmlContent.slice(position)].join('');
|
|
153
|
-
}
|
|
154
|
-
return htmlContent;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|