create-backon 0.6.0 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-backon",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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.",
6
6
  "license": "MIT",
package/src/generate.ts CHANGED
@@ -92,7 +92,7 @@ export async function generateProject(answers: Answers, cwd: string = process.cw
92
92
  : [join(root, "tsconfig.json"), renderTsconfig()],
93
93
  [join(root, "README.md"), renderReadme(readmeAnswers)],
94
94
  [join(root, ".gitignore"), "node_modules/\ndist/\n*.log\n.env\n.env.local\nopenapi.json\ndocs.html\n"],
95
- [join(root, `src/app.${ext}`), renderAppTs(answers.framework)],
95
+ [join(root, `src/app.${ext}`), renderAppTs(packageName, answers.framework)],
96
96
  [join(root, `src/config/db.${ext}`), renderDbFile(answers.db)],
97
97
  [
98
98
  join(root, `src/middleware/example.middleware.${ext}`),
@@ -19,9 +19,13 @@ serve(app);
19
19
  `;
20
20
  }
21
21
 
22
- export function renderAppTs(framework: Framework): string {
22
+ // serveApiDocs() is called last, after every route is mounted — it reads
23
+ // the route table as it stands at call time, so anything registered after
24
+ // this line would be missing from /docs. Same live route this project's
25
+ // bun run docs script generates a static copy of; see generate-docs.<ext>.
26
+ export function renderAppTs(projectName: string, framework: Framework): string {
23
27
  if (framework === "express") {
24
- return `import { createApp } from "@mednours/backon/express";
28
+ return `import { createApp, serveApiDocs } from "@mednours/backon/express";
25
29
  import { endpoints } from "./endpoints";
26
30
  import { exampleMiddleware } from "./middleware/example.middleware";
27
31
 
@@ -29,9 +33,11 @@ export const app = createApp();
29
33
 
30
34
  app.use(exampleMiddleware);
31
35
  app.use("/", endpoints);
36
+
37
+ serveApiDocs(app, "/docs", { title: "${projectName}" });
32
38
  `;
33
39
  }
34
- return `import { createApp } from "@mednours/backon";
40
+ return `import { createApp, serveApiDocs } from "@mednours/backon";
35
41
  import { endpoints } from "./endpoints";
36
42
  import { exampleMiddleware } from "./middleware/example.middleware";
37
43
 
@@ -39,6 +45,8 @@ export const app = createApp();
39
45
 
40
46
  app.use("*", exampleMiddleware);
41
47
  app.route("/", endpoints);
48
+
49
+ serveApiDocs(app, "/docs", { title: "${projectName}" });
42
50
  `;
43
51
  }
44
52
 
@@ -159,15 +167,21 @@ ${mounts}
159
167
  // rather than starting the server, so running this doesn't require anything
160
168
  // to be listening — generateOpenApiSpec() only needs the app's routes
161
169
  // registered, which happens at import time.
170
+ //
171
+ // docs.html embeds the spec directly (apiReferenceHtmlInline), rather than
172
+ // pointing at ./openapi.json the way the live serveApiDocs() page does —
173
+ // this file gets opened straight from disk as often as it's served over
174
+ // HTTP, and a browser blocks one file:// URL from fetching another, so a
175
+ // URL-based page would fail exactly there.
162
176
  export function renderGenerateDocsScript(projectName: string, framework: Framework): string {
163
177
  const backonImport = framework === "express" ? "@mednours/backon/express" : "@mednours/backon";
164
178
  return `import { writeFileSync } from "node:fs";
165
- import { generateOpenApiSpec, apiReferenceHtml } from "${backonImport}";
179
+ import { generateOpenApiSpec, apiReferenceHtmlInline } from "${backonImport}";
166
180
  import { app } from "../src/app";
167
181
 
168
182
  const spec = generateOpenApiSpec(app, { title: "${projectName}", version: "0.1.0" });
169
183
  writeFileSync("openapi.json", JSON.stringify(spec, null, 2));
170
- writeFileSync("docs.html", apiReferenceHtml("./openapi.json", "${projectName}"));
184
+ writeFileSync("docs.html", apiReferenceHtmlInline(spec, "${projectName}"));
171
185
 
172
186
  console.log("Wrote openapi.json and docs.html");
173
187
  `;
@@ -312,6 +326,10 @@ cp .env.example .env # fill in real values
312
326
  bun run dev
313
327
  \`\`\`
314
328
 
329
+ Once running, \`http://localhost:3000/docs\` has a live API reference for
330
+ every route added via \`defineRoute\` — \`bun run docs\` also writes the same
331
+ document to \`openapi.json\`/\`docs.html\` on disk, for CI or static hosting.
332
+
315
333
  ## Database: ${answers.db}
316
334
 
317
335
  ${dbReadmeNote(answers.db)}