MCPcopy Index your code
hub / github.com/itwanger/toBeBetterJavaer / appendMissingEntries

Function appendMissingEntries

scripts/sync-sidebar.js:301–334  ·  view source on GitHub ↗
(block, missingFiles, fallbackGroup)

Source from the content-addressed store, hash-verified

299}
300
301function 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
336function detectChildIndent(block, fallback) {
337 const lines = block.split(/\r?\n/).reverse();

Callers 1

syncTargetFunction · 0.85

Calls 3

findFallbackChildrenFunction · 0.85
detectChildIndentFunction · 0.85
findLineStartFunction · 0.85

Tested by

no test coverage detected