|
| 1 | +# @devframes/plugin-git |
| 2 | + |
| 3 | +Git integration for [devframe](https://github.com/devframes/devframe) — a |
| 4 | +repository dashboard with a **Next.js App Router + shadcn/ui** SPA over |
| 5 | +type-safe RPC. The host process shells out to `git` and exposes the repository; |
| 6 | +the same bundle runs as a live dev server or a fully static deployment. |
| 7 | + |
| 8 | +Status, a SourceTree-style **commit graph**, branches, and diffs are read-only; |
| 9 | +staging, unstaging, and committing are available when write mode is enabled. The |
| 10 | +UI follows the system **light/dark** preference with a manual toggle. |
| 11 | + |
| 12 | +## Install |
| 13 | + |
| 14 | +```sh |
| 15 | +npm i -D @devframes/plugin-git |
| 16 | +``` |
| 17 | + |
| 18 | +## Standalone CLI |
| 19 | + |
| 20 | +Run the dashboard against the current repository: |
| 21 | + |
| 22 | +```sh |
| 23 | +npx devframe-git # dev server (live RPC over WebSocket) |
| 24 | +npx devframe-git --write # also enable staging / committing from the UI |
| 25 | +npx devframe-git build # static deploy → dist-static/ |
| 26 | +npx devframe-git --port 4000 |
| 27 | +``` |
| 28 | + |
| 29 | +## Programmatic |
| 30 | + |
| 31 | +`createGitDevframe(options)` returns a devframe definition you can mount into |
| 32 | +any host with devframe's adapters, or drive yourself. |
| 33 | + |
| 34 | +```ts |
| 35 | +import { createGitDevframe } from '@devframes/plugin-git' |
| 36 | +import { createCli } from 'devframe/adapters/cli' |
| 37 | + |
| 38 | +await createCli(createGitDevframe({ repoRoot: process.cwd() })).parse() |
| 39 | +``` |
| 40 | + |
| 41 | +| Option | Default | Description | |
| 42 | +|--------|---------|-------------| |
| 43 | +| `repoRoot` | the devframe `cwd` | Repository directory to inspect. | |
| 44 | +| `basePath` | adapter-resolved | Mount path (`/` standalone, `/__git/` hosted). | |
| 45 | +| `distDir` | bundled SPA | Override the served SPA directory. | |
| 46 | +| `port` | `9710` | Preferred dev-server port. | |
| 47 | +| `write` | `false` | Enable staging, unstaging, and committing from the UI. | |
| 48 | + |
| 49 | +## RPC surface |
| 50 | + |
| 51 | +The read functions are each a `query` with `snapshot: true`: resolved live over |
| 52 | +WebSocket in dev, and served from a snapshot baked at build time for static |
| 53 | +deploys. Each degrades to an empty, `isRepo: false` result outside a git |
| 54 | +repository. |
| 55 | + |
| 56 | +- `git:status` — branch, upstream tracking (ahead/behind), staged / unstaged / |
| 57 | + untracked files, parsed from `git status --porcelain=v2`. Reports `canWrite`. |
| 58 | +- `git:log` — paginated commit history (`limit` / `skip`) including parent |
| 59 | + hashes, which drive the commit graph. |
| 60 | +- `git:branches` — local branches with SHA, upstream, ahead/behind, tip subject. |
| 61 | +- `git:diff` — per-file added/deleted counts for the working tree or index, plus |
| 62 | + a unified patch for a selected file. |
| 63 | + |
| 64 | +Write actions are `action` functions, registered only when write mode is enabled |
| 65 | +(`createGitDevframe({ write: true })` or the `--write` flag) and gated behind |
| 66 | +`status.canWrite` in the UI. Each returns fresh status (commit returns a result): |
| 67 | + |
| 68 | +- `git:stage` — `git add` the given paths. |
| 69 | +- `git:unstage` — `git restore --staged` the given paths. |
| 70 | +- `git:commit` — commit the staged changes with a message. |
| 71 | + |
| 72 | +## Develop |
| 73 | + |
| 74 | +```sh |
| 75 | +pnpm -C plugins/git dev # client (Next.js HMR) + RPC backend together |
| 76 | +pnpm -C plugins/git build # tsdown (node) + next build (SPA) → dist/ |
| 77 | +``` |
| 78 | + |
| 79 | +`pnpm dev` starts the Next.js dev server (with hot-reload) and the devframe |
| 80 | +RPC/WebSocket backend at the same time, then prints both URLs — open the UI one. |
| 81 | +The SPA connects to the backend over the WebSocket port carried in |
| 82 | +`NEXT_PUBLIC_DEVFRAME_WS`. Override ports with `PORT` (UI) and |
| 83 | +`DEVFRAME_GIT_PORT` (backend). Run a single side with `dev:client` or |
| 84 | +`dev:server`. |
| 85 | + |
| 86 | +The SPA is a standard shadcn/ui setup (Tailwind v4, `components/ui/*`). Three |
| 87 | +Next.js settings in `src/client/next.config.mjs` keep it portable: `output: |
| 88 | +'export'` (devframe owns the server), `assetPrefix: '.'` (relative assets so the |
| 89 | +same bundle works at any base), and `trailingSlash: true` (composes with |
| 90 | +devframe's static directory-with-index resolution). |
0 commit comments