()
| 10 | const DEFAULT_OUTPUT_DIR = path.resolve(process.cwd(), 'recovered-claude-code') |
| 11 | |
| 12 | async function main() { |
| 13 | const options = parseArgs(process.argv.slice(2)) |
| 14 | const sourceDir = path.resolve(options.source ?? DEFAULT_SOURCE_DIR) |
| 15 | const outDir = path.resolve(options.out ?? DEFAULT_OUTPUT_DIR) |
| 16 | const outSrcDir = path.join(outDir, 'src') |
| 17 | |
| 18 | await assertDirectory(sourceDir) |
| 19 | await fs.mkdir(outSrcDir, { recursive: true }) |
| 20 | |
| 21 | const files = await walk(sourceDir) |
| 22 | const stats = { |
| 23 | sourceDir, |
| 24 | outDir, |
| 25 | totalFiles: 0, |
| 26 | recoveredFromInlineMap: 0, |
| 27 | copiedAsFallback: 0, |
| 28 | skippedBinaryLike: 0, |
| 29 | errors: [], |
| 30 | } |
| 31 | |
| 32 | const dependencyRoots = new Set() |
| 33 | const fileEntries = [] |
| 34 | |
| 35 | for (const filePath of files) { |
| 36 | const relPath = path.relative(sourceDir, filePath) |
| 37 | const destPath = path.join(outSrcDir, relPath) |
| 38 | stats.totalFiles += 1 |
| 39 | |
| 40 | try { |
| 41 | await fs.mkdir(path.dirname(destPath), { recursive: true }) |
| 42 | const buffer = await fs.readFile(filePath) |
| 43 | |
| 44 | if (!isTextLike(filePath)) { |
| 45 | await fs.writeFile(destPath, buffer) |
| 46 | stats.skippedBinaryLike += 1 |
| 47 | fileEntries.push({ |
| 48 | relPath, |
| 49 | mode: 'binary-copy', |
| 50 | }) |
| 51 | continue |
| 52 | } |
| 53 | |
| 54 | const text = buffer.toString('utf8') |
| 55 | const recovered = extractInlineSource(text) |
| 56 | |
| 57 | if (recovered) { |
| 58 | await fs.writeFile(destPath, recovered.content, 'utf8') |
| 59 | stats.recoveredFromInlineMap += 1 |
| 60 | collectDependencyRoots(recovered.content, dependencyRoots) |
| 61 | fileEntries.push({ |
| 62 | relPath, |
| 63 | mode: 'inline-sourcemap', |
| 64 | sourcemapSource: recovered.sourceName, |
| 65 | }) |
| 66 | } else { |
| 67 | await fs.writeFile(destPath, text, 'utf8') |
| 68 | stats.copiedAsFallback += 1 |
| 69 | collectDependencyRoots(text, dependencyRoots) |
no test coverage detected