create-backon 0.6.1 → 0.9.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 +102 -12
- package/dist/cli.js +1240 -0
- package/package.json +10 -6
- package/src/add-method.ts +101 -0
- package/src/add-route.ts +11 -9
- package/src/cli.ts +145 -3
- package/src/colors.ts +25 -0
- package/src/generate.ts +17 -6
- package/src/prompts.ts +26 -0
- package/src/route-methods.ts +76 -0
- package/src/templates/base.ts +103 -7
- package/src/templates/route.ts +143 -64
package/README.md
CHANGED
|
@@ -17,12 +17,18 @@ Or, without the `bun create` shorthand:
|
|
|
17
17
|
bunx create-backon
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
No Bun installed? `npx create-backon` and `npm create backon` both work too
|
|
21
|
+
— same scaffolder either way, generated projects still default to Bun
|
|
22
|
+
scripts (see [Running a generated project without Bun](#running-a-generated-project-without-bun)
|
|
23
|
+
if that's not an option).
|
|
24
|
+
|
|
20
25
|
Prompts for a project name (or `.` to scaffold into the current directory,
|
|
21
26
|
same as `bun create vite@latest .`), a framework (Hono or Express), a
|
|
22
27
|
language (TypeScript or JavaScript), a database (Neon, Postgres, SQLite, or
|
|
23
|
-
none — via [Drizzle](https://orm.drizzle.team)),
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
none — via [Drizzle](https://orm.drizzle.team)), where it's headed
|
|
29
|
+
([Vercel](#deploying-to-vercel), another Node/Bun host, local-only, or not
|
|
30
|
+
sure yet), whether to create `.env` from `.env.example` right away (default
|
|
31
|
+
yes — skips the manual `cp` step), and any number of routes, then generates:
|
|
26
32
|
|
|
27
33
|
```
|
|
28
34
|
my-api/
|
|
@@ -41,11 +47,14 @@ my-api/
|
|
|
41
47
|
<route>.services.ts
|
|
42
48
|
```
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
Every route starts blank — a folder mounted in `src/endpoints/index.ts`
|
|
51
|
+
with zero HTTP methods wired up yet. `bun run add-method` (below) adds
|
|
52
|
+
them one at a time: each one appends a `defineRoute`-wrapped export to
|
|
53
|
+
`*.controller.ts` (from `@mednours/backon` or `@mednours/backon/express`,
|
|
54
|
+
depending on the framework picked), a matching function to `*.services.ts`
|
|
55
|
+
— typed via `z.infer` off whatever schema the method declared, so the
|
|
56
|
+
service layer doesn't just see `unknown` — and the mount line to
|
|
57
|
+
`*.routes.ts`. In JavaScript mode every file is generated without any
|
|
49
58
|
TypeScript-only syntax (no `import type`, no generics, no type
|
|
50
59
|
annotations) — generated files are genuinely plain JavaScript rather than
|
|
51
60
|
TypeScript with the types stripped, with JSDoc `@param` comments on the one
|
|
@@ -89,12 +98,40 @@ under a shorter name.)
|
|
|
89
98
|
|
|
90
99
|
It reads the project's own `package.json` to figure out whether it's
|
|
91
100
|
Hono or Express, TypeScript or JavaScript — no need to answer those again
|
|
92
|
-
— then writes `src/endpoints/users/users.controller.ts` (or
|
|
93
|
-
`.
|
|
101
|
+
— then writes a blank `src/endpoints/users/users.controller.ts` (or
|
|
102
|
+
`.routes`, `.services` — zero methods yet, same as the initial scaffold),
|
|
94
103
|
and regenerates `src/endpoints/index.ts` so the new route is mounted next
|
|
95
104
|
to the ones that were already there. It refuses to run outside a backon
|
|
96
105
|
project, refuses a route name whose folder already exists, and refuses a
|
|
97
|
-
name that's already mounted.
|
|
106
|
+
name that's already mounted. Run `add-method` next to give the new route
|
|
107
|
+
an actual GET/POST/etc.
|
|
108
|
+
|
|
109
|
+
## Adding a method to a route
|
|
110
|
+
|
|
111
|
+
Interactive, and separate from `add-route` on purpose — this is where the
|
|
112
|
+
per-endpoint work happens, while `add-route`/`remove-route` stay simple
|
|
113
|
+
whole-folder create/delete:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
bun run add-method
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
or `bunx create-backon add-method` (`method` also works). It opens with a
|
|
120
|
+
dashboard of every endpoint already mounted and the methods each one
|
|
121
|
+
actually has right now — read straight off `*.routes.ts`, colored by verb
|
|
122
|
+
(GET/POST/PUT/PATCH/DELETE) — then walks through: which endpoint to add
|
|
123
|
+
to (or spin up a new blank one on the spot), the HTTP method, the path
|
|
124
|
+
(`/` or `/:id`, or anything else — path params are picked up automatically
|
|
125
|
+
from whatever `:name` segments show up), a name for the controller export
|
|
126
|
+
and matching service function (suggested — `list`, `create`, `getById`,
|
|
127
|
+
`update`, `remove` — but editable), and whether this method validates a
|
|
128
|
+
request body and/or query params. Path params always get a Zod schema
|
|
129
|
+
(auto-derived from the path itself — no guessing there); body and query
|
|
130
|
+
schemas start as `z.object({})` with a `TODO` comment, same convention as
|
|
131
|
+
everywhere else in the generated code, for filling in by hand. Loops until
|
|
132
|
+
told to stop, so a whole endpoint's worth of methods is normally one
|
|
133
|
+
`bun run add-method` session. Refuses a method name or a verb+path pair
|
|
134
|
+
that's already there.
|
|
98
135
|
|
|
99
136
|
## Removing a route
|
|
100
137
|
|
|
@@ -123,7 +160,9 @@ bun run list-routes
|
|
|
123
160
|
```
|
|
124
161
|
|
|
125
162
|
or `bunx create-backon list-routes` (`routes` also works). Read-only —
|
|
126
|
-
|
|
163
|
+
the same dashboard `add-method` opens with: every route mounted in
|
|
164
|
+
`src/endpoints/index.ts`, and the HTTP methods each one actually has,
|
|
165
|
+
colored by verb.
|
|
127
166
|
|
|
128
167
|
## Checking a project for drift
|
|
129
168
|
|
|
@@ -164,6 +203,57 @@ same spec and reference page as live routes on a running server instead of
|
|
|
164
203
|
writing them to disk — useful for CI, static hosting, or feeding the spec
|
|
165
204
|
into an external tool, where `serveApiDocs`'s live routes don't apply.
|
|
166
205
|
|
|
206
|
+
## Deploying to Vercel
|
|
207
|
+
|
|
208
|
+
Picking Vercel at the "Where's this headed?" prompt adds two things, both
|
|
209
|
+
additive — nothing about running the project locally changes:
|
|
210
|
+
|
|
211
|
+
- `src/app.<ext>` gets a default export (`export default app;`), which is
|
|
212
|
+
all [Vercel's zero-config Hono/Express support](https://vercel.com/docs/frameworks/backend/hono)
|
|
213
|
+
needs — it already lives at one of Vercel's recognized entry paths.
|
|
214
|
+
`index.<ext>`'s `serve(app)` call is untouched and keeps working for
|
|
215
|
+
`bun run dev`/`start` anywhere else; Vercel just never runs that file.
|
|
216
|
+
- `vercel.json` pins the [Bun runtime](https://vercel.com/docs/functions/runtimes/bun)
|
|
217
|
+
(`{ "bunVersion": "1.x" }`), so the deployed function runs on the same
|
|
218
|
+
runtime as local dev. Not required for the zero-config detection itself —
|
|
219
|
+
only there so the runtime doesn't silently switch between local and
|
|
220
|
+
deployed.
|
|
221
|
+
|
|
222
|
+
Connect the repo at [vercel.com/new](https://vercel.com/new) or run
|
|
223
|
+
`vercel deploy`; `vercel dev` runs it locally the same way it runs once
|
|
224
|
+
deployed. Missed the prompt, or already have a project? Add both by hand —
|
|
225
|
+
`export default app;` at the end of `src/app.<ext>`, and a `vercel.json`
|
|
226
|
+
with `{ "bunVersion": "1.x" }` — no need to re-scaffold.
|
|
227
|
+
|
|
228
|
+
## Running a generated project without Bun
|
|
229
|
+
|
|
230
|
+
Generated projects still default to Bun (`bun install`, `bun run dev`) —
|
|
231
|
+
that hasn't changed. But the underlying pieces are genuinely Node-capable
|
|
232
|
+
now, if Bun isn't an option:
|
|
233
|
+
|
|
234
|
+
- `@mednours/backon` itself (0.7.0+) runs on Node — its Hono adapter's
|
|
235
|
+
`serve()` uses [`@hono/node-server`](https://github.com/honojs/node-server)
|
|
236
|
+
under Node instead of `Bun.serve()`, detected automatically. Install it
|
|
237
|
+
yourself (`npm install @hono/node-server`) — it's an optional peer
|
|
238
|
+
dependency, so `npm install` alone won't pull it in.
|
|
239
|
+
- `create-backon` itself runs via `npx create-backon`/`npm create backon`
|
|
240
|
+
now too, not just `bunx`/`bun create` — see the badge on
|
|
241
|
+
[npmjs.com/package/create-backon](https://www.npmjs.com/package/create-backon)
|
|
242
|
+
if in doubt about which runtimes are supported.
|
|
243
|
+
- The one piece that's still Bun-flavored: generated source uses
|
|
244
|
+
extensionless relative imports (`./src/app`, not `./src/app.ts` or
|
|
245
|
+
`./src/app.js`) — fine for Bun's bundler-style resolution, but plain
|
|
246
|
+
`node index.ts`/`node index.js` refuses those outright (Node's ESM loader
|
|
247
|
+
requires a real extension on every relative import, full stop — this
|
|
248
|
+
isn't a TypeScript thing, it fails the exact same way in JavaScript
|
|
249
|
+
mode). [`tsx`](https://github.com/privatenumber/tsx) resolves imports the
|
|
250
|
+
same permissive way Bun does, so `npx tsx index.ts` (or `npx tsx watch
|
|
251
|
+
index.ts` for the `bun run dev` equivalent) runs a generated project
|
|
252
|
+
under plain Node with no other changes — verified against a real
|
|
253
|
+
generated project, Hono and Express, TypeScript and JavaScript mode, all
|
|
254
|
+
four combinations. `npm test` still needs a real Node test runner in
|
|
255
|
+
place of `bun test`, which isn't wired up here — that part's on you.
|
|
256
|
+
|
|
167
257
|
## Requirements
|
|
168
258
|
|
|
169
259
|
Bun >= 1.3.
|