| 0d9d723 | | | 1 | import { log } from "@clack/prompts"; |
| 0d9d723 | | | 2 | import { existsSync, readFileSync } from "node:fs"; |
| 0d9d723 | | | 3 | import { join, dirname } from "node:path"; |
| 0d9d723 | | | 4 | import { execSync } from "node:child_process"; |
| 0d9d723 | | | 5 | |
| 0d9d723 | | | 6 | export async function status() { |
| 0d9d723 | | | 7 | let dir = process.cwd(); |
| 0d9d723 | | | 8 | let slDir: string | null = null; |
| 0d9d723 | | | 9 | while (dir !== dirname(dir)) { |
| 0d9d723 | | | 10 | if (existsSync(join(dir, ".sl", "config"))) { |
| 0d9d723 | | | 11 | slDir = join(dir, ".sl"); |
| 0d9d723 | | | 12 | break; |
| 0d9d723 | | | 13 | } |
| 0d9d723 | | | 14 | dir = dirname(dir); |
| 0d9d723 | | | 15 | } |
| 0d9d723 | | | 16 | |
| 0d9d723 | | | 17 | if (!slDir) { |
| 0d9d723 | | | 18 | log.error("Not in a Grove repository."); |
| 0d9d723 | | | 19 | process.exit(1); |
| 0d9d723 | | | 20 | } |
| 0d9d723 | | | 21 | |
| 0d9d723 | | | 22 | const config = readFileSync(join(slDir, "config"), "utf-8"); |
| 0d9d723 | | | 23 | const repoMatch = config.match(/reponame\s*=\s*(.+)/); |
| 0d9d723 | | | 24 | const ownerMatch = config.match(/owner\s*=\s*(.+)/); |
| 0d9d723 | | | 25 | const branchMatch = config.match(/selectivepulldefault\s*=\s*(.+)/); |
| 0d9d723 | | | 26 | |
| 0d9d723 | | | 27 | const repo = repoMatch?.[1]?.trim() ?? "unknown"; |
| 0d9d723 | | | 28 | const owner = ownerMatch?.[1]?.trim() ?? "unknown"; |
| 0d9d723 | | | 29 | const branch = branchMatch?.[1]?.trim() ?? "main"; |
| 0d9d723 | | | 30 | |
| 0d9d723 | | | 31 | let current = ""; |
| 0d9d723 | | | 32 | try { |
| 0d9d723 | | | 33 | current = execSync("sl log -r . --template {bookmarks}", { cwd: dir, stdio: "pipe" }).toString().trim(); |
| 0d9d723 | | | 34 | } catch {} |
| 0d9d723 | | | 35 | |
| 0d9d723 | | | 36 | const lines = [ |
| 0d9d723 | | | 37 | `Repo: ${owner}/${repo}`, |
| 0d9d723 | | | 38 | `Branch: ${branch}`, |
| 0d9d723 | | | 39 | ]; |
| 0d9d723 | | | 40 | if (current) lines.push(`At: ${current}`); |
| 0d9d723 | | | 41 | lines.push(`URL: https://grove.host/${owner}/${repo}`); |
| 0d9d723 | | | 42 | |
| 0d9d723 | | | 43 | log.info(lines.join("\n")); |
| 0d9d723 | | | 44 | } |