You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: devframe/docs/guide/adapters.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ All adapter factories share the same shape: `createXxx(devtoolDef, options?)`.
13
13
| Adapter | Entry | Factory | Best for |
14
14
|---------|-------|---------|----------|
15
15
|[`cli`](#cli)|`devframe/adapters/cli`|`createCli(def, options?)`| Standalone tools run via `node ./my-tool.js`|
16
+
|[`dev`](#dev)|`devframe/adapters/dev`|`createDevServer(def, options?)`| Run the dev server programmatically — drive it from any CLI framework |
16
17
|[`vite`](#vite)|`devframe/adapters/vite`|`createVitePlugin(def, options?)`| Mount a tool's UI inside an existing Vite dev server |
17
18
|[`build`](#build)|`devframe/adapters/build`|`createBuild(def, options?)`| Offline reports, CI artifacts, deployable SPA snapshots |
18
19
|[`kit`](#kit)|`devframe/adapters/kit`|`createKitPlugin(def, options?)`| Integrating into Vite DevTools Kit |
@@ -113,6 +114,65 @@ await createCli(devtool, {
113
114
114
115
Structured diagnostics (via `logs-sdk`) continue to surface through their normal reporters.
115
116
117
+
### Use your own CLI framework
118
+
119
+
When `createCli`'s baked-in `dev` / `build` / `mcp` triplet doesn't fit — e.g. integrating devframe into an existing commander/yargs program, or exposing a different command structure — drop down to the peer factories. Same `DevtoolDefinition`, different shell:
120
+
121
+
| Building block | Entry | Purpose |
122
+
|----------------|-------|---------|
123
+
|[`createDevServer(def, opts?)`](#dev)|`devframe/adapters/dev`| h3 + WebSocket RPC + SPA mount |
|[`createMcpServer(def, opts?)`](#mcp)|`devframe/adapters/mcp`| stdio MCP server |
126
+
|`parseCliFlags(schema, raw)`|`devframe/adapters/cli`| Validate a flag bag against a `CliFlagsSchema`|
127
+
128
+
See the [Standalone CLI guide](./standalone-cli#use-your-own-cli-framework) for a worked commander example.
129
+
130
+
## Dev
131
+
132
+
The `dev` adapter is the building block `createCli` uses internally — h3 + WebSocket RPC + the author's SPA mounted at the resolved base path. Reach for it directly when you want to mount the dev server inside an existing CLI program (commander, yargs, hand-rolled CAC) or attach custom middleware to the underlying h3 app.
`createDevServer` returns the underlying `StartedServer` (origin, port, h3 app, WS server, RPC group, `close()`), so callers integrate cleanly into their own process lifecycle.
|`port`| resolved via `resolveDevServerPort`| Port to listen on. |
153
+
|`flags`|`{}`| Parsed flag bag forwarded to `setup(ctx, { flags })`. |
154
+
|`distDir`|`def.cli?.distDir`| Required — throws when neither is set. |
155
+
|`basePath`|`resolveBasePath(def, 'standalone')`| Mount path override. |
156
+
|`app`| fresh h3 app | Pre-configured h3 app to mount onto (custom middleware, auth, extra static assets). |
157
+
|`openBrowser`| resolves from `flags.open` / `def.cli?.open`| Explicit on/off override. `false` disables; a string opens that relative path. |
158
+
|`onReady`| — | Callback when the WS server is bound. |
159
+
160
+
### Port resolution
161
+
162
+
`resolveDevServerPort(def, opts?)` is exposed separately so authors can resolve a port up-front (to print it, log it, etc.) before starting the server:
`createCli` is a convenience wrapper around three lower-level factories — reach for them directly when you already own a CLI framework (commander, yargs, oclif, hand-rolled cac) or want a different command structure:
`createDevServer` returns the underlying `StartedServer` handle (`origin`, `port`, `app`, `wss`, `rpcGroup`, `close()`) so the surrounding program can drive graceful shutdown — SIGINT, hot reload, integration tests.
309
+
310
+
For typed flag schemas, `parseCliFlags(schema, rawBag)` (from `devframe/adapters/cli`) validates a commander/yargs flag bag against a `CliFlagsSchema` (the same `defineCliFlags(...)` value you'd put on `cli.flags`). Typed-schema validation isn't tied to cac.
311
+
258
312
## Why this shape
259
313
260
314
-**One command, one binary.**`createCli` is a complete CLI — dev, build, spa, mcp all from a single `defineDevtool` value.
0 commit comments