create-backon 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -1
- package/dist/cli.js +809 -29
- package/package.json +3 -2
- package/src/add-method.ts +26 -27
- package/src/ast-edit.ts +224 -0
- package/src/cli.ts +404 -3
- package/src/colors.ts +10 -0
- package/src/crud-scaffold.ts +62 -0
- package/src/db-status.ts +117 -0
- package/src/generate.ts +3 -1
- package/src/remove-method.ts +98 -0
- package/src/route-methods.ts +24 -0
- package/src/templates/base.ts +208 -2
package/README.md
CHANGED
|
@@ -104,7 +104,19 @@ and regenerates `src/endpoints/index.ts` so the new route is mounted next
|
|
|
104
104
|
to the ones that were already there. It refuses to run outside a backon
|
|
105
105
|
project, refuses a route name whose folder already exists, and refuses a
|
|
106
106
|
name that's already mounted. Run `add-method` next to give the new route
|
|
107
|
-
an actual GET/POST/etc
|
|
107
|
+
an actual GET/POST/etc — or add `--crud` to wire up the standard five in
|
|
108
|
+
one go instead of one at a time:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
bun run add-route users --crud
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Adds `list` (GET /), `create` (POST /), `getById` (GET /:id), `update`
|
|
115
|
+
(PUT /:id), and `remove` (DELETE /:id) right after creating the route —
|
|
116
|
+
the exact same names `add-method`'s own suggestions already default to,
|
|
117
|
+
just all five at once. Leave `--crud` off (or say no to the "Scaffold
|
|
118
|
+
standard CRUD methods now?" prompt when running `add-route` with no name)
|
|
119
|
+
to get the usual blank endpoint instead.
|
|
108
120
|
|
|
109
121
|
## Adding a method to a route
|
|
110
122
|
|
|
@@ -133,6 +145,13 @@ told to stop, so a whole endpoint's worth of methods is normally one
|
|
|
133
145
|
`bun run add-method` session. Refuses a method name or a verb+path pair
|
|
134
146
|
that's already there.
|
|
135
147
|
|
|
148
|
+
Every file edit here (and in `remove-method`, below) goes through a real
|
|
149
|
+
TypeScript/JavaScript AST ([ts-morph](https://ts-morph.com)) rather than
|
|
150
|
+
matching raw text — an import is recognized as already present by its
|
|
151
|
+
actual structure, and a method's own statements are found by the exact
|
|
152
|
+
name `add-method` already enforces is unique per endpoint. A hand-reformatted
|
|
153
|
+
mount line or import doesn't throw either operation off.
|
|
154
|
+
|
|
136
155
|
## Removing a route
|
|
137
156
|
|
|
138
157
|
The undo for `add-route`:
|
|
@@ -180,6 +199,46 @@ comes from hand-editing `index.ts`, deleting a route folder without using
|
|
|
180
199
|
`doctor` only reports issues — it doesn't fix them — and exits non-zero if
|
|
181
200
|
it finds any, so it's usable in a pre-commit hook or CI step.
|
|
182
201
|
|
|
202
|
+
## Project overview
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
bun run project
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
or `bunx create-backon project`. Read-only, one shot — not a loop, nothing
|
|
209
|
+
here writes to disk. Prints three things: the database driver actually wired
|
|
210
|
+
up in `src/config/db.<ext>` and whether it has what it needs (a config
|
|
211
|
+
check, not a live connection attempt — for Neon/Postgres that means
|
|
212
|
+
`DATABASE_URL` is set in `.env`; SQLite is always "ready" since it falls
|
|
213
|
+
back to `./dev.db`; "none" means no database is configured, which is also
|
|
214
|
+
"ready"), the same per-endpoint, per-method dashboard `list-routes` shows,
|
|
215
|
+
and a one-line doctor summary. Point of this command is answering "what's
|
|
216
|
+
actually going on in this project" in one glance, without needing to
|
|
217
|
+
remember which of `list-routes`/`doctor`/checking `.env` by hand to run.
|
|
218
|
+
|
|
219
|
+
## Managing endpoints and methods interactively
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
bun run server-config
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
or `bunx create-backon server-config`. The interactive alternative to
|
|
226
|
+
running `add-route`/`add-method`/`remove-route` individually — opens with
|
|
227
|
+
the same endpoint dashboard `project` shows, then a menu: add a new
|
|
228
|
+
endpoint (with the same "scaffold standard CRUD methods now?" prompt
|
|
229
|
+
`add-route` offers), remove one, add a method, remove a method, or modify a method
|
|
230
|
+
(change its path, name, or body/query validation in place — the one thing
|
|
231
|
+
none of the standalone commands offer, since it's a checked
|
|
232
|
+
remove-then-re-add rather than a new codegen path). Loops back to the menu
|
|
233
|
+
after each action, re-reading the endpoint list fresh every time, until
|
|
234
|
+
told to stop. `project` and `server-config` are deliberately two separate
|
|
235
|
+
commands rather than one combined dashboard — "show me what's here" and
|
|
236
|
+
"let me start changing things" are different intents, and an overview that
|
|
237
|
+
can also accidentally edit something isn't actually a safe overview.
|
|
238
|
+
`add-route`/`add-method`/`remove-route`/`list-routes`/`doctor` all keep
|
|
239
|
+
working exactly as documented above; `server-config` is a wrapper around
|
|
240
|
+
the same underlying logic, not a replacement for them.
|
|
241
|
+
|
|
183
242
|
## Generating API docs
|
|
184
243
|
|
|
185
244
|
Every generated project includes a `docs` script:
|
|
@@ -203,6 +262,37 @@ same spec and reference page as live routes on a running server instead of
|
|
|
203
262
|
writing them to disk — useful for CI, static hosting, or feeding the spec
|
|
204
263
|
into an external tool, where `serveApiDocs`'s live routes don't apply.
|
|
205
264
|
|
|
265
|
+
## Generating a typed API client
|
|
266
|
+
|
|
267
|
+
Every generated project also includes:
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
bun run generate-client
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Writes `client/api.<ext>` — a fetch client with one function per mounted
|
|
274
|
+
method, grouped by endpoint (`usersApi.list()`, `usersApi.create(body)`,
|
|
275
|
+
`usersApi.getById(id)`, and so on), read directly off `*.routes.<ext>`/
|
|
276
|
+
`*.controller.<ext>` — the same files `add-method`/`remove-method`/
|
|
277
|
+
`server-config` already write, so there's nothing to keep in sync by hand.
|
|
278
|
+
Backed by `scripts/generate-client.<ext>`, generated alongside everything
|
|
279
|
+
else; unlike `generate-docs.<ext>` it doesn't import `src/app` — it reads
|
|
280
|
+
the endpoint files directly, so it can't fail because `app.ts` throws on a
|
|
281
|
+
missing env var. It also never goes stale on its own: it re-discovers
|
|
282
|
+
routes fresh every time it *runs*, so only its output needs a re-run after
|
|
283
|
+
routes or methods change, not the script itself.
|
|
284
|
+
|
|
285
|
+
In TypeScript projects, each generated function's body/query parameters
|
|
286
|
+
are typed via `z.infer<typeof theSchema>` against the schema the
|
|
287
|
+
controller already exports — imported by type, not re-declared, so the
|
|
288
|
+
client's argument types can't drift from what `defineRoute()` actually
|
|
289
|
+
validates. Response shape is deliberately not claimed beyond an optional
|
|
290
|
+
`<T = unknown>` generic per call (`usersApi.list<User[]>()`) — backon
|
|
291
|
+
doesn't validate responses, so nothing here pretends to know a shape it
|
|
292
|
+
can't verify. JavaScript projects get the same functions with no type
|
|
293
|
+
annotations. `client/` is a build artifact like `openapi.json`/`docs.html`,
|
|
294
|
+
not source, so it's in the generated `.gitignore` by default.
|
|
295
|
+
|
|
206
296
|
## Deploying to Vercel
|
|
207
297
|
|
|
208
298
|
Picking Vercel at the "Where's this headed?" prompt adds two things, both
|