()
| 86 | } |
| 87 | |
| 88 | function main() { |
| 89 | const opts = parseArgs(process.argv.slice(2)); |
| 90 | |
| 91 | if (opts.mode === 'generate') { |
| 92 | if (!opts.force && isMapIndexFresh(opts.output, DEFAULT_CACHE_MAX_AGE_MS)) { |
| 93 | const age = Date.now() - fs.statSync(opts.output).mtimeMs; |
| 94 | console.log(`Index is fresh (${Math.round(age / 1000)}s old). Use --force to rebuild.`); |
| 95 | process.exit(0); |
| 96 | } |
| 97 | |
| 98 | console.log(`Scanning ${opts.root} ...`); |
| 99 | const index = generateMapIndex(opts.root); |
| 100 | writeMapIndex(index, opts.output); |
| 101 | console.log(`Index written: ${opts.output}`); |
| 102 | console.log(` ${index.fileCount} files, ${index.graphEdgeCount} dependency links`); |
| 103 | console.log(` ${index.routes.length} routes, ${index.verificationCommands.length} verification commands`); |
| 104 | process.exit(0); |
| 105 | } |
| 106 | |
| 107 | const index = loadRequiredIndex(opts.output); |
| 108 | |
| 109 | if (opts.mode === 'stale') { |
| 110 | const report = detectMapStaleness(opts.root, index); |
| 111 | if (opts.json) { |
| 112 | console.log(JSON.stringify(report, null, 2)); |
| 113 | } else if (report.stale) { |
| 114 | console.log('Map index is stale.'); |
| 115 | if (report.changed.length) console.log(`Changed: ${report.changed.join(', ')}`); |
| 116 | if (report.added.length) console.log(`Added: ${report.added.join(', ')}`); |
| 117 | if (report.removed.length) console.log(`Removed: ${report.removed.join(', ')}`); |
| 118 | } else { |
| 119 | console.log('Map index is current.'); |
| 120 | } |
| 121 | process.exit(report.stale ? 2 : 0); |
| 122 | } |
| 123 | |
| 124 | if (opts.mode === 'stats') { |
| 125 | const stats = mapStats(index); |
| 126 | if (opts.json) console.log(JSON.stringify(stats, null, 2)); |
| 127 | else printStats(stats); |
| 128 | process.exit(0); |
| 129 | } |
| 130 | |
| 131 | if (opts.mode === 'slice') { |
| 132 | if (!opts.query) { |
| 133 | console.error('Usage: --slice <terms>'); |
| 134 | process.exit(1); |
| 135 | } |
| 136 | console.log(createMapSlice(index, opts.query, { maxFiles: opts.maxFiles })); |
| 137 | process.exit(0); |
| 138 | } |
| 139 | |
| 140 | if (opts.mode === 'query') { |
| 141 | if (!opts.query) { |
| 142 | console.error('Usage: --query <terms>'); |
| 143 | process.exit(1); |
| 144 | } |
| 145 |
no test coverage detected