MCPcopy Create free account
hub / github.com/Work-Fisher/code-claw / main

Function main

scripts/recover-project.mjs:12–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10const DEFAULT_OUTPUT_DIR = path.resolve(process.cwd(), 'recovered-claude-code')
11
12async 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)

Callers 1

Calls 9

assertDirectoryFunction · 0.85
isTextLikeFunction · 0.85
extractInlineSourceFunction · 0.85
collectDependencyRootsFunction · 0.85
parseArgsFunction · 0.70
walkFunction · 0.70
pushMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected