()
| 64 | } |
| 65 | |
| 66 | async function collectFiles(): Promise<FileEntry[]> { |
| 67 | const files: FileEntry[] = [] |
| 68 | |
| 69 | const globalFiles = await collectFilesFromDirectory(Global.Path.config, "global") |
| 70 | files.push(...globalFiles) |
| 71 | |
| 72 | const arcticDirs = await Array.fromAsync( |
| 73 | Filesystem.up({ |
| 74 | targets: [".arctic"], |
| 75 | start: Instance.directory, |
| 76 | stop: Instance.worktree, |
| 77 | }), |
| 78 | ) |
| 79 | |
| 80 | for (const arcticDir of arcticDirs) { |
| 81 | const projectFiles = await collectFilesFromDirectory(arcticDir, "project/.arctic") |
| 82 | files.push(...projectFiles) |
| 83 | } |
| 84 | |
| 85 | const rootPatterns = ["arctic.json", "arctic.jsonc"] |
| 86 | for (const pattern of rootPatterns) { |
| 87 | const found = await Filesystem.findUp(pattern, Instance.directory, Instance.worktree) |
| 88 | for (const resolved of found) { |
| 89 | const file = Bun.file(resolved) |
| 90 | const exists = await file.exists() |
| 91 | if (!exists) continue |
| 92 | |
| 93 | const content = await file.arrayBuffer().catch(() => null) |
| 94 | if (!content) continue |
| 95 | |
| 96 | const filename = path.basename(resolved) |
| 97 | files.push({ |
| 98 | path: resolved, |
| 99 | content: Buffer.from(content), |
| 100 | relativePath: path.join("project", filename), |
| 101 | }) |
| 102 | |
| 103 | log.debug("collected root file", { path: resolved }) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | log.info("collected files", { count: files.length }) |
| 108 | return files |
| 109 | } |
| 110 | |
| 111 | async function createZip(files: FileEntry[]): Promise<Buffer> { |
| 112 | const zip = new JSZip() |
no test coverage detected