create-backon 0.13.0 → 0.13.3
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/dist/cli.js +43 -8
- package/package.json +1 -1
- package/src/generate.ts +1 -1
- package/src/templates/base.ts +65 -12
- package/src/templates/db.ts +16 -1
package/dist/cli.js
CHANGED
|
@@ -250,6 +250,8 @@ export const db = drizzle(sql, { schema });
|
|
|
250
250
|
"@neondatabase/serverless": "^0.10.4"
|
|
251
251
|
},
|
|
252
252
|
devDependencies: DRIZZLE_KIT_DEV_DEPENDENCY,
|
|
253
|
+
// @neondatabase/serverless ships its own types — no @types/* needed.
|
|
254
|
+
typeOnlyDevDependencies: {},
|
|
253
255
|
envVars: "DATABASE_URL=postgres://user:password@ep-example-123456.us-east-2.aws.neon.tech/dbname?sslmode=require\n",
|
|
254
256
|
readmeNote: "Uses Neon's HTTP driver \u2014 no connection pooling to manage, which is what makes it safe to use from serverless functions (e.g. Vercel).",
|
|
255
257
|
hasSchemaSupport: true
|
|
@@ -278,6 +280,11 @@ export const db = drizzle(pool, { schema });
|
|
|
278
280
|
pg: "^8.13.1"
|
|
279
281
|
},
|
|
280
282
|
devDependencies: DRIZZLE_KIT_DEV_DEPENDENCY,
|
|
283
|
+
// pg doesn't ship its own types (unlike @neondatabase/serverless) — without
|
|
284
|
+
// this, a freshly scaffolded TypeScript "postgres" project fails
|
|
285
|
+
// `tsc --noEmit` out of the box with TS7016 on `import { Pool } from "pg"`.
|
|
286
|
+
// Caught via a real `bun run typecheck` on a real scaffold, not assumed.
|
|
287
|
+
typeOnlyDevDependencies: { "@types/pg": "^8.23.1" },
|
|
281
288
|
envVars: "DATABASE_URL=postgres://user:password@localhost:5432/dbname\n",
|
|
282
289
|
readmeNote: "Pooled Postgres connection \u2014 fine for local dev or a long-running server, NOT safe as-is on Vercel serverless functions (connection pool exhaustion on cold starts). Use Neon for serverless deploys.",
|
|
283
290
|
hasSchemaSupport: true
|
|
@@ -297,6 +304,7 @@ export const db = drizzle(sqlite);
|
|
|
297
304
|
"drizzle-orm": "^0.38.2"
|
|
298
305
|
},
|
|
299
306
|
devDependencies: {},
|
|
307
|
+
typeOnlyDevDependencies: {},
|
|
300
308
|
envVars: "DATABASE_URL=./dev.db\n",
|
|
301
309
|
readmeNote: "Local file-based SQLite \u2014 for local dev only, not for a serverless deploy target. No schema.ts/add-table support yet \u2014 SQLite uses a different set of drizzle-orm column builders (sqlite-core, not pg-core), hand-write a schema with drizzle-orm/sqlite-core if you need one.",
|
|
302
310
|
hasSchemaSupport: false
|
|
@@ -312,6 +320,7 @@ export const db = undefined;
|
|
|
312
320
|
`,
|
|
313
321
|
dependencies: {},
|
|
314
322
|
devDependencies: {},
|
|
323
|
+
typeOnlyDevDependencies: {},
|
|
315
324
|
envVars: "",
|
|
316
325
|
readmeNote: "No database configured. src/config/db.ts is an empty stub.",
|
|
317
326
|
hasSchemaSupport: false
|
|
@@ -326,6 +335,9 @@ function dbDependencies(db) {
|
|
|
326
335
|
function dbDevDependencies(db) {
|
|
327
336
|
return TEMPLATES[db].devDependencies;
|
|
328
337
|
}
|
|
338
|
+
function dbTypeOnlyDevDependencies(db) {
|
|
339
|
+
return TEMPLATES[db].typeOnlyDevDependencies;
|
|
340
|
+
}
|
|
329
341
|
function dbEnvVars(db) {
|
|
330
342
|
return TEMPLATES[db].envVars;
|
|
331
343
|
}
|
|
@@ -350,9 +362,14 @@ function renderAppTs(projectName, framework, deployTarget) {
|
|
|
350
362
|
const defaultExport = deployTarget === "vercel" ? `
|
|
351
363
|
// Vercel deploys straight from this export \u2014 see vercel.json.
|
|
352
364
|
export default app;
|
|
365
|
+
` : "";
|
|
366
|
+
const detectionImport = deployTarget === "vercel" ? framework === "express" ? `// Vercel's build scans for this import to detect an Express app \u2014 see vercel.json.
|
|
367
|
+
import "express";
|
|
368
|
+
` : `// Vercel's build scans for this import to detect a Hono app \u2014 see vercel.json.
|
|
369
|
+
import "hono";
|
|
353
370
|
` : "";
|
|
354
371
|
if (framework === "express") {
|
|
355
|
-
return
|
|
372
|
+
return `${detectionImport}import { createApp, serveApiDocs } from "@mednours/backon/express";
|
|
356
373
|
import { endpoints } from "./endpoints";
|
|
357
374
|
import { exampleMiddleware } from "./middleware/example.middleware";
|
|
358
375
|
|
|
@@ -364,7 +381,7 @@ app.use("/", endpoints);
|
|
|
364
381
|
serveApiDocs(app, "/docs", { title: "${projectName}" });
|
|
365
382
|
${defaultExport}`;
|
|
366
383
|
}
|
|
367
|
-
return
|
|
384
|
+
return `${detectionImport}import { createApp, serveApiDocs } from "@mednours/backon";
|
|
368
385
|
import { endpoints } from "./endpoints";
|
|
369
386
|
import { exampleMiddleware } from "./middleware/example.middleware";
|
|
370
387
|
|
|
@@ -376,9 +393,10 @@ app.route("/", endpoints);
|
|
|
376
393
|
serveApiDocs(app, "/docs", { title: "${projectName}" });
|
|
377
394
|
${defaultExport}`;
|
|
378
395
|
}
|
|
379
|
-
function renderVercelJson() {
|
|
396
|
+
function renderVercelJson(framework) {
|
|
380
397
|
return `{
|
|
381
398
|
"$schema": "https://openapi.vercel.sh/vercel.json",
|
|
399
|
+
"framework": "${framework}",
|
|
382
400
|
"bunVersion": "1.x"
|
|
383
401
|
}
|
|
384
402
|
`;
|
|
@@ -720,7 +738,18 @@ function renderPackageJson(projectName, framework, language, db) {
|
|
|
720
738
|
zod: "^3.24.1",
|
|
721
739
|
...dbDependencies(db)
|
|
722
740
|
};
|
|
723
|
-
const devDependencies = language === "javascript" ? { ...dbDevDependencies(db) } : framework === "express" ? {
|
|
741
|
+
const devDependencies = language === "javascript" ? { ...dbDevDependencies(db) } : framework === "express" ? {
|
|
742
|
+
"@types/bun": "latest",
|
|
743
|
+
"@types/express": "^4.17.21",
|
|
744
|
+
typescript: "^5.7.2",
|
|
745
|
+
...dbDevDependencies(db),
|
|
746
|
+
...dbTypeOnlyDevDependencies(db)
|
|
747
|
+
} : {
|
|
748
|
+
"@types/bun": "latest",
|
|
749
|
+
typescript: "^5.7.2",
|
|
750
|
+
...dbDevDependencies(db),
|
|
751
|
+
...dbTypeOnlyDevDependencies(db)
|
|
752
|
+
};
|
|
724
753
|
const scripts = {
|
|
725
754
|
dev: `bun run --watch index.${ext}`,
|
|
726
755
|
start: `bun run index.${ext}`,
|
|
@@ -788,9 +817,15 @@ function renderDeploySection(deployTarget, ext) {
|
|
|
788
817
|
Set up for [Vercel](https://vercel.com)'s zero-config Hono/Express support:
|
|
789
818
|
\`src/app.${ext}\` has a default export (Vercel deploys straight from it,
|
|
790
819
|
bypassing \`index.${ext}\`/\`serve()\` \u2014 those keep working locally exactly as
|
|
791
|
-
before)
|
|
792
|
-
|
|
793
|
-
|
|
820
|
+
before). \`vercel.json\` pins the Bun runtime so the deployed function matches
|
|
821
|
+
local dev, and explicitly sets \`"framework"\` to \`"hono"\`/\`"express"\` \u2014 not
|
|
822
|
+
just cosmetic: Vercel's auto-detection for this looks for a file that
|
|
823
|
+
imports \`hono\`/\`express\` directly, which nothing generated here ever does
|
|
824
|
+
(everything goes through \`createApp()\` from \`@mednours/backon\` instead), so
|
|
825
|
+
without this pin Vercel falls back to Framework Preset "Other" and serves
|
|
826
|
+
\`index.${ext}\`'s raw source as a static file instead of running your app.
|
|
827
|
+
Connect the repo on [vercel.com/new](https://vercel.com/new) or run
|
|
828
|
+
\`vercel deploy\` \u2014 no other configuration needed. \`vercel dev\` runs it
|
|
794
829
|
locally the same way it'll run once deployed.
|
|
795
830
|
`;
|
|
796
831
|
case "node":
|
|
@@ -1030,7 +1065,7 @@ ${answers.deployTarget === "vercel" ? ".vercel\n" : ""}`
|
|
|
1030
1065
|
[join(root, `src/endpoints/index.${ext}`), renderEndpointsIndex(answers.framework, answers.routes)],
|
|
1031
1066
|
[join(root, `scripts/generate-docs.${ext}`), renderGenerateDocsScript(packageName, answers.framework)],
|
|
1032
1067
|
[join(root, `scripts/generate-client.${ext}`), renderGenerateClientScript(answers.language)],
|
|
1033
|
-
...answers.deployTarget === "vercel" ? [[join(root, "vercel.json"), renderVercelJson()]] : []
|
|
1068
|
+
...answers.deployTarget === "vercel" ? [[join(root, "vercel.json"), renderVercelJson(answers.framework)]] : []
|
|
1034
1069
|
];
|
|
1035
1070
|
for (const route of answers.routes) {
|
|
1036
1071
|
const dir = join(root, "src/endpoints", route);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-backon",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Scaffolds a new backend project on backon — like `bun create vite@latest`, but for a consistent controller/routes/services backend layout. Runs via bunx/bun create or npx/npm create.",
|
|
6
6
|
"license": "MIT",
|
package/src/generate.ts
CHANGED
|
@@ -116,7 +116,7 @@ export async function generateProject(answers: Answers, cwd: string = process.cw
|
|
|
116
116
|
[join(root, `scripts/generate-docs.${ext}`), renderGenerateDocsScript(packageName, answers.framework)],
|
|
117
117
|
[join(root, `scripts/generate-client.${ext}`), renderGenerateClientScript(answers.language)],
|
|
118
118
|
...(answers.deployTarget === "vercel"
|
|
119
|
-
? ([[join(root, "vercel.json"), renderVercelJson()]] as Array<[string, string]>)
|
|
119
|
+
? ([[join(root, "vercel.json"), renderVercelJson(answers.framework)]] as Array<[string, string]>)
|
|
120
120
|
: []),
|
|
121
121
|
];
|
|
122
122
|
|
package/src/templates/base.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Answers, DeployTarget, Framework, Language } from "../prompts";
|
|
2
2
|
import { camelCase } from "./route";
|
|
3
|
-
import { dbDependencies, dbDevDependencies, dbEnvVars, dbHasSchemaSupport, dbReadmeNote } from "./db";
|
|
3
|
+
import { dbDependencies, dbDevDependencies, dbEnvVars, dbHasSchemaSupport, dbReadmeNote, dbTypeOnlyDevDependencies } from "./db";
|
|
4
4
|
|
|
5
5
|
// renderIndexTs/renderAppTs/renderEndpointsIndex are intentionally NOT
|
|
6
6
|
// language-aware: none of them contain TypeScript-only syntax (no type
|
|
@@ -45,11 +45,31 @@ export function renderAppTs(projectName: string, framework: Framework, deployTar
|
|
|
45
45
|
? `
|
|
46
46
|
// Vercel deploys straight from this export — see vercel.json.
|
|
47
47
|
export default app;
|
|
48
|
+
`
|
|
49
|
+
: "";
|
|
50
|
+
|
|
51
|
+
// Vercel's zero-config Hono/Express builder doesn't just need a default
|
|
52
|
+
// export in the right file — it statically scans app.<ext>/index.<ext>/
|
|
53
|
+
// server.<ext> for a literal `import ... from "hono"` (or "express") and
|
|
54
|
+
// refuses to build without one ("Error: No entrypoint found which imports
|
|
55
|
+
// hono", confirmed against a real failed build). createApp() wraps that
|
|
56
|
+
// import inside @mednours/backon, so without this the scan finds nothing
|
|
57
|
+
// no matter how correct the app itself is — this line exists only to be
|
|
58
|
+
// found, nothing here calls it. Not needed (and left out) for any
|
|
59
|
+
// non-vercel deployTarget.
|
|
60
|
+
const detectionImport =
|
|
61
|
+
deployTarget === "vercel"
|
|
62
|
+
? framework === "express"
|
|
63
|
+
? `// Vercel's build scans for this import to detect an Express app — see vercel.json.
|
|
64
|
+
import "express";
|
|
65
|
+
`
|
|
66
|
+
: `// Vercel's build scans for this import to detect a Hono app — see vercel.json.
|
|
67
|
+
import "hono";
|
|
48
68
|
`
|
|
49
69
|
: "";
|
|
50
70
|
|
|
51
71
|
if (framework === "express") {
|
|
52
|
-
return
|
|
72
|
+
return `${detectionImport}import { createApp, serveApiDocs } from "@mednours/backon/express";
|
|
53
73
|
import { endpoints } from "./endpoints";
|
|
54
74
|
import { exampleMiddleware } from "./middleware/example.middleware";
|
|
55
75
|
|
|
@@ -61,7 +81,7 @@ app.use("/", endpoints);
|
|
|
61
81
|
serveApiDocs(app, "/docs", { title: "${projectName}" });
|
|
62
82
|
${defaultExport}`;
|
|
63
83
|
}
|
|
64
|
-
return
|
|
84
|
+
return `${detectionImport}import { createApp, serveApiDocs } from "@mednours/backon";
|
|
65
85
|
import { endpoints } from "./endpoints";
|
|
66
86
|
import { exampleMiddleware } from "./middleware/example.middleware";
|
|
67
87
|
|
|
@@ -78,12 +98,28 @@ ${defaultExport}`;
|
|
|
78
98
|
// the deployed function on (currently "1.x" is the only valid value; minor/
|
|
79
99
|
// patch are managed by Vercel automatically) — kept in sync with this
|
|
80
100
|
// being a Bun-first framework, so the deployed function behaves the same
|
|
81
|
-
// runtime as local dev.
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
101
|
+
// runtime as local dev.
|
|
102
|
+
//
|
|
103
|
+
// `framework` explicitly pins Vercel's Framework Preset to "hono"/"express"
|
|
104
|
+
// (both valid slugs — checked against openapi.vercel.sh/vercel.json's own
|
|
105
|
+
// schema, not guessed) instead of leaving it to auto-detection. This is not
|
|
106
|
+
// optional: a real deployed project — src/app.ts importing createApp() from
|
|
107
|
+
// @mednours/backon, never `hono` directly — was confirmed live to fail
|
|
108
|
+
// Vercel's zero-config Hono auto-detect. It fell back to Project Settings
|
|
109
|
+
// showing Framework Preset "Other" and serving src/index.ts as a raw static
|
|
110
|
+
// file (content-type video/mp2t, the .ts-extension misdetection) instead of
|
|
111
|
+
// running it as a function — a real request against the deployed URL
|
|
112
|
+
// returned the literal unexecuted source of index.ts, not a response from
|
|
113
|
+
// the app. Because backon's whole point is wrapping `new Hono()`/
|
|
114
|
+
// `express()` behind createApp(), no entry file this CLI generates will ever
|
|
115
|
+
// contain a literal top-level `from "hono"`/`from "express"` import for a
|
|
116
|
+
// content-sniffing detector to find — so auto-detection can't be relied on
|
|
117
|
+
// for any backon-based project, and this override is the fix, not a
|
|
118
|
+
// workaround for one broken app.
|
|
119
|
+
export function renderVercelJson(framework: Framework): string {
|
|
85
120
|
return `{
|
|
86
121
|
"$schema": "https://openapi.vercel.sh/vercel.json",
|
|
122
|
+
"framework": "${framework}",
|
|
87
123
|
"bunVersion": "1.x"
|
|
88
124
|
}
|
|
89
125
|
`;
|
|
@@ -507,8 +543,19 @@ export function renderPackageJson(
|
|
|
507
543
|
language === "javascript"
|
|
508
544
|
? { ...dbDevDependencies(db) }
|
|
509
545
|
: framework === "express"
|
|
510
|
-
? {
|
|
511
|
-
|
|
546
|
+
? {
|
|
547
|
+
"@types/bun": "latest",
|
|
548
|
+
"@types/express": "^4.17.21",
|
|
549
|
+
typescript: "^5.7.2",
|
|
550
|
+
...dbDevDependencies(db),
|
|
551
|
+
...dbTypeOnlyDevDependencies(db),
|
|
552
|
+
}
|
|
553
|
+
: {
|
|
554
|
+
"@types/bun": "latest",
|
|
555
|
+
typescript: "^5.7.2",
|
|
556
|
+
...dbDevDependencies(db),
|
|
557
|
+
...dbTypeOnlyDevDependencies(db),
|
|
558
|
+
};
|
|
512
559
|
|
|
513
560
|
const scripts: Record<string, string> = {
|
|
514
561
|
dev: `bun run --watch index.${ext}`,
|
|
@@ -583,9 +630,15 @@ function renderDeploySection(deployTarget: DeployTarget | undefined, ext: string
|
|
|
583
630
|
Set up for [Vercel](https://vercel.com)'s zero-config Hono/Express support:
|
|
584
631
|
\`src/app.${ext}\` has a default export (Vercel deploys straight from it,
|
|
585
632
|
bypassing \`index.${ext}\`/\`serve()\` — those keep working locally exactly as
|
|
586
|
-
before)
|
|
587
|
-
|
|
588
|
-
|
|
633
|
+
before). \`vercel.json\` pins the Bun runtime so the deployed function matches
|
|
634
|
+
local dev, and explicitly sets \`"framework"\` to \`"hono"\`/\`"express"\` — not
|
|
635
|
+
just cosmetic: Vercel's auto-detection for this looks for a file that
|
|
636
|
+
imports \`hono\`/\`express\` directly, which nothing generated here ever does
|
|
637
|
+
(everything goes through \`createApp()\` from \`@mednours/backon\` instead), so
|
|
638
|
+
without this pin Vercel falls back to Framework Preset "Other" and serves
|
|
639
|
+
\`index.${ext}\`'s raw source as a static file instead of running your app.
|
|
640
|
+
Connect the repo on [vercel.com/new](https://vercel.com/new) or run
|
|
641
|
+
\`vercel deploy\` — no other configuration needed. \`vercel dev\` runs it
|
|
589
642
|
locally the same way it'll run once deployed.
|
|
590
643
|
`;
|
|
591
644
|
case "node":
|
package/src/templates/db.ts
CHANGED
|
@@ -5,8 +5,10 @@ export interface DbTemplate {
|
|
|
5
5
|
file: string;
|
|
6
6
|
/** Extra runtime dependencies the generated package.json needs. */
|
|
7
7
|
dependencies: Record<string, string>;
|
|
8
|
-
/** Extra dev-only dependencies the generated package.json needs (drizzle-kit — a CLI tool, not runtime code). */
|
|
8
|
+
/** Extra dev-only dependencies the generated package.json needs (drizzle-kit — a CLI tool, not runtime code). Merged in regardless of language, same as `dependencies`. */
|
|
9
9
|
devDependencies: Record<string, string>;
|
|
10
|
+
/** Extra dev-only *type declaration* dependencies (e.g. @types/pg) — merged in for TypeScript projects only, mirroring how @types/bun/@types/express are already excluded from JavaScript-mode devDependencies in renderPackageJson(). */
|
|
11
|
+
typeOnlyDevDependencies: Record<string, string>;
|
|
10
12
|
/** Line(s) appended to .env.example. */
|
|
11
13
|
envVars: string;
|
|
12
14
|
/** One-line note surfaced in the generated README so the caveats aren't silently lost. */
|
|
@@ -40,6 +42,8 @@ export const db = drizzle(sql, { schema });
|
|
|
40
42
|
"@neondatabase/serverless": "^0.10.4",
|
|
41
43
|
},
|
|
42
44
|
devDependencies: DRIZZLE_KIT_DEV_DEPENDENCY,
|
|
45
|
+
// @neondatabase/serverless ships its own types — no @types/* needed.
|
|
46
|
+
typeOnlyDevDependencies: {},
|
|
43
47
|
envVars: "DATABASE_URL=postgres://user:password@ep-example-123456.us-east-2.aws.neon.tech/dbname?sslmode=require\n",
|
|
44
48
|
readmeNote:
|
|
45
49
|
"Uses Neon's HTTP driver — no connection pooling to manage, which is what makes it safe to use from serverless functions (e.g. Vercel).",
|
|
@@ -69,6 +73,11 @@ export const db = drizzle(pool, { schema });
|
|
|
69
73
|
pg: "^8.13.1",
|
|
70
74
|
},
|
|
71
75
|
devDependencies: DRIZZLE_KIT_DEV_DEPENDENCY,
|
|
76
|
+
// pg doesn't ship its own types (unlike @neondatabase/serverless) — without
|
|
77
|
+
// this, a freshly scaffolded TypeScript "postgres" project fails
|
|
78
|
+
// `tsc --noEmit` out of the box with TS7016 on `import { Pool } from "pg"`.
|
|
79
|
+
// Caught via a real `bun run typecheck` on a real scaffold, not assumed.
|
|
80
|
+
typeOnlyDevDependencies: { "@types/pg": "^8.23.1" },
|
|
72
81
|
envVars: "DATABASE_URL=postgres://user:password@localhost:5432/dbname\n",
|
|
73
82
|
readmeNote:
|
|
74
83
|
"Pooled Postgres connection — fine for local dev or a long-running server, NOT safe as-is on Vercel serverless functions (connection pool exhaustion on cold starts). Use Neon for serverless deploys.",
|
|
@@ -89,6 +98,7 @@ export const db = drizzle(sqlite);
|
|
|
89
98
|
"drizzle-orm": "^0.38.2",
|
|
90
99
|
},
|
|
91
100
|
devDependencies: {},
|
|
101
|
+
typeOnlyDevDependencies: {},
|
|
92
102
|
envVars: "DATABASE_URL=./dev.db\n",
|
|
93
103
|
readmeNote:
|
|
94
104
|
"Local file-based SQLite — for local dev only, not for a serverless deploy target. No schema.ts/add-table support yet — SQLite uses a different set of drizzle-orm column builders (sqlite-core, not pg-core), hand-write a schema with drizzle-orm/sqlite-core if you need one.",
|
|
@@ -105,6 +115,7 @@ export const db = undefined;
|
|
|
105
115
|
`,
|
|
106
116
|
dependencies: {},
|
|
107
117
|
devDependencies: {},
|
|
118
|
+
typeOnlyDevDependencies: {},
|
|
108
119
|
envVars: "",
|
|
109
120
|
readmeNote: "No database configured. src/config/db.ts is an empty stub.",
|
|
110
121
|
hasSchemaSupport: false,
|
|
@@ -123,6 +134,10 @@ export function dbDevDependencies(db: DbChoice): Record<string, string> {
|
|
|
123
134
|
return TEMPLATES[db].devDependencies;
|
|
124
135
|
}
|
|
125
136
|
|
|
137
|
+
export function dbTypeOnlyDevDependencies(db: DbChoice): Record<string, string> {
|
|
138
|
+
return TEMPLATES[db].typeOnlyDevDependencies;
|
|
139
|
+
}
|
|
140
|
+
|
|
126
141
|
export function dbEnvVars(db: DbChoice): string {
|
|
127
142
|
return TEMPLATES[db].envVars;
|
|
128
143
|
}
|