@sap-ux/app-config-writer 1.0.7 → 1.0.8
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.
|
@@ -192,6 +192,29 @@ async function removeFioriToolsFromExistingConfig(basePath, fs, logger) {
|
|
|
192
192
|
logger?.debug(`Removed SAP Fiori tools plugin references from ${configPath}`);
|
|
193
193
|
return JSON.stringify(eslintConfig, null, 2);
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Finds the index of the `[` that is matched by the `]` at the given closing index, walking
|
|
197
|
+
* backwards through the string while tracking bracket depth.
|
|
198
|
+
*
|
|
199
|
+
* @param content - the full file content string
|
|
200
|
+
* @param closingIndex - the index of the `]` whose matching `[` we want to find
|
|
201
|
+
* @returns the index of the matching `[`, or -1 if not found
|
|
202
|
+
*/
|
|
203
|
+
function findMatchingOpenBracket(content, closingIndex) {
|
|
204
|
+
let depth = 0;
|
|
205
|
+
for (let i = closingIndex; i >= 0; i--) {
|
|
206
|
+
if (content.charAt(i) === ']') {
|
|
207
|
+
depth++;
|
|
208
|
+
}
|
|
209
|
+
else if (content.charAt(i) === '[') {
|
|
210
|
+
depth--;
|
|
211
|
+
if (depth === 0) {
|
|
212
|
+
return i;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return -1;
|
|
217
|
+
}
|
|
195
218
|
/**
|
|
196
219
|
* Injects the SAP Fiori tools plugin import and config spread into the migrated flat-config file.
|
|
197
220
|
*
|
|
@@ -216,10 +239,13 @@ async function injectFioriToolsIntoMigratedConfig(basePath, fs, config = 'recomm
|
|
|
216
239
|
if (lastBracketIndex === -1) {
|
|
217
240
|
throw new Error('Unexpected format of migrated eslint config. Could not inject the SAP Fiori tools plugin configuration.');
|
|
218
241
|
}
|
|
242
|
+
const beforeBracket = content.slice(0, lastBracketIndex);
|
|
243
|
+
const matchingOpenIndex = findMatchingOpenBracket(content, lastBracketIndex);
|
|
244
|
+
const betweenBrackets = matchingOpenIndex === -1 ? '' : content.slice(matchingOpenIndex + 1, lastBracketIndex);
|
|
245
|
+
const isEmptyArray = /^\s*$/.test(betweenBrackets);
|
|
246
|
+
const separator = isEmptyArray ? '' : ',';
|
|
219
247
|
content =
|
|
220
|
-
content.slice(
|
|
221
|
-
`,\n ...fioriTools.configs['${config}'],\n` +
|
|
222
|
-
content.slice(lastBracketIndex);
|
|
248
|
+
beforeBracket + `${separator}\n ...fioriTools.configs['${config}'],\n` + content.slice(lastBracketIndex);
|
|
223
249
|
fs.write(migratedConfigPath, content);
|
|
224
250
|
logger?.debug(`Injected SAP Fiori tools plugin into ${migratedConfigPath}`);
|
|
225
251
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/app-config-writer",
|
|
3
3
|
"description": "Add or update configuration for SAP Fiori tools application",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@types/cross-spawn": "6.0.6",
|
|
48
48
|
"axios": "1.16.0",
|
|
49
49
|
"nock": "14.0.11",
|
|
50
|
-
"@sap-ux/preview-middleware": "1.0.
|
|
50
|
+
"@sap-ux/preview-middleware": "1.0.15"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=22.x"
|