mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
cli create: updated templates, reworked examples to be standalone
This commit is contained in:
@@ -7,9 +7,9 @@ export type TPackageJson = Partial<{
|
|||||||
main: string;
|
main: string;
|
||||||
version: string;
|
version: string;
|
||||||
scripts: Record<string, string>;
|
scripts: Record<string, string>;
|
||||||
dependencies: Record<string, string>;
|
dependencies: Record<string, string | undefined>;
|
||||||
devDependencies: Record<string, string>;
|
devDependencies: Record<string, string | undefined>;
|
||||||
optionalDependencies: Record<string, string>;
|
optionalDependencies: Record<string, string | undefined>;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ async function createLibsql(ctx: TemplateSetupCtx) {
|
|||||||
...pkg,
|
...pkg,
|
||||||
scripts: {
|
scripts: {
|
||||||
...pkg.scripts,
|
...pkg.scripts,
|
||||||
db: "turso db",
|
db: "turso dev",
|
||||||
dev: "npm run db && wrangler dev"
|
dev: "npm run db && wrangler dev"
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { cloudflare } from "./cloudflare";
|
import { cloudflare } from "./cloudflare";
|
||||||
|
import { nextjs } from "./nextjs";
|
||||||
|
import { remix } from "./remix";
|
||||||
|
|
||||||
export type TemplateSetupCtx = {
|
export type TemplateSetupCtx = {
|
||||||
template: Template;
|
template: Template;
|
||||||
@@ -32,6 +34,9 @@ export type Template = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const templates: Template[] = [
|
export const templates: Template[] = [
|
||||||
|
cloudflare,
|
||||||
|
nextjs,
|
||||||
|
remix,
|
||||||
{
|
{
|
||||||
key: "node",
|
key: "node",
|
||||||
title: "Node.js Basic",
|
title: "Node.js Basic",
|
||||||
@@ -48,27 +53,6 @@ export const templates: Template[] = [
|
|||||||
path: "gh:bknd-io/bknd/examples/bun",
|
path: "gh:bknd-io/bknd/examples/bun",
|
||||||
ref: true
|
ref: true
|
||||||
},
|
},
|
||||||
cloudflare,
|
|
||||||
{
|
|
||||||
key: "remix",
|
|
||||||
title: "Remix Basic",
|
|
||||||
integration: "remix",
|
|
||||||
description: "A basic bknd Remix starter",
|
|
||||||
path: "gh:bknd-io/bknd/examples/remix",
|
|
||||||
ref: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// @todo: add `concurrently`?
|
|
||||||
key: "nextjs",
|
|
||||||
title: "Next.js Basic",
|
|
||||||
integration: "nextjs",
|
|
||||||
description: "A basic bknd Next.js starter",
|
|
||||||
path: "gh:bknd-io/bknd/examples/nextjs",
|
|
||||||
scripts: {
|
|
||||||
install: "npm install --force"
|
|
||||||
},
|
|
||||||
ref: true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: "astro",
|
key: "astro",
|
||||||
title: "Astro Basic",
|
title: "Astro Basic",
|
||||||
|
|||||||
29
app/src/cli/commands/create/templates/nextjs.ts
Normal file
29
app/src/cli/commands/create/templates/nextjs.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { overridePackageJson } from "cli/commands/create/npm";
|
||||||
|
import type { Template } from ".";
|
||||||
|
|
||||||
|
// @todo: add `concurrently`?
|
||||||
|
export const nextjs = {
|
||||||
|
key: "nextjs",
|
||||||
|
title: "Next.js Basic",
|
||||||
|
integration: "nextjs",
|
||||||
|
description: "A basic bknd Next.js starter",
|
||||||
|
path: "gh:bknd-io/bknd/examples/nextjs",
|
||||||
|
scripts: {
|
||||||
|
install: "npm install --force"
|
||||||
|
},
|
||||||
|
ref: true,
|
||||||
|
preinstall: async (ctx) => {
|
||||||
|
// locally it's required to overwrite react, here it is not
|
||||||
|
await overridePackageJson(
|
||||||
|
(pkg) => ({
|
||||||
|
...pkg,
|
||||||
|
dependencies: {
|
||||||
|
...pkg.dependencies,
|
||||||
|
react: undefined,
|
||||||
|
"react-dom": undefined
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
{ dir: ctx.dir }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} as const satisfies Template;
|
||||||
25
app/src/cli/commands/create/templates/remix.ts
Normal file
25
app/src/cli/commands/create/templates/remix.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { overridePackageJson } from "cli/commands/create/npm";
|
||||||
|
import type { Template } from ".";
|
||||||
|
|
||||||
|
export const remix = {
|
||||||
|
key: "remix",
|
||||||
|
title: "Remix Basic",
|
||||||
|
integration: "remix",
|
||||||
|
description: "A basic bknd Remix starter",
|
||||||
|
path: "gh:bknd-io/bknd/examples/remix",
|
||||||
|
ref: true,
|
||||||
|
preinstall: async (ctx) => {
|
||||||
|
// locally it's required to overwrite react
|
||||||
|
await overridePackageJson(
|
||||||
|
(pkg) => ({
|
||||||
|
...pkg,
|
||||||
|
dependencies: {
|
||||||
|
...pkg.dependencies,
|
||||||
|
react: "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0"
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
{ dir: ctx.dir }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} as const satisfies Template;
|
||||||
1
examples/.gitignore
vendored
Normal file
1
examples/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*/package-lock.json
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
"start": "astro dev",
|
"start": "astro dev",
|
||||||
"build": "astro check && astro build",
|
"build": "astro check && astro build",
|
||||||
"preview": "astro preview",
|
"preview": "astro preview",
|
||||||
"db": "turso dev --db-file test.db",
|
|
||||||
"db:check": "sqlite3 test.db \"PRAGMA wal_checkpoint(FULL);\"",
|
|
||||||
"astro": "astro"
|
"astro": "astro"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -17,7 +15,7 @@
|
|||||||
"@types/react": "^18.3.12",
|
"@types/react": "^18.3.12",
|
||||||
"@types/react-dom": "^18.3.1",
|
"@types/react-dom": "^18.3.1",
|
||||||
"astro": "^4.16.16",
|
"astro": "^4.16.16",
|
||||||
"bknd": "workspace:*",
|
"bknd": "file:../../app",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"typescript": "^5.7.2"
|
"typescript": "^5.7.2"
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ import { type BunBkndConfig, serve } from "bknd/adapter/bun";
|
|||||||
const config: BunBkndConfig = {
|
const config: BunBkndConfig = {
|
||||||
connection: {
|
connection: {
|
||||||
url: ":memory:"
|
url: ":memory:"
|
||||||
},
|
}
|
||||||
// this is only required to run inside the same workspace
|
|
||||||
// leave blank if you're running this from a different project
|
|
||||||
distPath: "../../app/dist"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
serve(config);
|
serve(config);
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run --hot index.ts"
|
"dev": "bun run --hot index.ts",
|
||||||
|
"start": "bun run index.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bknd": "workspace:*"
|
"bknd": "file:../../app"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest"
|
"@types/bun": "latest"
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import { $ } from "bun";
|
|
||||||
//import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
|
|
||||||
import esbuild from "esbuild";
|
|
||||||
|
|
||||||
const result = await esbuild.build({
|
|
||||||
//plugins: [NodeModulesPolyfillPlugin()],
|
|
||||||
platform: "browser",
|
|
||||||
conditions: ["worker", "browser"],
|
|
||||||
entryPoints: ["./src/index.ts"],
|
|
||||||
outdir: "dist",
|
|
||||||
external: ["__STATIC_CONTENT_MANIFEST", "cloudflare:workers"],
|
|
||||||
format: "esm",
|
|
||||||
target: "es2022",
|
|
||||||
keepNames: true,
|
|
||||||
bundle: true,
|
|
||||||
metafile: true,
|
|
||||||
minify: true,
|
|
||||||
loader: {
|
|
||||||
".html": "copy"
|
|
||||||
},
|
|
||||||
define: {
|
|
||||||
IS_CLOUDFLARE_WORKER: "true"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Bun.write("dist/meta.json", JSON.stringify(result.metafile));
|
|
||||||
await $`gzip dist/index.js -c > dist/index.js.gz`;
|
|
||||||
@@ -4,19 +4,17 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"deploy": "wrangler deploy",
|
"deploy": "wrangler deploy",
|
||||||
"db": "turso dev",
|
|
||||||
"dev": "wrangler dev",
|
"dev": "wrangler dev",
|
||||||
"start": "wrangler dev",
|
"start": "wrangler dev",
|
||||||
"test": "vitest",
|
|
||||||
"cf-typegen": "wrangler types"
|
"cf-typegen": "wrangler types"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bknd": "workspace:*",
|
"bknd": "file:../../app",
|
||||||
"kysely-d1": "^0.3.0"
|
"kysely-d1": "^0.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20241106.0",
|
"@cloudflare/workers-types": "^4.20240620.0",
|
||||||
"typescript": "^5.5.2",
|
"typescript": "^5.5.3",
|
||||||
"wrangler": "^3.86.0"
|
"wrangler": "^3.108.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#:schema node_modules/wrangler/config-schema.json
|
|
||||||
name = "bknd-cf-worker-example"
|
|
||||||
main = "src/index.ts"
|
|
||||||
compatibility_date = "2025-02-04"
|
|
||||||
compatibility_flags = ["nodejs_compat"]
|
|
||||||
workers_dev = true
|
|
||||||
minify = true
|
|
||||||
assets = { directory = "../../app/dist/static" }
|
|
||||||
|
|
||||||
[observability]
|
|
||||||
enabled = true
|
|
||||||
|
|
||||||
[[d1_databases]]
|
|
||||||
binding = "DB"
|
|
||||||
database_name = "bknd-cf-example"
|
|
||||||
database_id = "7ad67953-2bbf-47fc-8696-f4517dbfe674"
|
|
||||||
|
|
||||||
[[r2_buckets]]
|
|
||||||
binding = "BUCKET"
|
|
||||||
bucket_name = "bknd-cf-example"
|
|
||||||
@@ -3,20 +3,17 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "npm run db & next dev",
|
||||||
"db": "turso dev --db-file test.db",
|
"db": "turso dev --db-file test.db",
|
||||||
"db:check": "sqlite3 test.db \"PRAGMA wal_checkpoint(FULL);\"",
|
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "npm run db & next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bknd": "workspace:*",
|
"bknd": "file:../../app",
|
||||||
"next": "15.0.2"
|
"next": "15.0.2",
|
||||||
},
|
"react": "file:../../node_modules/react",
|
||||||
"peerDependencies": {
|
"react-dom": "file:../../node_modules/react-dom"
|
||||||
"react": ">=18",
|
|
||||||
"react-dom": ">=18"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5",
|
"typescript": "^5",
|
||||||
|
|||||||
@@ -8,10 +8,7 @@ import { serve } from "bknd/adapter/node";
|
|||||||
const config = {
|
const config = {
|
||||||
connection: {
|
connection: {
|
||||||
url: ":memory:"
|
url: ":memory:"
|
||||||
},
|
}
|
||||||
// this is only required to run inside the same workspace
|
|
||||||
// leave blank if you're running this from a different project
|
|
||||||
distPath: "../../app/dist"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
serve(config);
|
serve(config);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"dev": "tsx --watch index.js"
|
"dev": "tsx --watch index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bknd": "workspace:*",
|
"bknd": "file:../../app",
|
||||||
"@hono/node-server": "^1.13.3"
|
"@hono/node-server": "^1.13.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
"@remix-run/node": "^2.15.2",
|
"@remix-run/node": "^2.15.2",
|
||||||
"@remix-run/react": "^2.15.2",
|
"@remix-run/react": "^2.15.2",
|
||||||
"@remix-run/serve": "^2.15.2",
|
"@remix-run/serve": "^2.15.2",
|
||||||
"bknd": "workspace:*",
|
"bknd": "file:../../app",
|
||||||
"isbot": "^5.1.18",
|
"isbot": "^5.1.18",
|
||||||
"react": "^18.2.0",
|
"react": "file:../../node_modules/react",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "file:../../node_modules/react-dom",
|
||||||
"remix-utils": "^7.0.0"
|
"remix-utils": "^7.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
"workspaces": [
|
"workspaces": [
|
||||||
"app",
|
"app",
|
||||||
"docs",
|
"docs",
|
||||||
"packages/*",
|
"packages/*"
|
||||||
"examples/*"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user