()
| 5 | import { DevCtxConfig } from "../core/types"; |
| 6 | |
| 7 | export async function initCommand() { |
| 8 | try { |
| 9 | const root = await getRepoRoot(); |
| 10 | const devctxDir = path.join(root, ".devctx"); |
| 11 | |
| 12 | if (fs.existsSync(devctxDir)) { |
| 13 | console.log(chalk.yellow("⚠ DevContext already initialized in this repo.")); |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // Create directory structure |
| 18 | fs.mkdirSync(path.join(devctxDir, "sessions"), { recursive: true }); |
| 19 | fs.mkdirSync(path.join(devctxDir, "branches"), { recursive: true }); |
| 20 | |
| 21 | // Write config |
| 22 | const config: DevCtxConfig = { |
| 23 | version: "0.1.0", |
| 24 | createdAt: new Date().toISOString(), |
| 25 | repo: await getRepoName(), |
| 26 | }; |
| 27 | fs.writeFileSync(path.join(devctxDir, "config.json"), JSON.stringify(config, null, 2)); |
| 28 | |
| 29 | // Add to .gitignore |
| 30 | const gitignorePath = path.join(root, ".gitignore"); |
| 31 | const gitignoreContent = fs.existsSync(gitignorePath) |
| 32 | ? fs.readFileSync(gitignorePath, "utf-8") |
| 33 | : ""; |
| 34 | |
| 35 | if (!gitignoreContent.includes(".devctx/")) { |
| 36 | fs.appendFileSync(gitignorePath, "\n# DevContext - AI coding context\n.devctx/\n"); |
| 37 | console.log(chalk.gray(" Added .devctx/ to .gitignore")); |
| 38 | } |
| 39 | |
| 40 | console.log(chalk.green(`✓ Initialized DevContext in ${root}`)); |
| 41 | console.log(chalk.gray(" Run `devctx save` to capture your first context.")); |
| 42 | } catch (err: any) { |
| 43 | if (err.message?.includes("not a git repository")) { |
| 44 | console.log(chalk.red("✗ Not a git repository. Run `git init` first.")); |
| 45 | } else { |
| 46 | console.log(chalk.red(`✗ Error: ${err.message}`)); |
| 47 | } |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected