UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

45 lines (44 loc) 1.61 kB
/** * Build targetFileMap from collected source files. * * Previously duplicated in: * - bootstrap-internal.ts (Phase 4.5) * - rescan-internal.ts (Step 6) * * @module bootstrap/shared/target-file-map */ import { inferLang } from '../../LanguageExtensions.js'; import { inferFilePriority } from '../../TargetClassifier.js'; /** * Build a map of target → TargetFile[] from collected source files. * * @param allFiles - Collected source files from Phase 1 * @param contentMaxLines - Max lines to include in content (default: 120) * @param sort - Whether to sort files by priority within each target (default: false) * @returns Record<targetName, TargetFile[]> */ export function buildTargetFileMap(allFiles, contentMaxLines, sort = false) { const targetFileMap = {}; for (const f of allFiles) { if (!targetFileMap[f.targetName]) { targetFileMap[f.targetName] = []; } const lines = f.content.split('\n'); targetFileMap[f.targetName].push({ name: f.name, relativePath: f.relativePath, language: inferLang(f.name), totalLines: lines.length, priority: inferFilePriority(f.name), content: lines.slice(0, contentMaxLines).join('\n'), truncated: lines.length > contentMaxLines, }); } if (sort) { const prio = { high: 0, medium: 1, low: 2 }; for (const tName of Object.keys(targetFileMap)) { targetFileMap[tName].sort((a, b) => (prio[a.priority] ?? 1) - (prio[b.priority] ?? 1)); } } return targetFileMap; }