create-backon 0.13.1 → 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 +19 -7
- package/package.json +1 -1
- package/src/generate.ts +1 -1
- package/src/templates/base.ts +51 -9
package/dist/cli.js
CHANGED
|
@@ -362,9 +362,14 @@ function renderAppTs(projectName, framework, deployTarget) {
|
|
|
362
362
|
const defaultExport = deployTarget === "vercel" ? `
|
|
363
363
|
// Vercel deploys straight from this export \u2014 see vercel.json.
|
|
364
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";
|
|
365
370
|
` : "";
|
|
366
371
|
if (framework === "express") {
|
|
367
|
-
return
|
|
372
|
+
return `${detectionImport}import { createApp, serveApiDocs } from "@mednours/backon/express";
|
|
368
373
|
import { endpoints } from "./endpoints";
|
|
369
374
|
import { exampleMiddleware } from "./middleware/example.middleware";
|
|
370
375
|
|
|
@@ -376,7 +381,7 @@ app.use("/", endpoints);
|
|
|
376
381
|
serveApiDocs(app, "/docs", { title: "${projectName}" });
|
|
377
382
|
${defaultExport}`;
|
|
378
383
|
}
|
|
379
|
-
return
|
|
384
|
+
return `${detectionImport}import { createApp, serveApiDocs } from "@mednours/backon";
|
|
380
385
|
import { endpoints } from "./endpoints";
|
|
381
386
|
import { exampleMiddleware } from "./middleware/example.middleware";
|
|
382
387
|
|
|
@@ -388,9 +393,10 @@ app.route("/", endpoints);
|
|
|
388
393
|
serveApiDocs(app, "/docs", { title: "${projectName}" });
|
|
389
394
|
${defaultExport}`;
|
|
390
395
|
}
|
|
391
|
-
function renderVercelJson() {
|
|
396
|
+
function renderVercelJson(framework) {
|
|
392
397
|
return `{
|
|
393
398
|
"$schema": "https://openapi.vercel.sh/vercel.json",
|
|
399
|
+
"framework": "${framework}",
|
|
394
400
|
"bunVersion": "1.x"
|
|
395
401
|
}
|
|
396
402
|
`;
|
|
@@ -811,9 +817,15 @@ function renderDeploySection(deployTarget, ext) {
|
|
|
811
817
|
Set up for [Vercel](https://vercel.com)'s zero-config Hono/Express support:
|
|
812
818
|
\`src/app.${ext}\` has a default export (Vercel deploys straight from it,
|
|
813
819
|
bypassing \`index.${ext}\`/\`serve()\` \u2014 those keep working locally exactly as
|
|
814
|
-
before)
|
|
815
|
-
|
|
816
|
-
|
|
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
|
|
817
829
|
locally the same way it'll run once deployed.
|
|
818
830
|
`;
|
|
819
831
|
case "node":
|
|
@@ -1053,7 +1065,7 @@ ${answers.deployTarget === "vercel" ? ".vercel\n" : ""}`
|
|
|
1053
1065
|
[join(root, `src/endpoints/index.${ext}`), renderEndpointsIndex(answers.framework, answers.routes)],
|
|
1054
1066
|
[join(root, `scripts/generate-docs.${ext}`), renderGenerateDocsScript(packageName, answers.framework)],
|
|
1055
1067
|
[join(root, `scripts/generate-client.${ext}`), renderGenerateClientScript(answers.language)],
|
|
1056
|
-
...answers.deployTarget === "vercel" ? [[join(root, "vercel.json"), renderVercelJson()]] : []
|
|
1068
|
+
...answers.deployTarget === "vercel" ? [[join(root, "vercel.json"), renderVercelJson(answers.framework)]] : []
|
|
1057
1069
|
];
|
|
1058
1070
|
for (const route of answers.routes) {
|
|
1059
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
|
@@ -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
|
`;
|
|
@@ -594,9 +630,15 @@ function renderDeploySection(deployTarget: DeployTarget | undefined, ext: string
|
|
|
594
630
|
Set up for [Vercel](https://vercel.com)'s zero-config Hono/Express support:
|
|
595
631
|
\`src/app.${ext}\` has a default export (Vercel deploys straight from it,
|
|
596
632
|
bypassing \`index.${ext}\`/\`serve()\` — those keep working locally exactly as
|
|
597
|
-
before)
|
|
598
|
-
|
|
599
|
-
|
|
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
|
|
600
642
|
locally the same way it'll run once deployed.
|
|
601
643
|
`;
|
|
602
644
|
case "node":
|