Merge remote-tracking branch 'origin/release/0.11' into feat/init-e2e

This commit is contained in:
dswbx
2025-04-03 09:18:09 +02:00
5 changed files with 45 additions and 31 deletions
+7 -5
View File
@@ -8,7 +8,7 @@ import { Option } from "commander";
import { env } from "core"; import { env } from "core";
import color from "picocolors"; import color from "picocolors";
import { overridePackageJson, updateBkndPackages } from "./npm"; import { overridePackageJson, updateBkndPackages } from "./npm";
import { type Template, templates } from "./templates"; import { type Template, templates, type TemplateSetupCtx } from "./templates";
import { createScoped, flush } from "cli/utils/telemetry"; import { createScoped, flush } from "cli/utils/telemetry";
const config = { const config = {
@@ -35,6 +35,8 @@ export const create: CliCommand = (program) => {
.addOption(new Option("-i, --integration <integration>", "integration to use")) .addOption(new Option("-i, --integration <integration>", "integration to use"))
.addOption(new Option("-t, --template <template>", "template to use")) .addOption(new Option("-t, --template <template>", "template to use"))
.addOption(new Option("-d --dir <directory>", "directory to create in")) .addOption(new Option("-d --dir <directory>", "directory to create in"))
.addOption(new Option("-c, --clean", "cleans destination directory"))
.addOption(new Option("-y, --yes", "use defaults, skip skippable prompts"))
.description("create a new project") .description("create a new project")
.action(action); .action(action);
}; };
@@ -53,7 +55,7 @@ async function onExit() {
await flush(); await flush();
} }
async function action(options: { template?: string; dir?: string; integration?: string }) { async function action(options: { template?: string; dir?: string; integration?: string, yes?: boolean, clean?: boolean }) {
console.log(""); console.log("");
const $t = createScoped("create"); const $t = createScoped("create");
$t.capture("start", { $t.capture("start", {
@@ -94,7 +96,7 @@ async function action(options: { template?: string; dir?: string; integration?:
$t.properties.at = "dir"; $t.properties.at = "dir";
if (fs.existsSync(downloadOpts.dir)) { if (fs.existsSync(downloadOpts.dir)) {
const clean = await $p.confirm({ const clean = options.clean ?? await $p.confirm({
message: `Directory ${color.cyan(downloadOpts.dir)} exists. Clean it?`, message: `Directory ${color.cyan(downloadOpts.dir)} exists. Clean it?`,
initialValue: false, initialValue: false,
}); });
@@ -203,7 +205,7 @@ async function action(options: { template?: string; dir?: string; integration?:
} }
$t.properties.template = template.key; $t.properties.template = template.key;
const ctx = { template, dir: downloadOpts.dir, name }; const ctx: TemplateSetupCtx = { template, dir: downloadOpts.dir, name, skip: !!options.yes };
{ {
const ref = env("cli_create_ref", `#v${version}`, { const ref = env("cli_create_ref", `#v${version}`, {
@@ -259,7 +261,7 @@ async function action(options: { template?: string; dir?: string; integration?:
$p.log.success(`Updated package name to ${color.cyan(ctx.name)}`); $p.log.success(`Updated package name to ${color.cyan(ctx.name)}`);
{ {
const install = await $p.confirm({ const install = options.yes ?? await $p.confirm({
message: "Install dependencies?", message: "Install dependencies?",
}); });
@@ -29,7 +29,7 @@ export const cloudflare = {
{ dir: ctx.dir }, { dir: ctx.dir },
); );
const db = await $p.select({ const db = ctx.skip ? "d1" : await $p.select({
message: "What database do you want to use?", message: "What database do you want to use?",
options: [ options: [
{ label: "Cloudflare D1", value: "d1" }, { label: "Cloudflare D1", value: "d1" },
@@ -63,10 +63,11 @@ export const cloudflare = {
} as const satisfies Template; } as const satisfies Template;
async function createD1(ctx: TemplateSetupCtx) { async function createD1(ctx: TemplateSetupCtx) {
const name = await $p.text({ const default_db = "data";
const name = ctx.skip ? default_db : await $p.text({
message: "Enter database name", message: "Enter database name",
initialValue: "data", initialValue: default_db,
placeholder: "data", placeholder: default_db,
validate: (v) => { validate: (v) => {
if (!v) { if (!v) {
return "Invalid name"; return "Invalid name";
@@ -84,12 +85,15 @@ async function createD1(ctx: TemplateSetupCtx) {
})(), })(),
); );
exec(`npx wrangler d1 create ${name}`); if (!ctx.skip) {
await $p.stream.info( exec(`npx wrangler d1 create ${name}`);
(async function* () {
yield* typewriter("Please update your wrangler configuration with the output above."); await $p.stream.info(
})(), (async function* () {
); yield* typewriter("Please update your wrangler configuration with the output above.");
})(),
);
}
await overrideJson( await overrideJson(
WRANGLER_FILE, WRANGLER_FILE,
@@ -149,7 +153,7 @@ async function createLibsql(ctx: TemplateSetupCtx) {
} }
async function createR2(ctx: TemplateSetupCtx) { async function createR2(ctx: TemplateSetupCtx) {
const create = await $p.confirm({ const create = ctx.skip ?? await $p.confirm({
message: "Do you want to use a R2 bucket?", message: "Do you want to use a R2 bucket?",
initialValue: true, initialValue: true,
}); });
@@ -168,10 +172,11 @@ async function createR2(ctx: TemplateSetupCtx) {
return; return;
} }
const name = await $p.text({ const default_bucket = "bucket";
const name = ctx.skip ? default_bucket : await $p.text({
message: "Enter bucket name", message: "Enter bucket name",
initialValue: "bucket", initialValue: default_bucket,
placeholder: "bucket", placeholder: default_bucket,
validate: (v) => { validate: (v) => {
if (!v) { if (!v) {
return "Invalid name"; return "Invalid name";
@@ -183,7 +188,9 @@ async function createR2(ctx: TemplateSetupCtx) {
process.exit(1); process.exit(1);
} }
exec(`npx wrangler r2 bucket create ${name}`); if (!ctx.skip) {
exec(`npx wrangler r2 bucket create ${name}`);
}
await overrideJson( await overrideJson(
WRANGLER_FILE, WRANGLER_FILE,
@@ -4,6 +4,7 @@ export type TemplateSetupCtx = {
template: Template; template: Template;
dir: string; dir: string;
name: string; name: string;
skip: boolean;
}; };
export type Integration = export type Integration =
+5 -1
View File
@@ -3,8 +3,12 @@ FROM node:20 as builder
WORKDIR /app WORKDIR /app
# define bknd version to be used as:
# `docker build --build-arg VERSION=<version> -t bknd .`
ARG VERSION=0.10.2
# Install & copy required cli # Install & copy required cli
RUN npm install --omit=dev bknd@0.9.1 RUN npm install --omit=dev bknd@${VERSION}
RUN mkdir /output && cp -r node_modules/bknd/dist /output/dist RUN mkdir /output && cp -r node_modules/bknd/dist /output/dist
# Stage 2: Final minimal image # Stage 2: Final minimal image
+10 -10
View File
@@ -4,12 +4,9 @@ description: 'Official docker image for bknd'
--- ---
# Official `bknd` Docker image # Official `bknd` Docker image
The docker image intentially doesn't copy any data into the image for now, so you can copy the The docker image intentially doesn't copy any data into the image for now, so you can copy the Dockerfile and build the image anywhere.
Dockerfile and build the image anywhere.
Locate the Dockerfile either by pulling the [repository](https://github.com/bknd-io/bknd) and navigating to the `docker` Locate the Dockerfile either by pulling the [repository](https://github.com/bknd-io/bknd) and navigating to the `docker` directory, or download from [here](https://github.com/bknd-io/bknd/blob/main/docker/Dockerfile).
directory,
or download from [here](https://github.com/bknd-io/bknd/blob/main/docker/Dockerfile).
## Building the Docker image ## Building the Docker image
To build the Docker image, run the following command: To build the Docker image, run the following command:
@@ -18,6 +15,13 @@ To build the Docker image, run the following command:
docker build -t bknd . docker build -t bknd .
``` ```
If you want to override the bknd version used, you can pass a `VERSION` build argument:
```bash
docker build --build-arg VERSION=<version> -t bknd .
````
```bash
## Running the Docker container ## Running the Docker container
To run the Docker container, run the following command: To run the Docker container, run the following command:
@@ -25,11 +29,7 @@ To run the Docker container, run the following command:
docker run -p 1337:1337 bknd docker run -p 1337:1337 bknd
``` ```
You can pass the same CLI arguments (see [Using the CLI](https://docs.bknd.io/cli) guide) to the You can pass the same CLI arguments (see [Using the CLI](https://docs.bknd.io/cli) guide) to the docker container as you'd do with `npx bknd run`, like so:
docker container as you'd do with
`npx bknd
run`,
like so:
```bash ```bash
docker run -p 1337:1337 -e ARGS="--db-url file:/data/data.db" bknd docker run -p 1337:1337 -e ARGS="--db-url file:/data/data.db" bknd