From b787837dd298216064f10bea0a06d2cb9083c03f Mon Sep 17 00:00:00 2001 From: dswbx Date: Sat, 25 Oct 2025 10:18:43 +0200 Subject: [PATCH] add deno to the cli starters --- app/src/cli/commands/create/create.ts | 3 ++- app/src/cli/commands/create/templates/deno.ts | 21 +++++++++++++++++++ .../cli/commands/create/templates/index.ts | 8 +++++++ examples/.gitignore | 5 ++++- examples/deno/deno.json | 8 +++++++ examples/deno/main.ts | 12 +++++------ examples/deno/package.json | 7 ------- 7 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 app/src/cli/commands/create/templates/deno.ts create mode 100644 examples/deno/deno.json delete mode 100644 examples/deno/package.json diff --git a/app/src/cli/commands/create/create.ts b/app/src/cli/commands/create/create.ts index 217b07d..d3caae6 100644 --- a/app/src/cli/commands/create/create.ts +++ b/app/src/cli/commands/create/create.ts @@ -20,6 +20,7 @@ const config = { node: "Node.js", bun: "Bun", cloudflare: "Cloudflare", + deno: "Deno", aws: "AWS Lambda", }, framework: { @@ -269,7 +270,7 @@ async function action(options: { ); $p.log.success(`Updated package name to ${color.cyan(ctx.name)}`); - { + if (template.installDeps !== false) { const install = options.yes ?? (await $p.confirm({ diff --git a/app/src/cli/commands/create/templates/deno.ts b/app/src/cli/commands/create/templates/deno.ts new file mode 100644 index 0000000..eb17269 --- /dev/null +++ b/app/src/cli/commands/create/templates/deno.ts @@ -0,0 +1,21 @@ +import { overrideJson } from "cli/commands/create/npm"; +import type { Template } from "cli/commands/create/templates"; +import { getVersion } from "cli/utils/sys"; + +export const deno = { + key: "deno", + title: "Deno Basic", + integration: "deno", + description: "A basic bknd Deno server with static assets", + path: "gh:bknd-io/bknd/examples/deno", + installDeps: false, + ref: true, + setup: async (ctx) => { + const version = await getVersion(); + await overrideJson( + "deno.json", + (json) => ({ ...json, links: undefined, imports: { bknd: `npm:bknd@${version}` } }), + { dir: ctx.dir }, + ); + }, +} satisfies Template; diff --git a/app/src/cli/commands/create/templates/index.ts b/app/src/cli/commands/create/templates/index.ts index ed0f9e1..7aab8d5 100644 --- a/app/src/cli/commands/create/templates/index.ts +++ b/app/src/cli/commands/create/templates/index.ts @@ -1,3 +1,4 @@ +import { deno } from "cli/commands/create/templates/deno"; import { cloudflare } from "./cloudflare"; export type TemplateSetupCtx = { @@ -15,6 +16,7 @@ export type Integration = | "react-router" | "astro" | "aws" + | "deno" | "custom"; type TemplateScripts = "install" | "dev" | "build" | "start"; @@ -34,6 +36,11 @@ export type Template = { * adds a ref "#{ref}" to the path. If "true", adds the current version of bknd */ ref?: true | string; + /** + * control whether to install dependencies automatically + * e.g. on deno, this is not needed + */ + installDeps?: boolean; scripts?: Partial>; preinstall?: (ctx: TemplateSetupCtx) => Promise; postinstall?: (ctx: TemplateSetupCtx) => Promise; @@ -90,4 +97,5 @@ export const templates: Template[] = [ path: "gh:bknd-io/bknd/examples/aws-lambda", ref: true, }, + deno, ]; diff --git a/examples/.gitignore b/examples/.gitignore index f0f60a6..d305846 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,2 +1,5 @@ */package-lock.json -*/bun.lock \ No newline at end of file +*/bun.lock +*/deno.lock +*/node_modules +*/*.db \ No newline at end of file diff --git a/examples/deno/deno.json b/examples/deno/deno.json new file mode 100644 index 0000000..0f8edde --- /dev/null +++ b/examples/deno/deno.json @@ -0,0 +1,8 @@ +{ + "nodeModulesDir": "auto", + "imports": { + "bknd": "npm:bknd@0.19.0-rc.1" + }, + "links": ["../../app/"], + "unstable": ["raw-imports"] +} diff --git a/examples/deno/main.ts b/examples/deno/main.ts index 58e052f..68aba30 100644 --- a/examples/deno/main.ts +++ b/examples/deno/main.ts @@ -1,14 +1,12 @@ -import { createRuntimeApp } from "bknd/adapter"; +import { createRuntimeApp, serveStaticViaImport } from "bknd/adapter"; const app = await createRuntimeApp({ connection: { url: "file:./data.db", }, - adminOptions: { - // currently needs a hosted version of the static assets - assetsPath: "https://cdn.bknd.io/bknd/static/0.15.0-rc.9/", - }, + serveStatic: serveStaticViaImport(), }); -// @ts-ignore -Deno.serve(app.fetch); +export default { + fetch: app.fetch, +}; diff --git a/examples/deno/package.json b/examples/deno/package.json deleted file mode 100644 index 97faf72..0000000 --- a/examples/deno/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "bknd-deno-example", - "private": true, - "dependencies": { - "bknd": "file:../../app" - } -}