import { mkdir, writeFile } from "node:fs/promises"; import path from "node:path"; /** An empty but valid git directory, so git commands stop here instead of searching upwards. */ async function writeGitDirectory(project: string): Promise { await mkdir(path.join(project, ".git", "objects"), { recursive: true }); await mkdir(path.join(project, ".git", "refs"), { recursive: true }); await writeFile(path.join(project, ".git", "HEAD"), "ref: refs/heads/main\n"); } async function writeFiles(root: string, files: Record): Promise { for (const [relative, content] of Object.entries(files)) { const file = path.join(root, relative); await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, content); } } /** * A home folder for the onboarding scan: two projects ("code/atlas" in TypeScript with Docker and * GitHub Actions, "code/garden" in Python) and a notes folder that is not a project. */ export async function writeOnboardingScanFixture(home: string): Promise { await writeFiles(home, { "code/atlas/src/index.ts": "export const atlas = 1;\n", "code/atlas/src/app.tsx": "export const App = () => null;\n", "code/atlas/Dockerfile": "FROM scratch\n", "code/atlas/.github/workflows/ci.yml": "on: push\n", "code/garden/main.py": "print('garden')\n", "code/garden/util.py": "VALUE = 1\n", "notes/todo.md": "- water the plants\n", }); await writeGitDirectory(path.join(home, "code/atlas")); await writeGitDirectory(path.join(home, "code/garden")); }