@ihk-gfi/lux-components-update 11.13.0 → 13.0.1
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 +2 -4
- package/package.json +14 -17
- package/src/add-lux-components/files/app/app.component.html +1 -1
- package/src/add-lux-components/files/app/app.component.ts +4 -1
- package/src/add-lux-components/files/locale/messages.en.xlf +489 -235
- package/src/add-lux-components/files/locale/messages.xlf +451 -218
- package/src/add-lux-components/files/scripts/.browserslistrc +10 -7
- package/src/add-lux-components/files/src/index.html +31 -0
- package/src/add-lux-components/index.js +151 -78
- package/src/add-lux-components/index.js.map +1 -1
- package/src/add-lux-components/index.ts +141 -66
- package/src/add-lux-components/index_spec.js +4 -4
- package/src/add-lux-components/index_spec.js.map +1 -1
- package/src/add-lux-components/index_spec.ts +1 -1
- package/src/add-lux-components/schema.json +1 -1
- package/src/collection.json +8 -88
- package/src/update-dependencies/index.d.ts +1 -1
- package/src/update-dependencies/index.js +82 -65
- package/src/update-dependencies/index.js.map +1 -1
- package/src/update-dependencies/index.ts +112 -95
- package/src/update-dependencies/schema.json +1 -1
- package/src/update-en-messages/index.d.ts +2 -0
- package/src/update-en-messages/index.js +75 -0
- package/src/update-en-messages/index.js.map +1 -0
- package/src/update-en-messages/index.ts +78 -0
- package/src/{update110100 → update-en-messages}/schema.json +3 -3
- package/src/updates/update130000/files/root/.browserslistrc +20 -0
- package/src/updates/update130000/index.d.ts +27 -0
- package/src/updates/update130000/index.js +296 -0
- package/src/updates/update130000/index.js.map +1 -0
- package/src/updates/update130000/index.ts +346 -0
- package/src/{migrate-to-eslint → updates/update130000}/index_spec.d.ts +0 -0
- package/src/updates/update130000/index_spec.js +574 -0
- package/src/updates/update130000/index_spec.js.map +1 -0
- package/src/updates/update130000/index_spec.ts +665 -0
- package/src/{update → updates/update130000}/schema.json +1 -1
- package/src/utility/dependencies.js +16 -14
- package/src/utility/dependencies.js.map +1 -1
- package/src/utility/dependencies.ts +6 -4
- package/src/utility/files.d.ts +5 -1
- package/src/utility/files.js +27 -16
- package/src/utility/files.js.map +1 -1
- package/src/utility/files.ts +16 -3
- package/src/utility/html.js +88 -25
- package/src/utility/html.js.map +1 -1
- package/src/utility/html.ts +105 -29
- package/src/{migrate-to-webcomponent/index_spec.d.ts → utility/html_spec.d.ts} +0 -0
- package/src/utility/html_spec.js +560 -0
- package/src/utility/html_spec.js.map +1 -0
- package/src/utility/html_spec.ts +575 -0
- package/src/utility/json.d.ts +46 -1
- package/src/utility/json.js +174 -4
- package/src/utility/json.js.map +1 -1
- package/src/utility/json.ts +198 -3
- package/src/{update/index_spec.d.ts → utility/json_spec.d.ts} +0 -0
- package/src/utility/json_spec.js +326 -0
- package/src/utility/json_spec.js.map +1 -0
- package/src/utility/json_spec.ts +376 -0
- package/src/utility/typescript.js +16 -16
- package/src/utility/typescript.js.map +1 -1
- package/src/utility/typescript_spec.js +36 -36
- package/src/utility/typescript_spec.js.map +1 -1
- package/src/utility/util.d.ts +2 -2
- package/src/utility/util.js +16 -14
- package/src/utility/util.js.map +1 -1
- package/src/utility/util.ts +7 -5
- package/src/utility/validation.js +11 -11
- package/src/utility/validation.js.map +1 -1
- package/src/migrate-to-eslint/files/.eslintrc.json +0 -68
- package/src/migrate-to-eslint/files/.prettierrc +0 -25
- package/src/migrate-to-eslint/index.d.ts +0 -6
- package/src/migrate-to-eslint/index.js +0 -149
- package/src/migrate-to-eslint/index.js.map +0 -1
- package/src/migrate-to-eslint/index.ts +0 -181
- package/src/migrate-to-eslint/index_spec.js +0 -129
- package/src/migrate-to-eslint/index_spec.js.map +0 -1
- package/src/migrate-to-eslint/index_spec.ts +0 -152
- package/src/migrate-to-eslint/schema.json +0 -23
- package/src/migrate-to-webcomponent/index.d.ts +0 -10
- package/src/migrate-to-webcomponent/index.js +0 -278
- package/src/migrate-to-webcomponent/index.js.map +0 -1
- package/src/migrate-to-webcomponent/index.ts +0 -331
- package/src/migrate-to-webcomponent/index_spec.js +0 -580
- package/src/migrate-to-webcomponent/index_spec.js.map +0 -1
- package/src/migrate-to-webcomponent/index_spec.ts +0 -703
- package/src/migrate-to-webcomponent/schema.json +0 -23
- package/src/update/files/locale/messages.en.xlf +0 -940
- package/src/update/files/locale/messages.xlf +0 -815
- package/src/update/files/scripts/move-de-files.js +0 -15
- package/src/update/index.d.ts +0 -23
- package/src/update/index.js +0 -635
- package/src/update/index.js.map +0 -1
- package/src/update/index.ts +0 -712
- package/src/update/index_spec.js +0 -984
- package/src/update/index_spec.js.map +0 -1
- package/src/update/index_spec.ts +0 -1139
- package/src/update110001/index.d.ts +0 -2
- package/src/update110001/index.js +0 -42
- package/src/update110001/index.js.map +0 -1
- package/src/update110001/index.ts +0 -40
- package/src/update110001/index_spec.d.ts +0 -1
- package/src/update110001/index_spec.js +0 -67
- package/src/update110001/index_spec.js.map +0 -1
- package/src/update110001/index_spec.ts +0 -72
- package/src/update110001/schema.json +0 -23
- package/src/update110100/index.d.ts +0 -2
- package/src/update110100/index.js +0 -27
- package/src/update110100/index.js.map +0 -1
- package/src/update110100/index.ts +0 -24
- package/src/update110100/index_spec.d.ts +0 -1
- package/src/update110100/index_spec.js +0 -69
- package/src/update110100/index_spec.js.map +0 -1
- package/src/update110100/index_spec.ts +0 -73
- package/src/update110101/index.d.ts +0 -2
- package/src/update110101/index.js +0 -24
- package/src/update110101/index.js.map +0 -1
- package/src/update110101/index.ts +0 -21
- package/src/update110101/index_spec.d.ts +0 -1
- package/src/update110101/index_spec.js +0 -65
- package/src/update110101/index_spec.js.map +0 -1
- package/src/update110101/index_spec.ts +0 -69
- package/src/update110101/schema.json +0 -23
- package/src/update110200/index.d.ts +0 -2
- package/src/update110200/index.js +0 -24
- package/src/update110200/index.js.map +0 -1
- package/src/update110200/index.ts +0 -21
- package/src/update110200/index_spec.d.ts +0 -1
- package/src/update110200/index_spec.js +0 -65
- package/src/update110200/index_spec.js.map +0 -1
- package/src/update110200/index_spec.ts +0 -69
- package/src/update110200/schema.json +0 -23
- package/src/update110300/index.d.ts +0 -2
- package/src/update110300/index.js +0 -133
- package/src/update110300/index.js.map +0 -1
- package/src/update110300/index.ts +0 -148
- package/src/update110300/index_spec.d.ts +0 -1
- package/src/update110300/index_spec.js +0 -121
- package/src/update110300/index_spec.js.map +0 -1
- package/src/update110300/index_spec.ts +0 -139
- package/src/update110300/schema.json +0 -23
- package/src/update110400/index.d.ts +0 -2
- package/src/update110400/index.js +0 -28
- package/src/update110400/index.js.map +0 -1
- package/src/update110400/index.ts +0 -28
- package/src/update110400/index_spec.d.ts +0 -1
- package/src/update110400/index_spec.js +0 -66
- package/src/update110400/index_spec.js.map +0 -1
- package/src/update110400/index_spec.ts +0 -70
- package/src/update110400/schema.json +0 -23
- package/src/update110500/index.d.ts +0 -2
- package/src/update110500/index.js +0 -28
- package/src/update110500/index.js.map +0 -1
- package/src/update110500/index.ts +0 -28
- package/src/update110500/index_spec.d.ts +0 -1
- package/src/update110500/index_spec.js +0 -66
- package/src/update110500/index_spec.js.map +0 -1
- package/src/update110500/index_spec.ts +0 -70
- package/src/update110500/schema.json +0 -23
- package/src/update110600/index.d.ts +0 -2
- package/src/update110600/index.js +0 -28
- package/src/update110600/index.js.map +0 -1
- package/src/update110600/index.ts +0 -28
- package/src/update110600/index_spec.d.ts +0 -1
- package/src/update110600/index_spec.js +0 -66
- package/src/update110600/index_spec.js.map +0 -1
- package/src/update110600/index_spec.ts +0 -70
- package/src/update110600/schema.json +0 -23
- package/src/update110700/index.d.ts +0 -2
- package/src/update110700/index.js +0 -45
- package/src/update110700/index.js.map +0 -1
- package/src/update110700/index.ts +0 -47
- package/src/update110700/index_spec.d.ts +0 -1
- package/src/update110700/index_spec.js +0 -108
- package/src/update110700/index_spec.js.map +0 -1
- package/src/update110700/index_spec.ts +0 -122
- package/src/update110700/schema.json +0 -23
- package/src/update110800/index.d.ts +0 -2
- package/src/update110800/index.js +0 -32
- package/src/update110800/index.js.map +0 -1
- package/src/update110800/index.ts +0 -33
- package/src/update110800/index_spec.d.ts +0 -1
- package/src/update110800/index_spec.js +0 -70
- package/src/update110800/index_spec.js.map +0 -1
- package/src/update110800/index_spec.ts +0 -75
- package/src/update110800/schema.json +0 -23
- package/src/update110900/index.d.ts +0 -4
- package/src/update110900/index.js +0 -111
- package/src/update110900/index.js.map +0 -1
- package/src/update110900/index.ts +0 -123
- package/src/update110900/index_spec.d.ts +0 -1
- package/src/update110900/index_spec.js +0 -311
- package/src/update110900/index_spec.js.map +0 -1
- package/src/update110900/index_spec.ts +0 -341
- package/src/update110900/schema.json +0 -23
- package/src/update111000/index.d.ts +0 -2
- package/src/update111000/index.js +0 -27
- package/src/update111000/index.js.map +0 -1
- package/src/update111000/index.ts +0 -27
- package/src/update111000/index_spec.d.ts +0 -1
- package/src/update111000/index_spec.js +0 -65
- package/src/update111000/index_spec.js.map +0 -1
- package/src/update111000/index_spec.ts +0 -70
- package/src/update111000/schema.json +0 -23
- package/src/update111100/index.d.ts +0 -2
- package/src/update111100/index.js +0 -389
- package/src/update111100/index.js.map +0 -1
- package/src/update111100/index.ts +0 -405
- package/src/update111100/index_spec.d.ts +0 -1
- package/src/update111100/index_spec.js +0 -66
- package/src/update111100/index_spec.js.map +0 -1
- package/src/update111100/index_spec.ts +0 -70
- package/src/update111100/schema.json +0 -23
- package/src/update111200/index.d.ts +0 -2
- package/src/update111200/index.js +0 -59
- package/src/update111200/index.js.map +0 -1
- package/src/update111200/index.ts +0 -75
- package/src/update111200/index_spec.d.ts +0 -1
- package/src/update111200/index_spec.js +0 -67
- package/src/update111200/index_spec.js.map +0 -1
- package/src/update111200/index_spec.ts +0 -71
- package/src/update111200/schema.json +0 -23
- package/src/update111300/index.d.ts +0 -2
- package/src/update111300/index.js +0 -27
- package/src/update111300/index.js.map +0 -1
- package/src/update111300/index.ts +0 -27
- package/src/update111300/index_spec.d.ts +0 -1
- package/src/update111300/index_spec.js +0 -65
- package/src/update111300/index_spec.js.map +0 -1
- package/src/update111300/index_spec.ts +0 -69
- package/src/update111300/schema.json +0 -23
package/src/utility/json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appendScript = exports.readJsonAsString = exports.readJson = exports.jsonFormattingOptions = void 0;
|
|
3
|
+
exports.removeJsonNode = exports.findStringIndexInArray = exports.findObjectPropertyInArray = exports.findObjectIndexInArray = exports.updateJsonArray = exports.updateJsonValue = exports.appendScript = exports.readJsonAsString = exports.readJson = exports.jsonFormattingOptions = void 0;
|
|
4
4
|
const jsonc_parser_1 = require("jsonc-parser");
|
|
5
5
|
const logging_1 = require("./logging");
|
|
6
6
|
exports.jsonFormattingOptions = {
|
|
@@ -17,10 +17,10 @@ exports.jsonFormattingOptions = {
|
|
|
17
17
|
function readJson(tree, filePath) {
|
|
18
18
|
const buffer = tree.read(filePath);
|
|
19
19
|
if (buffer === null) {
|
|
20
|
-
throw logging_1.formattedSchematicsException(`Konnte die Datei ${filePath} nicht lesen.`);
|
|
20
|
+
throw (0, logging_1.formattedSchematicsException)(`Konnte die Datei ${filePath} nicht lesen.`);
|
|
21
21
|
}
|
|
22
22
|
const content = buffer.toString();
|
|
23
|
-
let result = jsonc_parser_1.parseTree(content);
|
|
23
|
+
let result = (0, jsonc_parser_1.parseTree)(content);
|
|
24
24
|
return result;
|
|
25
25
|
}
|
|
26
26
|
exports.readJson = readJson;
|
|
@@ -33,7 +33,7 @@ exports.readJson = readJson;
|
|
|
33
33
|
function readJsonAsString(tree, filePath) {
|
|
34
34
|
const buffer = tree.read(filePath);
|
|
35
35
|
if (buffer === null) {
|
|
36
|
-
throw logging_1.formattedSchematicsException(`Konnte die Datei ${filePath} nicht lesen.`);
|
|
36
|
+
throw (0, logging_1.formattedSchematicsException)(`Konnte die Datei ${filePath} nicht lesen.`);
|
|
37
37
|
}
|
|
38
38
|
return buffer.toString();
|
|
39
39
|
}
|
|
@@ -67,4 +67,174 @@ function appendScript(script, part, index) {
|
|
|
67
67
|
return newSkript;
|
|
68
68
|
}
|
|
69
69
|
exports.appendScript = appendScript;
|
|
70
|
+
function updateJsonValue(options, filePath, jsonPath, value, onlyUpdate = false) {
|
|
71
|
+
return (tree, context) => {
|
|
72
|
+
const found = (0, jsonc_parser_1.findNodeAtLocation)(readJson(tree, filePath), jsonPath);
|
|
73
|
+
if (!onlyUpdate || (onlyUpdate && found)) {
|
|
74
|
+
const jsonFile = readJsonAsString(tree, filePath);
|
|
75
|
+
const edits = (0, jsonc_parser_1.modify)(jsonFile, jsonPath, value, { formattingOptions: exports.jsonFormattingOptions, isArrayInsertion: false });
|
|
76
|
+
if (edits) {
|
|
77
|
+
tree.overwrite(filePath, (0, jsonc_parser_1.applyEdits)(jsonFile, edits));
|
|
78
|
+
(0, logging_1.logInfo)(`"${JSON.stringify(value)}" an der Stelle "${jsonPath.join('.')}" eingetragen.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
exports.updateJsonValue = updateJsonValue;
|
|
84
|
+
function updateJsonArray(options, filePath, jsonPath, value, onlyUpdate = false, findFn) {
|
|
85
|
+
return (tree, context) => {
|
|
86
|
+
// Gibt es bereits eine passende Stelle?
|
|
87
|
+
let foundIndex = -1;
|
|
88
|
+
let childrenCount = -1;
|
|
89
|
+
const node = (0, jsonc_parser_1.findNodeAtLocation)(readJson(tree, filePath), jsonPath);
|
|
90
|
+
if (node && node.children) {
|
|
91
|
+
childrenCount = node.children.length;
|
|
92
|
+
if (!findFn && typeof value === 'string') {
|
|
93
|
+
// Sollte der Wert bereits im Array enthalten sein,
|
|
94
|
+
// kann man an dieser Stelle abbrechen und die
|
|
95
|
+
// Methode verlassen.
|
|
96
|
+
foundIndex = findStringIndexInArray(node, value);
|
|
97
|
+
if (foundIndex >= 0) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (findFn) {
|
|
102
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
103
|
+
if (findFn(node.children[i])) {
|
|
104
|
+
foundIndex = i;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!onlyUpdate || (onlyUpdate && foundIndex >= 0)) {
|
|
111
|
+
const jsonFile = readJsonAsString(tree, filePath);
|
|
112
|
+
const edits = (0, jsonc_parser_1.modify)(jsonFile, [...jsonPath, foundIndex >= 0 ? foundIndex : childrenCount !== -1 ? childrenCount : 0], value, { formattingOptions: exports.jsonFormattingOptions, isArrayInsertion: foundIndex === -1 });
|
|
113
|
+
if (edits) {
|
|
114
|
+
tree.overwrite(filePath, (0, jsonc_parser_1.applyEdits)(jsonFile, edits));
|
|
115
|
+
(0, logging_1.logInfo)(`"${JSON.stringify(value)}" an der Stelle "${jsonPath.join('.')}" hinzugefügt.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
exports.updateJsonArray = updateJsonArray;
|
|
121
|
+
/**
|
|
122
|
+
* Diese Methode liefert den Index im Array des Objekts mit der übergebenen Property zurück.
|
|
123
|
+
*
|
|
124
|
+
* Beispiel: findObjectIndexInArray(node, 'glob', '*.css') = 1
|
|
125
|
+
* ```json
|
|
126
|
+
* 'assets': [
|
|
127
|
+
* 'src/assets',
|
|
128
|
+
* {
|
|
129
|
+
* 'glob': '*.css',
|
|
130
|
+
* 'input': './node_modules/@ihk-gfi/lux-components-theme/prebuilt-themes',
|
|
131
|
+
* 'output': './assets/themes'
|
|
132
|
+
* },
|
|
133
|
+
* 'src/favicon.ico',
|
|
134
|
+
* ]
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @param arrayNode Ein Konten, der ein Array als Wert hat.
|
|
138
|
+
* @param propertyName Ein Propertyname (z.B. glob).
|
|
139
|
+
* @param propertyValue Ein Propertywert (z.B. *.css).
|
|
140
|
+
*/
|
|
141
|
+
function findObjectIndexInArray(arrayNode, propertyName, propertyValue) {
|
|
142
|
+
var _a;
|
|
143
|
+
let arrayIndex = -1;
|
|
144
|
+
if (arrayNode.children) {
|
|
145
|
+
for (let i = 0; i < arrayNode.children.length; i++) {
|
|
146
|
+
const assetChild = arrayNode.children[i];
|
|
147
|
+
if (assetChild.type === 'object' && assetChild.children && assetChild.children.length > 0) {
|
|
148
|
+
const assetObjectChildren = assetChild.children;
|
|
149
|
+
if (assetObjectChildren) {
|
|
150
|
+
for (let j = 0; j < assetObjectChildren.length; j++) {
|
|
151
|
+
if (assetObjectChildren[j].type === 'property') {
|
|
152
|
+
const propertyChildren = (_a = assetObjectChildren[j].children) !== null && _a !== void 0 ? _a : [];
|
|
153
|
+
if (propertyChildren.length > 1 &&
|
|
154
|
+
propertyChildren[0].value === propertyName &&
|
|
155
|
+
propertyChildren[1].value === propertyValue) {
|
|
156
|
+
arrayIndex = i;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (assetChild.type === 'string' && assetChild.value === propertyValue) {
|
|
164
|
+
arrayIndex = i;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return arrayIndex;
|
|
170
|
+
}
|
|
171
|
+
exports.findObjectIndexInArray = findObjectIndexInArray;
|
|
172
|
+
function findObjectPropertyInArray(node, propertyName, propertyValue) {
|
|
173
|
+
var _a;
|
|
174
|
+
let found = false;
|
|
175
|
+
if (node.type === 'object' && node.children && node.children.length > 0) {
|
|
176
|
+
const assetObjectChildren = node.children;
|
|
177
|
+
if (assetObjectChildren) {
|
|
178
|
+
for (let j = 0; j < assetObjectChildren.length; j++) {
|
|
179
|
+
if (assetObjectChildren[j].type === 'property') {
|
|
180
|
+
const propertyChildren = (_a = assetObjectChildren[j].children) !== null && _a !== void 0 ? _a : [];
|
|
181
|
+
if (propertyChildren.length > 1 &&
|
|
182
|
+
propertyChildren[0].value === propertyName &&
|
|
183
|
+
propertyChildren[1].value === propertyValue) {
|
|
184
|
+
found = true;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return found;
|
|
192
|
+
}
|
|
193
|
+
exports.findObjectPropertyInArray = findObjectPropertyInArray;
|
|
194
|
+
/**
|
|
195
|
+
* Diese Methode liefert den Index im Array des Werts zurück.
|
|
196
|
+
*
|
|
197
|
+
* Beispiel: findStringIndexInArray(node, 'src/favicon.ico') = 2
|
|
198
|
+
* ```json
|
|
199
|
+
* 'assets': [
|
|
200
|
+
* 'src/assets',
|
|
201
|
+
* {
|
|
202
|
+
* 'glob': '*.css',
|
|
203
|
+
* 'input': './node_modules/@ihk-gfi/lux-components-theme/prebuilt-themes',
|
|
204
|
+
* 'output': './assets/themes'
|
|
205
|
+
* },
|
|
206
|
+
* 'src/favicon.ico',
|
|
207
|
+
* ]
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @param arrayNode Ein Konten, der ein Array als Wert hat.
|
|
211
|
+
* @param value Ein Wert (z.B. 'src/favicon.ico').
|
|
212
|
+
*/
|
|
213
|
+
function findStringIndexInArray(arrayNode, value) {
|
|
214
|
+
let arrayIndex = -1;
|
|
215
|
+
if (arrayNode.children) {
|
|
216
|
+
for (let i = 0; i < arrayNode.children.length; i++) {
|
|
217
|
+
const assetChild = arrayNode.children[i];
|
|
218
|
+
if (assetChild.type === 'string' && assetChild.value === value) {
|
|
219
|
+
arrayIndex = i;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return arrayIndex;
|
|
225
|
+
}
|
|
226
|
+
exports.findStringIndexInArray = findStringIndexInArray;
|
|
227
|
+
function removeJsonNode(tree, filePath, jsonPath, message = `Den Abschnitt "${JSON.stringify(jsonPath)}" gelöscht.`) {
|
|
228
|
+
const contentAsNode = readJson(tree, filePath);
|
|
229
|
+
const testAssetsNode = (0, jsonc_parser_1.findNodeAtLocation)(contentAsNode, jsonPath);
|
|
230
|
+
if (testAssetsNode) {
|
|
231
|
+
const angularJson = readJsonAsString(tree, filePath);
|
|
232
|
+
const edits = (0, jsonc_parser_1.modify)(angularJson, jsonPath, void 0, { formattingOptions: exports.jsonFormattingOptions });
|
|
233
|
+
if (edits) {
|
|
234
|
+
tree.overwrite(filePath, (0, jsonc_parser_1.applyEdits)(angularJson, edits));
|
|
235
|
+
(0, logging_1.logInfo)(message);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.removeJsonNode = removeJsonNode;
|
|
70
240
|
//# sourceMappingURL=json.js.map
|
package/src/utility/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["json.ts"],"names":[],"mappings":";;;AACA,+
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["json.ts"],"names":[],"mappings":";;;AACA,+CAA0G;AAE1G,uCAAkE;AAErD,QAAA,qBAAqB,GAAsB;IACtD,YAAY,EAAE,IAAI;IAClB,OAAO,EAAE,CAAC;IACV,GAAG,EAAE,IAAI;CACV,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,IAAU,EAAE,QAAgB;IACnD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,MAAM,IAAA,sCAA4B,EAAC,oBAAoB,QAAQ,eAAe,CAAC,CAAC;KACjF;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAElC,IAAI,MAAM,GAAG,IAAA,wBAAS,EAAC,OAAO,CAAS,CAAC;IACxC,OAAO,MAAM,CAAC;AAChB,CAAC;AATD,4BASC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAU,EAAE,QAAgB;IAC3D,MA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,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,aAAa;IACxJ,MAAM,aAAa,GAAI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAChD,MAAM,cAAc,GAAG,IAAA,iCAAkB,EAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACnE,IAAI,cAAc,EAAE;QAClB,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACrD,MAAM,KAAK,GAAS,IAAA,qBAAM,EAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,iBAAiB,EAAE,6BAAqB,EAAE,CAAC,CAAC;QACxG,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAA,yBAAU,EAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YACzD,IAAA,iBAAO,EAAC,OAAO,CAAC,CAAC;SAClB;KACF;AACH,CAAC;AAXD,wCAWC"}
|
package/src/utility/json.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Tree } from '@angular-devkit/schematics';
|
|
2
|
-
import { FormattingOptions, Node, parseTree } from 'jsonc-parser';
|
|
3
|
-
import {
|
|
1
|
+
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
|
|
2
|
+
import { applyEdits, findNodeAtLocation, FormattingOptions, modify, Node, parseTree } from 'jsonc-parser';
|
|
3
|
+
import { types } from 'util';
|
|
4
|
+
import { formattedSchematicsException, logInfo } from './logging';
|
|
4
5
|
|
|
5
6
|
export const jsonFormattingOptions: FormattingOptions = {
|
|
6
7
|
insertSpaces: true,
|
|
@@ -68,3 +69,197 @@ export function appendScript(script: string, part: string, index?: number) {
|
|
|
68
69
|
|
|
69
70
|
return newSkript;
|
|
70
71
|
}
|
|
72
|
+
|
|
73
|
+
export function updateJsonValue(options: any, filePath: string, jsonPath: string[], value: any, onlyUpdate = false): Rule {
|
|
74
|
+
return (tree: Tree, context: SchematicContext) => {
|
|
75
|
+
const found = findNodeAtLocation(readJson(tree, filePath), jsonPath);
|
|
76
|
+
|
|
77
|
+
if (!onlyUpdate || (onlyUpdate && found)) {
|
|
78
|
+
const jsonFile = readJsonAsString(tree, filePath);
|
|
79
|
+
const edits = modify(
|
|
80
|
+
jsonFile,
|
|
81
|
+
jsonPath,
|
|
82
|
+
value,
|
|
83
|
+
{ formattingOptions: jsonFormattingOptions, isArrayInsertion: false}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (edits) {
|
|
87
|
+
tree.overwrite(filePath, applyEdits(jsonFile, edits));
|
|
88
|
+
logInfo(`"${JSON.stringify(value)}" an der Stelle "${jsonPath.join('.')}" eingetragen.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function updateJsonArray(options: any, filePath: string, jsonPath: string[], value: any, onlyUpdate = false, findFn?: (value: Node) => boolean): Rule {
|
|
95
|
+
return (tree: Tree, context: SchematicContext) => {
|
|
96
|
+
|
|
97
|
+
// Gibt es bereits eine passende Stelle?
|
|
98
|
+
let foundIndex = -1;
|
|
99
|
+
let childrenCount = -1;
|
|
100
|
+
|
|
101
|
+
const node = findNodeAtLocation(readJson(tree, filePath), jsonPath);
|
|
102
|
+
if (node && node.children) {
|
|
103
|
+
childrenCount = node.children.length;
|
|
104
|
+
|
|
105
|
+
if (!findFn && typeof value === 'string') {
|
|
106
|
+
// Sollte der Wert bereits im Array enthalten sein,
|
|
107
|
+
// kann man an dieser Stelle abbrechen und die
|
|
108
|
+
// Methode verlassen.
|
|
109
|
+
foundIndex = findStringIndexInArray(node, value);
|
|
110
|
+
if (foundIndex >= 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (findFn) {
|
|
116
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
117
|
+
if (findFn(node.children[ i ])) {
|
|
118
|
+
foundIndex = i;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!onlyUpdate || (onlyUpdate && foundIndex >= 0)) {
|
|
126
|
+
const jsonFile = readJsonAsString(tree, filePath);
|
|
127
|
+
const edits = modify(
|
|
128
|
+
jsonFile,
|
|
129
|
+
[...jsonPath, foundIndex >= 0 ? foundIndex : childrenCount !== -1 ? childrenCount : 0],
|
|
130
|
+
value,
|
|
131
|
+
{ formattingOptions: jsonFormattingOptions, isArrayInsertion: foundIndex === -1}
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
if (edits) {
|
|
135
|
+
tree.overwrite(filePath, applyEdits(jsonFile, edits));
|
|
136
|
+
logInfo(`"${JSON.stringify(value)}" an der Stelle "${jsonPath.join('.')}" hinzugefügt.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Diese Methode liefert den Index im Array des Objekts mit der übergebenen Property zurück.
|
|
144
|
+
*
|
|
145
|
+
* Beispiel: findObjectIndexInArray(node, 'glob', '*.css') = 1
|
|
146
|
+
* ```json
|
|
147
|
+
* 'assets': [
|
|
148
|
+
* 'src/assets',
|
|
149
|
+
* {
|
|
150
|
+
* 'glob': '*.css',
|
|
151
|
+
* 'input': './node_modules/@ihk-gfi/lux-components-theme/prebuilt-themes',
|
|
152
|
+
* 'output': './assets/themes'
|
|
153
|
+
* },
|
|
154
|
+
* 'src/favicon.ico',
|
|
155
|
+
* ]
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param arrayNode Ein Konten, der ein Array als Wert hat.
|
|
159
|
+
* @param propertyName Ein Propertyname (z.B. glob).
|
|
160
|
+
* @param propertyValue Ein Propertywert (z.B. *.css).
|
|
161
|
+
*/
|
|
162
|
+
export function findObjectIndexInArray(arrayNode: Node, propertyName: string, propertyValue: string): number {
|
|
163
|
+
let arrayIndex = -1;
|
|
164
|
+
if (arrayNode.children) {
|
|
165
|
+
for (let i = 0; i < arrayNode.children.length; i++) {
|
|
166
|
+
const assetChild = arrayNode.children[i];
|
|
167
|
+
|
|
168
|
+
if (assetChild.type === 'object' && assetChild.children && assetChild.children.length > 0) {
|
|
169
|
+
const assetObjectChildren = assetChild.children;
|
|
170
|
+
if (assetObjectChildren) {
|
|
171
|
+
for (let j = 0; j < assetObjectChildren.length; j++) {
|
|
172
|
+
if (assetObjectChildren[j].type === 'property') {
|
|
173
|
+
const propertyChildren = assetObjectChildren[j].children ?? [];
|
|
174
|
+
if (
|
|
175
|
+
propertyChildren.length > 1 &&
|
|
176
|
+
propertyChildren[0].value === propertyName &&
|
|
177
|
+
propertyChildren[1].value === propertyValue
|
|
178
|
+
) {
|
|
179
|
+
arrayIndex = i;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} else if (assetChild.type === 'string' && assetChild.value === propertyValue) {
|
|
186
|
+
arrayIndex = i;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return arrayIndex;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function findObjectPropertyInArray(node: Node, propertyName: string, propertyValue: string): boolean {
|
|
196
|
+
let found = false;
|
|
197
|
+
|
|
198
|
+
if (node.type === 'object' && node.children && node.children.length > 0) {
|
|
199
|
+
const assetObjectChildren = node.children;
|
|
200
|
+
if (assetObjectChildren) {
|
|
201
|
+
for (let j = 0; j < assetObjectChildren.length; j++) {
|
|
202
|
+
if (assetObjectChildren[j].type === 'property') {
|
|
203
|
+
const propertyChildren = assetObjectChildren[j].children ?? [];
|
|
204
|
+
if (
|
|
205
|
+
propertyChildren.length > 1 &&
|
|
206
|
+
propertyChildren[0].value === propertyName &&
|
|
207
|
+
propertyChildren[1].value === propertyValue
|
|
208
|
+
) {
|
|
209
|
+
found = true;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return found;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Diese Methode liefert den Index im Array des Werts zurück.
|
|
222
|
+
*
|
|
223
|
+
* Beispiel: findStringIndexInArray(node, 'src/favicon.ico') = 2
|
|
224
|
+
* ```json
|
|
225
|
+
* 'assets': [
|
|
226
|
+
* 'src/assets',
|
|
227
|
+
* {
|
|
228
|
+
* 'glob': '*.css',
|
|
229
|
+
* 'input': './node_modules/@ihk-gfi/lux-components-theme/prebuilt-themes',
|
|
230
|
+
* 'output': './assets/themes'
|
|
231
|
+
* },
|
|
232
|
+
* 'src/favicon.ico',
|
|
233
|
+
* ]
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @param arrayNode Ein Konten, der ein Array als Wert hat.
|
|
237
|
+
* @param value Ein Wert (z.B. 'src/favicon.ico').
|
|
238
|
+
*/
|
|
239
|
+
export function findStringIndexInArray(arrayNode: Node, value: string): number {
|
|
240
|
+
let arrayIndex = -1;
|
|
241
|
+
if (arrayNode.children) {
|
|
242
|
+
for (let i = 0; i < arrayNode.children.length; i++) {
|
|
243
|
+
const assetChild = arrayNode.children[i];
|
|
244
|
+
if (assetChild.type === 'string' && assetChild.value === value) {
|
|
245
|
+
arrayIndex = i;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return arrayIndex;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function removeJsonNode(tree: Tree, filePath: string, jsonPath: (string | any)[], message = `Den Abschnitt "${JSON.stringify(jsonPath)}" gelöscht.`) {
|
|
255
|
+
const contentAsNode = readJson(tree, filePath);
|
|
256
|
+
const testAssetsNode = findNodeAtLocation(contentAsNode, jsonPath);
|
|
257
|
+
if (testAssetsNode) {
|
|
258
|
+
const angularJson = readJsonAsString(tree, filePath);
|
|
259
|
+
const edits = modify(angularJson, jsonPath, void 0, { formattingOptions: jsonFormattingOptions });
|
|
260
|
+
if (edits) {
|
|
261
|
+
tree.overwrite(filePath, applyEdits(angularJson, edits));
|
|
262
|
+
logInfo(message);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
File without changes
|