@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.
Files changed (158) hide show
  1. package/LICENSE +198 -0
  2. package/README.md +55 -0
  3. package/package.json +54 -0
  4. package/src/add-lux-components/files/app/app-routing.module.ts +19 -0
  5. package/src/add-lux-components/files/app/app.component.html +27 -0
  6. package/src/add-lux-components/files/app/app.component.spec.ts +19 -0
  7. package/src/add-lux-components/files/app/app.component.ts +13 -0
  8. package/src/add-lux-components/files/app/app.module.ts +56 -0
  9. package/src/add-lux-components/files/app/error/error.component.html +10 -0
  10. package/src/add-lux-components/files/app/error/error.component.scss +3 -0
  11. package/src/add-lux-components/files/app/error/error.component.spec.ts +49 -0
  12. package/src/add-lux-components/files/app/error/error.component.ts +17 -0
  13. package/src/add-lux-components/files/app/home/home.component.html +7 -0
  14. package/src/add-lux-components/files/app/home/home.component.scss +0 -0
  15. package/src/add-lux-components/files/app/home/home.component.ts +13 -0
  16. package/src/add-lux-components/files/app/profil/profil.component.html +1 -0
  17. package/src/add-lux-components/files/app/profil/profil.component.scss +0 -0
  18. package/src/add-lux-components/files/app/profil/profil.component.spec.ts +24 -0
  19. package/src/add-lux-components/files/app/profil/profil.component.ts +11 -0
  20. package/src/add-lux-components/files/environments/environment.prod.ts +4 -0
  21. package/src/add-lux-components/files/environments/environment.ts +17 -0
  22. package/src/add-lux-components/files/locale/messages.en.xlf +948 -0
  23. package/src/add-lux-components/files/locale/messages.xlf +822 -0
  24. package/src/add-lux-components/files/scripts/.browserslistrc +17 -0
  25. package/src/add-lux-components/files/src/polyfills.ts +68 -0
  26. package/src/add-lux-components/index.d.ts +10 -0
  27. package/src/add-lux-components/index.js +143 -0
  28. package/src/add-lux-components/index.js.map +1 -0
  29. package/src/add-lux-components/index.ts +183 -0
  30. package/src/add-lux-components/index_spec.d.ts +1 -0
  31. package/src/add-lux-components/index_spec.js +51 -0
  32. package/src/add-lux-components/index_spec.js.map +1 -0
  33. package/src/add-lux-components/index_spec.ts +55 -0
  34. package/src/add-lux-components/schema.json +23 -0
  35. package/src/collection.json +55 -0
  36. package/src/migrate-to-eslint/files/.eslintrc.json +68 -0
  37. package/src/migrate-to-eslint/files/.prettierrc +25 -0
  38. package/src/migrate-to-eslint/index.d.ts +6 -0
  39. package/src/migrate-to-eslint/index.js +149 -0
  40. package/src/migrate-to-eslint/index.js.map +1 -0
  41. package/src/migrate-to-eslint/index.ts +181 -0
  42. package/src/migrate-to-eslint/index_spec.d.ts +1 -0
  43. package/src/migrate-to-eslint/index_spec.js +129 -0
  44. package/src/migrate-to-eslint/index_spec.js.map +1 -0
  45. package/src/migrate-to-eslint/index_spec.ts +152 -0
  46. package/src/migrate-to-eslint/schema.json +23 -0
  47. package/src/migrate-to-webcomponent/index.d.ts +10 -0
  48. package/src/migrate-to-webcomponent/index.js +278 -0
  49. package/src/migrate-to-webcomponent/index.js.map +1 -0
  50. package/src/migrate-to-webcomponent/index.ts +331 -0
  51. package/src/migrate-to-webcomponent/index_spec.d.ts +1 -0
  52. package/src/migrate-to-webcomponent/index_spec.js +580 -0
  53. package/src/migrate-to-webcomponent/index_spec.js.map +1 -0
  54. package/src/migrate-to-webcomponent/index_spec.ts +703 -0
  55. package/src/migrate-to-webcomponent/schema.json +23 -0
  56. package/src/update/files/locale/messages.en.xlf +940 -0
  57. package/src/update/files/locale/messages.xlf +815 -0
  58. package/src/update/files/scripts/move-de-files.js +15 -0
  59. package/src/update/index.d.ts +23 -0
  60. package/src/update/index.js +635 -0
  61. package/src/update/index.js.map +1 -0
  62. package/src/update/index.ts +712 -0
  63. package/src/update/index_spec.d.ts +1 -0
  64. package/src/update/index_spec.js +990 -0
  65. package/src/update/index_spec.js.map +1 -0
  66. package/src/update/index_spec.ts +1145 -0
  67. package/src/update/schema.json +23 -0
  68. package/src/update-dependencies/index.d.ts +5 -0
  69. package/src/update-dependencies/index.js +113 -0
  70. package/src/update-dependencies/index.js.map +1 -0
  71. package/src/update-dependencies/index.ts +114 -0
  72. package/src/update-dependencies/schema.json +23 -0
  73. package/src/update110001/index.d.ts +2 -0
  74. package/src/update110001/index.js +42 -0
  75. package/src/update110001/index.js.map +1 -0
  76. package/src/update110001/index.ts +40 -0
  77. package/src/update110001/index_spec.d.ts +1 -0
  78. package/src/update110001/index_spec.js +67 -0
  79. package/src/update110001/index_spec.js.map +1 -0
  80. package/src/update110001/index_spec.ts +72 -0
  81. package/src/update110001/schema.json +23 -0
  82. package/src/update110100/index.d.ts +2 -0
  83. package/src/update110100/index.js +27 -0
  84. package/src/update110100/index.js.map +1 -0
  85. package/src/update110100/index.ts +24 -0
  86. package/src/update110100/index_spec.d.ts +1 -0
  87. package/src/update110100/index_spec.js +69 -0
  88. package/src/update110100/index_spec.js.map +1 -0
  89. package/src/update110100/index_spec.ts +73 -0
  90. package/src/update110100/schema.json +23 -0
  91. package/src/update110101/index.d.ts +2 -0
  92. package/src/update110101/index.js +24 -0
  93. package/src/update110101/index.js.map +1 -0
  94. package/src/update110101/index.ts +21 -0
  95. package/src/update110101/index_spec.d.ts +1 -0
  96. package/src/update110101/index_spec.js +65 -0
  97. package/src/update110101/index_spec.js.map +1 -0
  98. package/src/update110101/index_spec.ts +69 -0
  99. package/src/update110101/schema.json +23 -0
  100. package/src/update110200/index.d.ts +2 -0
  101. package/src/update110200/index.js +24 -0
  102. package/src/update110200/index.js.map +1 -0
  103. package/src/update110200/index.ts +21 -0
  104. package/src/update110200/index_spec.d.ts +1 -0
  105. package/src/update110200/index_spec.js +65 -0
  106. package/src/update110200/index_spec.js.map +1 -0
  107. package/src/update110200/index_spec.ts +69 -0
  108. package/src/update110200/schema.json +23 -0
  109. package/src/update110300/index.d.ts +2 -0
  110. package/src/update110300/index.js +133 -0
  111. package/src/update110300/index.js.map +1 -0
  112. package/src/update110300/index.ts +148 -0
  113. package/src/update110300/index_spec.d.ts +1 -0
  114. package/src/update110300/index_spec.js +121 -0
  115. package/src/update110300/index_spec.js.map +1 -0
  116. package/src/update110300/index_spec.ts +139 -0
  117. package/src/update110300/schema.json +23 -0
  118. package/src/utility/dependencies.d.ts +39 -0
  119. package/src/utility/dependencies.js +96 -0
  120. package/src/utility/dependencies.js.map +1 -0
  121. package/src/utility/dependencies.ts +116 -0
  122. package/src/utility/files.d.ts +60 -0
  123. package/src/utility/files.js +299 -0
  124. package/src/utility/files.js.map +1 -0
  125. package/src/utility/files.ts +355 -0
  126. package/src/utility/html.d.ts +49 -0
  127. package/src/utility/html.js +183 -0
  128. package/src/utility/html.js.map +1 -0
  129. package/src/utility/html.ts +212 -0
  130. package/src/utility/json.d.ts +34 -0
  131. package/src/utility/json.js +70 -0
  132. package/src/utility/json.js.map +1 -0
  133. package/src/utility/json.ts +70 -0
  134. package/src/utility/logging.d.ts +32 -0
  135. package/src/utility/logging.js +82 -0
  136. package/src/utility/logging.js.map +1 -0
  137. package/src/utility/logging.ts +80 -0
  138. package/src/utility/test.d.ts +10 -0
  139. package/src/utility/test.js +24 -0
  140. package/src/utility/test.js.map +1 -0
  141. package/src/utility/test.ts +24 -0
  142. package/src/utility/typescript.d.ts +22 -0
  143. package/src/utility/typescript.js +521 -0
  144. package/src/utility/typescript.js.map +1 -0
  145. package/src/utility/typescript.ts +598 -0
  146. package/src/utility/typescript_spec.d.ts +1 -0
  147. package/src/utility/typescript_spec.js +1006 -0
  148. package/src/utility/typescript_spec.js.map +1 -0
  149. package/src/utility/typescript_spec.ts +1267 -0
  150. package/src/utility/util.d.ts +33 -0
  151. package/src/utility/util.js +139 -0
  152. package/src/utility/util.js.map +1 -0
  153. package/src/utility/util.ts +140 -0
  154. package/src/utility/validation.d.ts +11 -0
  155. package/src/utility/validation.js +44 -0
  156. package/src/utility/validation.js.map +1 -0
  157. package/src/utility/validation.ts +49 -0
  158. package/tsconfig.json +37 -0
@@ -0,0 +1,712 @@
1
+ import { chain, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
2
+ import * as chalk from 'chalk';
3
+ import { applyEdits, Edit, findNodeAtLocation, modify } from 'jsonc-parser';
4
+ import * as ts from 'typescript';
5
+ import { updateDependencies } from '../update-dependencies/index';
6
+ import { deleteFilesInDirectory, moveFilesToDirectory } from '../utility/files';
7
+ import { jsonFormattingOptions, readJson, readJsonAsString } from '../utility/json';
8
+ import { logInfo, logInfoWithDescriptor, logSuccess } from '../utility/logging';
9
+ import {
10
+ addConstructorContent,
11
+ addConstructorParameter,
12
+ addImport,
13
+ getNextSibling,
14
+ getPrevSibling,
15
+ getSourceNodes,
16
+ removeImport,
17
+ removeProvider
18
+ } from '../utility/typescript';
19
+ import { applyRuleIf, finish, messageInfoRule, messageSuccessRule } from '../utility/util';
20
+ import { validateLuxComponentsVersion, validateNodeVersion } from '../utility/validation';
21
+
22
+ export const updateMajorVersion = '11';
23
+ export const updateMinVersion = '10.8.2';
24
+ export const updateNodeMinVersion = '12.0.0';
25
+
26
+ export function update(options: any): Rule {
27
+ return (tree: Tree, _context: SchematicContext) => {
28
+ return chain([
29
+ check(options),
30
+ applyRuleIf(updateMinVersion, updateProject(options)),
31
+ finish(
32
+ `${chalk.yellowBright(
33
+ 'Wichtig!!!'
34
+ )} Hinweise im Update Guide beachten -> https://github.com/IHK-GfI/lux-components/wiki/update-guide-${updateMajorVersion}`
35
+ )
36
+ ]);
37
+ };
38
+ }
39
+
40
+ export function updateProject(options: any): Rule {
41
+ return (tree: Tree, _context: SchematicContext) => {
42
+ return chain([
43
+ messageInfoRule(`LUX-Components ${updateMajorVersion} werden aktualisiert...`),
44
+ updateBrowserList(options),
45
+ deleteOldThemeDir(options),
46
+ clearStylesScss(options),
47
+ updateAngularJson(options),
48
+ updateAppComponent(options),
49
+ updateAppModule(options),
50
+ updateTsConfigJson(options),
51
+ addI18N(options),
52
+ updateDependencies(),
53
+ messageSuccessRule(`LUX-Components ${updateMajorVersion} wurden aktualisiert.`)
54
+ ]);
55
+ };
56
+ }
57
+
58
+ export function addI18N(options: any): Rule {
59
+ return chain([
60
+ messageInfoRule(`I18N-Unterstützung wird hinzugefügt...`),
61
+ i18nUpdatePackageJson(options),
62
+ i18nUpdateAngularJson(options),
63
+ i18nCopyMessages(options),
64
+ i18nUpdatePolyfills(options),
65
+ i18nUpdateAppModule(options),
66
+ messageSuccessRule(`I18N-Unterstützung wurde hinzugefügt...`)
67
+ ]);
68
+ }
69
+
70
+ export function i18nUpdateAngularJson(options: any): Rule {
71
+ return chain([
72
+ messageInfoRule(`Die Datei "angular.json" wird angepasst...`),
73
+ (tree: Tree, _context: SchematicContext) => {
74
+ const filePath = `/angular.json`;
75
+
76
+ const newValuesArr = [
77
+ {
78
+ path: ['projects', options.project, 'i18n'],
79
+ value: {
80
+ sourceLocale: {
81
+ 'code': 'de',
82
+ 'baseHref': '/'
83
+ },
84
+ locales: {
85
+ en: 'src/locale/messages.en.xlf'
86
+ }
87
+ },
88
+ message: `Neuen Abschnitt "xi18n" unter projects/${options.project} hinzugefügt.`
89
+ },
90
+ {
91
+ path: ['projects', options.project, 'architect', 'build', 'options', 'localize'],
92
+ value: ["de"],
93
+ message: `Neuen Abschnitt "localize" unter projects/${options.project}/architect/build/options hinzugefügt.`
94
+ },
95
+ {
96
+ path: ['projects', options.project, 'architect', 'build', 'options', 'i18nMissingTranslation'],
97
+ value: "error",
98
+ message: `Neuen Abschnitt "i18nMissingTranslation" unter projects/${options.project}/architect/build/options hinzugefügt.`
99
+ },
100
+ {
101
+ path: ['projects', options.project, 'architect', 'build', 'configurations', 'en'],
102
+ value: {
103
+ "localize": ["en"],
104
+ "aot": true,
105
+ "outputPath": "dist/en",
106
+ "i18nMissingTranslation": "error"
107
+ },
108
+ message: `Neuen Abschnitt "en" unter projects/${options.project}/architect/build/configurations hinzugefügt.`
109
+ },
110
+ {
111
+ path: ['projects', options.project, 'architect', 'serve', 'configurations', 'en'],
112
+ value: {
113
+ "browserTarget": options.project + ":build:en"
114
+ },
115
+ message: `Neuen Abschnitt "en" unter projects/${options.project}/architect/serve/configurations hinzugefügt.`
116
+ }
117
+ ];
118
+
119
+ newValuesArr.forEach(change => {
120
+ const tsConfigJson = readJsonAsString(tree, filePath);
121
+ const edits: Edit[] = modify(tsConfigJson, change.path, change.value, { formattingOptions: jsonFormattingOptions })
122
+
123
+ tree.overwrite(
124
+ filePath,
125
+ applyEdits(tsConfigJson, edits)
126
+ );
127
+
128
+ logInfo(change.message);
129
+ });
130
+
131
+ return tree;
132
+ },
133
+ messageSuccessRule(`Die Datei "angular.json" wurde angepasst.`)
134
+ ]);
135
+ }
136
+
137
+ export function i18nUpdatePackageJson(options: any): Rule {
138
+ return chain([
139
+ messageInfoRule(`Die Datei "package.json" wird angepasst...`),
140
+ (tree: Tree, _context: SchematicContext) => {
141
+ const filePath = `/package.json`;
142
+
143
+ const newValuesArr = [
144
+ { path: ['scripts', 'move-de-files'], value: "node move-de-files.js", message: `Neues Skript "move-de-files" hinzugefügt.`},
145
+ { path: ['scripts', 'xi18n'], value: "ng extract-i18n --output-path src/locale --ivy", message: `Neues Skript "xi18n" hinzugefügt.`}
146
+ ];
147
+
148
+ const packageJsonAsNode = readJson(tree, filePath);
149
+
150
+ // Neues start-en-Skript hinzufügen
151
+ const startScriptNode = findNodeAtLocation(packageJsonAsNode, ['scripts', 'start']);
152
+ if (startScriptNode) {
153
+ newValuesArr.push({
154
+ path: ['scripts', 'start-en'],
155
+ value: startScriptNode.value + ' --configuration en',
156
+ message: `Das neue Skript "start-en" hinzugefügt.`
157
+ });
158
+ } else {
159
+ newValuesArr.push({
160
+ path: ['scripts', 'start-en'],
161
+ value: 'ng serve --public-host=http://localhost:4200 --configuration en',
162
+ message: `Das neue Skript "start-en" hinzugefügt.`
163
+ });
164
+ }
165
+
166
+ // build-aot-Script anpassen
167
+ const buildAotScriptNode = findNodeAtLocation(packageJsonAsNode, ['scripts', 'build-aot']);
168
+ if (buildAotScriptNode) {
169
+ newValuesArr.push({
170
+ path: ['scripts', 'build-aot'],
171
+ value: buildAotScriptNode.value + ' && npm run move-de-files',
172
+ message: `Dem Skript "build-aot" den Parameter "&& npm run move-de-files" hinzugefügt.`
173
+ });
174
+ } else {
175
+ newValuesArr.push({
176
+ path: ['scripts', 'build-aot'],
177
+ value: 'node --max_old_space_size=4024 ./node_modules/@angular/cli/bin/ng build --aot && npm run move-de-files',
178
+ message: `Das Skript "build-aot" mit dem Parameter "&& npm run move-de-files" hinzugefügt.`
179
+ });
180
+ }
181
+
182
+ // buildzentral-Script anpassen
183
+ const buildZentralScriptNode = findNodeAtLocation(packageJsonAsNode, ['scripts', 'buildzentral']);
184
+ if (buildZentralScriptNode) {
185
+ newValuesArr.push({
186
+ path : ['scripts', 'buildzentral'],
187
+ value : buildZentralScriptNode.value + " && npm run move-de-files",
188
+ message: `Dem Skript "buildzentral" den Parameter "&& npm run move-de-files" hinzugefügt.`
189
+ });
190
+ } else {
191
+ newValuesArr.push({
192
+ path: ['scripts', 'buildzentral'],
193
+ value: 'node --max_old_space_size=4024 ./node_modules/@angular/cli/bin/ng build --prod && npm run move-de-files',
194
+ message: `Das Skript "buildzentral" mit dem Parameter "&& npm run move-de-files" hinzugefügt.`
195
+ });
196
+ }
197
+
198
+ newValuesArr.forEach(change => {
199
+ const tsConfigJson = readJsonAsString(tree, filePath);
200
+ const edits: Edit[] = modify(tsConfigJson, change.path, change.value, { formattingOptions: jsonFormattingOptions })
201
+
202
+ tree.overwrite(
203
+ filePath,
204
+ applyEdits(tsConfigJson, edits)
205
+ );
206
+
207
+ logInfo(change.message);
208
+ });
209
+
210
+ return tree;
211
+ },
212
+ messageSuccessRule(`Die Datei "package.json" wurde angepasst.`)
213
+ ]);
214
+ }
215
+
216
+ export function i18nUpdateAppModule(options: any): Rule {
217
+ return chain([
218
+ messageInfoRule(`Die Datei "app.module.ts" wird angepasst...`),
219
+ (tree: Tree, _context: SchematicContext) => {
220
+ const filePath = (options.path ? options.path : '') + `/src/app/app.module.ts`;
221
+
222
+ removeImport(tree, filePath, '@angular/core', 'LOCALE_ID');
223
+ removeImport(tree, filePath, '@angular/common', 'registerLocaleData');
224
+ removeImport(tree, filePath, '@angular/common/locales/global/de');
225
+
226
+ removeProvider(tree, filePath, 'LOCALE_ID');
227
+
228
+ return tree;
229
+ },
230
+ messageSuccessRule(`Die Datei "app.module.ts" wurde angepasst.`)
231
+ ]);
232
+ }
233
+
234
+ export function i18nUpdatePolyfills(options: any): Rule {
235
+ return chain([
236
+ messageInfoRule(`Import wird in der Datei "polyfills.ts" hinzugefügt...`),
237
+ (tree: Tree, _context: SchematicContext) => {
238
+ const filePath = (options.path ? options.path : '') + '/src/polyfills.ts';
239
+
240
+ const content = tree.read(filePath);
241
+ if (content) {
242
+ let modifiedContent = '/***************************************************************************************************\n * Load \`$localize\` onto the global scope - used if i18n tags appear in Angular templates.\n */\nimport \'@angular/localize/init\';\n\n';
243
+ modifiedContent += content;
244
+
245
+ tree.overwrite(filePath, modifiedContent);
246
+ }
247
+
248
+ return tree;
249
+ },
250
+ messageSuccessRule(`Import wird in der Datei "polyfills.ts" hinzugefügt...`)
251
+ ]);
252
+ }
253
+
254
+
255
+ export function i18nCopyMessages(options: any): Rule {
256
+ return chain([
257
+ messageInfoRule(`Sprachdateien werden kopiert...`),
258
+ moveFilesToDirectory(options, 'files/locale', 'src/locale'),
259
+ moveFilesToDirectory(options, 'files/scripts', '/'),
260
+ messageSuccessRule(`Sprachdateien wurden kopiert.`)
261
+ ]);
262
+ }
263
+
264
+ export function check(options: any): Rule {
265
+ return (tree: Tree, _context: SchematicContext) => {
266
+ logInfoWithDescriptor(`Vorbedingungen werden geprüft...`);
267
+
268
+ validateNodeVersion(_context, updateNodeMinVersion);
269
+ validateLuxComponentsVersion(tree, `${updateMinVersion} || ^${updateMajorVersion}.0.0`);
270
+
271
+ logSuccess(`Vorbedingungen wurden geprüft.`);
272
+
273
+ return tree;
274
+ };
275
+ }
276
+
277
+ export function updateTsConfigJson(options: any): Rule {
278
+ return chain([
279
+ messageInfoRule(`Datei "tsconfig.json" wird aktualisiert...`),(tree: Tree, _context: SchematicContext) => {
280
+ const filePath = '/tsconfig.json';
281
+
282
+ const newValuesArr = [
283
+ { path: ['compilerOptions', 'strict'], value: false, message: `Die Property "compilerOptions.strict" wurde auf "false" gesetzt.`},
284
+ { path: ['compilerOptions', 'noImplicitReturns'], value: true, message: `Die Property "compilerOptions.noImplicitReturns" wurde auf "true" gesetzt.`},
285
+ { path: ['compilerOptions', 'noFallthroughCasesInSwitch'], value: true, message: `Die Property "compilerOptions.noFallthroughCasesInSwitch" wurde auf "true" gesetzt.`},
286
+ { path: ['compilerOptions', 'forceConsistentCasingInFileNames'], value: true, message: `Die Property "compilerOptions.forceConsistentCasingInFileNames" wurde auf "true" gesetzt.`},
287
+ { path: ['compilerOptions', 'lib'], value: ["es2018", "dom"], message: `Die Property "compilerOptions.lib" wurde auf "["es2018", "dom"]" gesetzt.`},
288
+ { path: ['compilerOptions', 'module'], value: "es2020", message: `Die Property "compilerOptions.module" wurde auf "es2020" gesetzt.`},
289
+ { path: ['angularCompilerOptions', 'strictInputAccessModifiers'], value: true, message: `Die Property "angularCompilerOptions.strictInputAccessModifiers" wurde auf "true" gesetzt.`},
290
+ { path: ['angularCompilerOptions', 'strictTemplates'], value: false, message: `Die Property "angularCompilerOptions.strictTemplates" wurde auf "false" gesetzt.`},
291
+ ];
292
+
293
+ newValuesArr.forEach(change => {
294
+ const tsConfigJson = readJsonAsString(tree, filePath);
295
+ const edits: Edit[] = modify(tsConfigJson, change.path, change.value, { formattingOptions: jsonFormattingOptions })
296
+
297
+ tree.overwrite(
298
+ filePath,
299
+ applyEdits(tsConfigJson, edits)
300
+ );
301
+
302
+ logInfo(change.message);
303
+ });
304
+ } ,
305
+ messageSuccessRule(`Datei "tsconfig.json" wurde aktualisiert.`),
306
+ ]);
307
+ }
308
+
309
+ export function updateBrowserList(options: any): Rule {
310
+ return chain([
311
+ messageInfoRule(`Datei ".browserslistrc" wird aktualisiert...`),
312
+ (tree: Tree, context: SchematicContext) => {
313
+ const filePath = '/.browserslistrc';
314
+ const browserListContent = tree.read(filePath);
315
+ if (browserListContent) {
316
+ const content = (browserListContent as Buffer).toString();
317
+ if (content) {
318
+ let modifiedContent = '';
319
+
320
+ const lines = content.split('\n');
321
+ if (lines) {
322
+ lines.forEach(line => {
323
+ if (line.trim().startsWith('IE 9-11')) {
324
+ modifiedContent += 'not IE 9-10' + '\n';
325
+ modifiedContent += 'IE 11' + '\n';
326
+ } else {
327
+ modifiedContent += line + '\n';
328
+ }
329
+ });
330
+
331
+ if (content !== modifiedContent) {
332
+ tree.overwrite(filePath, modifiedContent);
333
+ logInfo(`Einträge für den IE 9-10 entfernt.`);
334
+ }
335
+ }
336
+ }
337
+ } else {
338
+ logInfo(`Die Datei ".browserslistrc" konnte nicht gefunden werden.`);
339
+ }
340
+ },
341
+ messageSuccessRule(`Datei ".browserslistrc" wurde aktualisiert.`),
342
+ ]);
343
+ }
344
+
345
+ export function deleteOldThemeDir(options: any): Rule {
346
+ return chain([
347
+ messageInfoRule(`Altes Theming-Verzeichnis '/src/theming/' wird gelöscht...`),
348
+ deleteFilesInDirectory(options, '/src/theming/', []),
349
+ messageSuccessRule(`Altes Theming-Verzeichnis wurde gelöscht.`),
350
+ ]);
351
+ }
352
+
353
+ export function updateAngularJson(options: any): Rule {
354
+ return (tree: Tree, _context: SchematicContext) => {
355
+ return chain([
356
+ messageInfoRule(`Datei "angular.json" wird aktualisiert...`),
357
+ addThemeAssets(options),
358
+ removeThemeAssets(options),
359
+ addNg2PdfViewer(options),
360
+ messageSuccessRule(`Datei "angular.json" wurde aktualisiert.`),
361
+ ]);
362
+ };
363
+ }
364
+
365
+ export function addNg2PdfViewer(options: any): Rule {
366
+ return (tree: Tree, context: SchematicContext) => {
367
+ const filePath = '/angular.json';
368
+ const value = 'ng2-pdf-viewer';
369
+
370
+ let contentAsNode = readJson(tree, filePath);
371
+ const ngPdfViewerNode = findNodeAtLocation(contentAsNode, ['projects', options.project, 'architect', 'build', 'options', 'allowedCommonJsDependencies']);
372
+
373
+ let found = false;
374
+ if (ngPdfViewerNode){
375
+ ngPdfViewerNode.children?.forEach(child => {
376
+ if (child.value === value) {
377
+ found = true;
378
+ }
379
+ });
380
+ }
381
+
382
+ if (!found) {
383
+ const angularJson = readJsonAsString(tree, filePath);
384
+ const edits = modify(angularJson, ['projects', options.project, 'architect', 'build', 'options', 'allowedCommonJsDependencies', 0], value, { formattingOptions: jsonFormattingOptions, isArrayInsertion: true });
385
+ if (edits) {
386
+ tree.overwrite(
387
+ filePath,
388
+ applyEdits(angularJson, edits)
389
+ );
390
+ logInfo(`"ng2-pdf-viewer" im Abschnitt "allowedCommonJsDependencies" hinzugefügt.`);
391
+ }
392
+ }
393
+ }
394
+ }
395
+
396
+ export function clearStylesScss(options: any): Rule {
397
+ return chain([
398
+ messageInfoRule(`Datei "styles.scss" wird aktualisiert...`),
399
+ (tree: Tree, context: SchematicContext) => {
400
+ const filePath = (options.path ? options.path : '') + '/src/styles.scss';
401
+ const content = (tree.read(filePath) as Buffer).toString();
402
+ if (content) {
403
+ let modifiedContent = '';
404
+
405
+ const lines = content.split('\n');
406
+ if (lines) {
407
+ lines.forEach(line => {
408
+ // Zeilen mit dem folgenden Inhalt werden nicht übernommen.
409
+ if (line.indexOf('@fortawesome/fontawesome-free') < 0 &&
410
+ line.indexOf('material-design-icons.css') < 0 &&
411
+ line.indexOf('@angular/material/theming') < 0 &&
412
+ line.indexOf('theming/luxtheme') < 0 &&
413
+ line.indexOf('mat-core()') < 0 &&
414
+ line.indexOf('angular-material-theme($lux-theme)') < 0
415
+ ) {
416
+ modifiedContent += line + '\n';
417
+ }
418
+ });
419
+
420
+ if (content !== modifiedContent) {
421
+ tree.overwrite(filePath, modifiedContent);
422
+ logInfo(`Einträge des alten LUX-Themes entfernt.`);
423
+ }
424
+ }
425
+ }
426
+ },
427
+ messageSuccessRule(`\`Datei "styles.scss" wurde aktualisiert.`)
428
+ ]);
429
+ }
430
+
431
+ export function addThemeAssets(options: any): Rule {
432
+ return (tree: Tree, context: SchematicContext) => {
433
+ const filePath = '/angular.json';
434
+ const value = { "glob": "*.css", "input": "./node_modules/@ihk-gfi/lux-components-theme/prebuilt-themes", "output": "./assets/themes" };
435
+
436
+ let contentAsNode = readJson(tree, filePath);
437
+ const testAssetsNode = findNodeAtLocation(contentAsNode, ['projects', options.project, 'architect', 'test', 'options', 'assets']);
438
+ if (testAssetsNode) {
439
+ const angularJson = readJsonAsString(tree, filePath);
440
+ const edits = modify(angularJson, ['projects', options.project, 'architect', 'test', 'options', 'assets', 0], value, { formattingOptions: jsonFormattingOptions, isArrayInsertion: true });
441
+ if (edits) {
442
+ tree.overwrite(
443
+ filePath,
444
+ applyEdits(angularJson, edits)
445
+ );
446
+ logInfo(`Neues LUX-Theme im Assets-Abschnitt (test) hinzugefügt.`);
447
+ }
448
+ }
449
+
450
+ contentAsNode = readJson(tree, filePath);
451
+ const buildAssetsNode = findNodeAtLocation(contentAsNode, ['projects', options.project, 'architect', 'build', 'options', 'assets']);
452
+ if (buildAssetsNode) {
453
+ const angularJson = readJsonAsString(tree, filePath);
454
+ const edits = modify(angularJson, ['projects', options.project, 'architect', 'build', 'options', 'assets', 0], value, { formattingOptions: jsonFormattingOptions, isArrayInsertion: true });
455
+ if (edits) {
456
+ tree.overwrite(
457
+ filePath,
458
+ applyEdits(angularJson, edits)
459
+ );
460
+ logInfo(`Neues LUX-Theme im Assets-Abschnitt (build) hinzugefügt.`);
461
+ }
462
+ }
463
+ }
464
+ }
465
+
466
+ export function removeThemeAssets(options: any): Rule {
467
+ return (tree: Tree, context: SchematicContext) => {
468
+ const filePath = '/angular.json';
469
+ const value = "src/theming/luxtheme.scss";
470
+
471
+ let contentAsNode = readJson(tree, filePath);
472
+ const testAssetsNode = findNodeAtLocation(contentAsNode, ['projects', options.project, 'architect', 'test', 'options', 'styles']);
473
+ if (testAssetsNode && testAssetsNode.children) {
474
+ const assetArray = testAssetsNode.children as Array<any>;
475
+ const index = assetArray.findIndex(item => item.value === value);
476
+
477
+ if (index >= 0) {
478
+ const angularJson = readJsonAsString(tree, filePath);
479
+ const edits = modify(angularJson, ['projects', options.project, 'architect', 'test', 'options', 'styles', index], void 0, { formattingOptions: jsonFormattingOptions });
480
+ if (edits) {
481
+ tree.overwrite(
482
+ filePath,
483
+ applyEdits(angularJson, edits)
484
+ );
485
+ logInfo(`Altes LUX-Theme aus dem Assets-Abschnitt (test) entfernt.`);
486
+ }
487
+ }
488
+ }
489
+
490
+ contentAsNode = readJson(tree, filePath);
491
+ const buildAssetsNode = findNodeAtLocation(contentAsNode, ['projects', options.project, 'architect', 'build', 'options', 'styles']);
492
+ if (buildAssetsNode && buildAssetsNode.children) {
493
+ const assetArray = buildAssetsNode.children as Array<any>;
494
+ const index = assetArray.findIndex(item => item.value === value);
495
+
496
+ if (index >= 0) {
497
+ const angularJson = readJsonAsString(tree, filePath);
498
+ const edits = modify(angularJson, ['projects', options.project, 'architect', 'build', 'options', 'styles', index], void 0, { formattingOptions: jsonFormattingOptions });
499
+ if (edits) {
500
+ tree.overwrite(
501
+ filePath,
502
+ applyEdits(angularJson, edits)
503
+ );
504
+ logInfo(`Altes LUX-Theme aus dem Assets-Abschnitt (build) entfernt.`);
505
+ }
506
+ }
507
+ }
508
+ }
509
+ }
510
+
511
+ export function updateAppComponent(options: any): Rule {
512
+ return chain([
513
+ messageInfoRule(`AppComponent wird aktualisiert...`),
514
+ (tree: Tree, context: SchematicContext) => {
515
+ const filePath = (options.path ? options.path : '') + '/src/app/app.component.ts';
516
+ addImport(tree, filePath, '@ihk-gfi/lux-components', 'LuxThemeService');
517
+ addConstructorParameter(tree, filePath, 'private themeService: LuxThemeService');
518
+ addConstructorContent(tree, filePath, 'themeService.loadTheme();', true);
519
+ },
520
+ messageSuccessRule(`AppComponent wurde aktualisiert.`)
521
+ ]);
522
+ }
523
+
524
+ function updateConfigGenerateLuxTagIds(tree: Tree, filePath: string) {
525
+ const content = (tree.read(filePath) as Buffer).toString();
526
+ const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
527
+ const sourceFile = ts.createSourceFile(`${ fileName }`, content, ts.ScriptTarget.Latest, true);
528
+ const nodes = getSourceNodes(sourceFile);
529
+
530
+ const identifierNode = nodes.find(n => n.kind === ts.SyntaxKind.Identifier && n.getText() === 'luxComponentsConfig');
531
+ if (identifierNode) {
532
+ const objectNode = identifierNode.parent.getChildren().find(n => n.kind === ts.SyntaxKind.ObjectLiteralExpression);
533
+ if (objectNode) {
534
+ const syntaxListNode = objectNode.getChildren().find(n => n.kind === ts.SyntaxKind.SyntaxList);
535
+ if (syntaxListNode) {
536
+ const propertyAssignmentNodes = syntaxListNode.getChildren().filter(n => n.kind === ts.SyntaxKind.PropertyAssignment);
537
+ if (propertyAssignmentNodes) {
538
+ propertyAssignmentNodes.forEach(assignment => {
539
+ const propertyIdentifierNode = assignment.getChildren().find(n => n.kind === ts.SyntaxKind.Identifier);
540
+ if (propertyIdentifierNode && propertyIdentifierNode.getText() === 'generateLuxTagIds') {
541
+ const updateRecorder = tree.beginUpdate(filePath);
542
+ updateRecorder.remove(assignment.pos, assignment.end - assignment.pos);
543
+ updateRecorder.insertLeft(assignment.pos, '\n generateLuxTagIds: environment.generateLuxTagIds');
544
+ if (!content.match(/import.*\{.*environment.*\}.*from.*/g)) {
545
+ updateRecorder.insertLeft(0, "import { environment } from '../environments/environment';\n");
546
+ }
547
+ tree.commitUpdate(updateRecorder);
548
+ logInfo(`In der Konfiguration wurde der Wert "generateLuxTagIds: environment.generateLuxTagIds" eingetragen.`);
549
+ }
550
+ });
551
+ }
552
+ }
553
+ }
554
+ }
555
+ }
556
+
557
+ function updateConfigLabelConfiguration(tree: Tree, filePath: string) {
558
+ const content = (tree.read(filePath) as Buffer).toString();
559
+ const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
560
+ const sourceFile = ts.createSourceFile(`${ fileName }`, content, ts.ScriptTarget.Latest, true);
561
+ const nodes = getSourceNodes(sourceFile);
562
+
563
+ const identifierNode = nodes.find(n => n.kind === ts.SyntaxKind.Identifier && n.getText() === 'luxComponentsConfig');
564
+ if (identifierNode) {
565
+ const objectNode = identifierNode.parent.getChildren().find(n => n.kind === ts.SyntaxKind.ObjectLiteralExpression);
566
+ if (objectNode) {
567
+ const syntaxListNode = objectNode.getChildren().find(n => n.kind === ts.SyntaxKind.SyntaxList);
568
+ if (syntaxListNode) {
569
+ const propertyAssignmentNodes = syntaxListNode.getChildren().filter(n => n.kind === ts.SyntaxKind.PropertyAssignment);
570
+ if (propertyAssignmentNodes) {
571
+ propertyAssignmentNodes.forEach(assignment => {
572
+ const propertyIdentifierNode = assignment.getChildren().find(n => n.kind === ts.SyntaxKind.Identifier);
573
+ if (propertyIdentifierNode && propertyIdentifierNode.getText() === 'labelConfiguration') {
574
+ const prevSibling = getPrevSibling(assignment, ts.SyntaxKind.SyntaxList);
575
+ const nextSibling = getNextSibling(assignment, ts.SyntaxKind.SyntaxList);
576
+ const updateRecorder = tree.beginUpdate(filePath);
577
+ if (nextSibling) {
578
+ updateRecorder.remove(assignment.pos, nextSibling.end - assignment.pos);
579
+ } else {
580
+ if (prevSibling) {
581
+ updateRecorder.remove(prevSibling.pos, assignment.end - assignment.pos);
582
+ } else {
583
+ updateRecorder.remove(assignment.pos, assignment.end - assignment.pos);
584
+ }
585
+ }
586
+ logInfo(`Aus der Konfiguration wurde die Property "labelConfiguration" entfernt, damit der Default verwendet wird.`)
587
+ tree.commitUpdate(updateRecorder);
588
+ }
589
+ });
590
+ }
591
+ }
592
+ }
593
+ }
594
+ }
595
+
596
+ function deleteDisplayBindingDebugHint(tree: Tree, filePath: string) {
597
+ const content = (tree.read(filePath) as Buffer).toString();
598
+ const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
599
+ const sourceFile = ts.createSourceFile(`${ fileName }`, content, ts.ScriptTarget.Latest, true);
600
+ const nodes = getSourceNodes(sourceFile);
601
+
602
+ const identifierNode = nodes.find(n => n.kind === ts.SyntaxKind.Identifier && n.getText() === 'luxComponentsConfig');
603
+ if (identifierNode) {
604
+ const objectNode = identifierNode.parent.getChildren().find(n => n.kind === ts.SyntaxKind.ObjectLiteralExpression);
605
+ if (objectNode) {
606
+ const syntaxListNode = objectNode.getChildren().find(n => n.kind === ts.SyntaxKind.SyntaxList);
607
+ if (syntaxListNode) {
608
+ const propertyAssignmentNodes = syntaxListNode
609
+ .getChildren()
610
+ .filter((n) => n.kind === ts.SyntaxKind.PropertyAssignment);
611
+ if (propertyAssignmentNodes) {
612
+ propertyAssignmentNodes.forEach((assignment) => {
613
+ const propertyIdentifierNode = assignment.getChildren().find((n) => n.kind === ts.SyntaxKind.Identifier);
614
+ if (propertyIdentifierNode && propertyIdentifierNode.getText() === 'displayBindingDebugHint') {
615
+ const prevSibling = getPrevSibling(assignment, ts.SyntaxKind.SyntaxList);
616
+ const nextSibling = getNextSibling(assignment, ts.SyntaxKind.SyntaxList);
617
+ const updateRecorder = tree.beginUpdate(filePath);
618
+ if (nextSibling) {
619
+ updateRecorder.remove(assignment.pos, nextSibling.end - assignment.pos);
620
+ } else {
621
+ if (prevSibling) {
622
+ updateRecorder.remove(prevSibling.pos, assignment.end - prevSibling.pos);
623
+ } else {
624
+ updateRecorder.remove(assignment.pos, assignment.end - assignment.pos);
625
+ }
626
+ }
627
+ logInfo(`Aus der Konfiguration wurde die Property "displayBindingDebugHint" entfernt.`)
628
+ tree.commitUpdate(updateRecorder);
629
+ }
630
+ });
631
+ }
632
+ }
633
+ }
634
+ }
635
+ }
636
+
637
+ function updateConfiglookupServiceUrl(tree: Tree, filePath: string) {
638
+ const content = (tree.read(filePath) as Buffer).toString();
639
+ const fileName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
640
+ const sourceFile = ts.createSourceFile(`${ fileName }`, content, ts.ScriptTarget.Latest, true);
641
+ const nodes = getSourceNodes(sourceFile);
642
+
643
+ const identifierNode = nodes.find(n => n.kind === ts.SyntaxKind.Identifier && n.getText() === 'luxComponentsConfig');
644
+ if (identifierNode) {
645
+ const objectNode = identifierNode.parent.getChildren().find(n => n.kind === ts.SyntaxKind.ObjectLiteralExpression);
646
+ if (objectNode) {
647
+ const syntaxListNode = objectNode.getChildren().find(n => n.kind === ts.SyntaxKind.SyntaxList);
648
+ if (syntaxListNode) {
649
+ const propertyAssignmentNodes = syntaxListNode
650
+ .getChildren()
651
+ .filter((n) => n.kind === ts.SyntaxKind.PropertyAssignment);
652
+ if (propertyAssignmentNodes) {
653
+ propertyAssignmentNodes.forEach((assignment) => {
654
+ const propertyIdentifierNode = assignment.getChildren().find((n) => n.kind === ts.SyntaxKind.Identifier);
655
+ const propertyStringNode = assignment.getChildren().find((n) => n.kind === ts.SyntaxKind.StringLiteral);
656
+ if (
657
+ propertyIdentifierNode && propertyIdentifierNode.getText() === 'lookupServiceUrl' &&
658
+ propertyStringNode && (propertyStringNode.getText() === "'/lookup/'" || propertyStringNode.getText() === '"/lookup/"')
659
+ ) {
660
+ const prevSibling = getPrevSibling(assignment, ts.SyntaxKind.SyntaxList);
661
+ const nextSibling = getNextSibling(assignment, ts.SyntaxKind.SyntaxList);
662
+ const updateRecorder = tree.beginUpdate(filePath);
663
+ if (nextSibling) {
664
+ updateRecorder.remove(assignment.pos, nextSibling.end - assignment.pos);
665
+ } else {
666
+ if (prevSibling) {
667
+ updateRecorder.remove(prevSibling.pos, assignment.end - prevSibling.pos);
668
+ } else {
669
+ updateRecorder.remove(assignment.pos, assignment.end - assignment.pos);
670
+ }
671
+ }
672
+ logInfo(`Aus der Konfiguration wurde die Property "lookupServiceUrl" entfernt. Der Wert entspricht dem Defaultwert.`)
673
+ tree.commitUpdate(updateRecorder);
674
+ }
675
+ });
676
+ }
677
+ }
678
+ }
679
+ }
680
+ }
681
+
682
+ export function updateAppModule(options: any): Rule {
683
+ return chain([
684
+ messageInfoRule(`AppModule wird aktualisiert...`),
685
+ (tree: Tree, context: SchematicContext) => {
686
+ const filePath = (options.path ? options.path : '') + `/src/app/app.module.ts`;
687
+
688
+ updateConfigGenerateLuxTagIds(tree, filePath);
689
+ updateConfigLabelConfiguration(tree, filePath);
690
+ updateConfiglookupServiceUrl(tree, filePath);
691
+ deleteDisplayBindingDebugHint(tree, filePath);
692
+
693
+ removeImport(tree, filePath, '@ihk-gfi/lux-components', 'LuxAppFooterButtonService');
694
+ removeImport(tree, filePath, '@ihk-gfi/lux-components','LuxAppFooterLinkService');
695
+ removeImport(tree, filePath, '@ihk-gfi/lux-components','LuxSnackbarService');
696
+ removeImport(tree, filePath, '@ihk-gfi/lux-components','LuxErrorService');
697
+ removeImport(tree, filePath, '@ihk-gfi/lux-components','LuxMasterDetailMobileHelperService');
698
+ removeImport(tree, filePath, '@ihk-gfi/lux-components','LuxStepperHelperService');
699
+ removeImport(tree, filePath, '@ihk-gfi/lux-components','LuxConsoleService');
700
+
701
+ removeProvider(tree, filePath, 'LuxAppFooterButtonService');
702
+ removeProvider(tree, filePath, 'LuxAppFooterLinkService');
703
+ removeProvider(tree, filePath, 'LuxSnackbarService');
704
+ removeProvider(tree, filePath, 'LuxErrorService');
705
+ removeProvider(tree, filePath, 'LuxMasterDetailMobileHelperService');
706
+ removeProvider(tree, filePath, 'LuxStepperHelperService');
707
+ removeProvider(tree, filePath, 'LuxConsoleService');
708
+ },
709
+ messageSuccessRule(`AppModule wurde aktualisiert.`)
710
+ ]);
711
+ }
712
+