(block, missingFiles, fallbackGroup)
| 299 | } |
| 300 | |
| 301 | function appendMissingEntries(block, missingFiles, fallbackGroup) { |
| 302 | const warnings = []; |
| 303 | const entries = missingFiles.map((file) => file.entry); |
| 304 | const fallback = fallbackGroup ? findFallbackChildren(block, fallbackGroup) : null; |
| 305 | |
| 306 | if (fallback) { |
| 307 | const childrenBlock = block.slice(fallback.start, fallback.end + 1); |
| 308 | const indent = detectChildIndent(childrenBlock, " "); |
| 309 | const insertion = entries.map((entry) => `${indent}"${entry}",`).join("\n"); |
| 310 | const insertAt = findLineStart(block, fallback.end); |
| 311 | const prefix = block.slice(0, insertAt); |
| 312 | const suffix = block.slice(insertAt); |
| 313 | const separator = prefix.endsWith("\n") ? "" : "\n"; |
| 314 | return { |
| 315 | block: `${prefix}${separator}${insertion}\n${suffix}`, |
| 316 | added: entries, |
| 317 | warnings, |
| 318 | }; |
| 319 | } |
| 320 | |
| 321 | warnings.push(`Fallback group "${fallbackGroup}" not found; appended new refs at route root.`); |
| 322 | const indent = detectChildIndent(block, " "); |
| 323 | const insertAt = findLineStart(block, block.length - 1); |
| 324 | const insertion = entries.map((entry) => `${indent}"${entry}",`).join("\n"); |
| 325 | const prefix = block.slice(0, insertAt); |
| 326 | const suffix = block.slice(insertAt); |
| 327 | const separator = prefix.endsWith("\n") ? "" : "\n"; |
| 328 | |
| 329 | return { |
| 330 | block: `${prefix}${separator}${insertion}\n${suffix}`, |
| 331 | added: entries, |
| 332 | warnings, |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | function detectChildIndent(block, fallback) { |
| 337 | const lines = block.split(/\r?\n/).reverse(); |
no test coverage detected