mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
cli now uses adapter logic, require node v22
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/bknd-io/bknd/issues"
|
"url": "https://github.com/bknd-io/bknd/issues"
|
||||||
},
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "BKND_CLI_LOG_LEVEL=debug vite",
|
"dev": "BKND_CLI_LOG_LEVEL=debug vite",
|
||||||
"build": "NODE_ENV=production bun run build.ts --minify --types",
|
"build": "NODE_ENV=production bun run build.ts --minify --types",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { Config } from "@libsql/client/node";
|
import { $console } from "core";
|
||||||
import { $console, config } from "core";
|
|
||||||
import type { MiddlewareHandler } from "hono";
|
import type { MiddlewareHandler } from "hono";
|
||||||
import open from "open";
|
import open from "open";
|
||||||
import { fileExists, getRelativeDistPath } from "../../utils/sys";
|
import { fileExists, getRelativeDistPath } from "../../utils/sys";
|
||||||
@@ -27,10 +26,6 @@ export async function serveStatic(server: Platform): Promise<MiddlewareHandler>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function attachServeStatic(app: any, platform: Platform) {
|
|
||||||
app.module.server.client.get(config.server.assets_path + "*", await serveStatic(platform));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function startServer(
|
export async function startServer(
|
||||||
server: Platform,
|
server: Platform,
|
||||||
app: App,
|
app: App,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Config } from "@libsql/client/node";
|
import type { Config } from "@libsql/client/node";
|
||||||
import { App, type CreateAppConfig } from "App";
|
import type { App, CreateAppConfig } from "App";
|
||||||
import { StorageLocalAdapter } from "adapter/node";
|
import { StorageLocalAdapter } from "adapter/node/storage";
|
||||||
import type { CliBkndConfig, CliCommand } from "cli/types";
|
import type { CliBkndConfig, CliCommand } from "cli/types";
|
||||||
import { Option } from "commander";
|
import { Option } from "commander";
|
||||||
import { colorizeConsole, config } from "core";
|
import { colorizeConsole, config } from "core";
|
||||||
@@ -11,19 +11,19 @@ import path from "node:path";
|
|||||||
import {
|
import {
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
type Platform,
|
type Platform,
|
||||||
attachServeStatic,
|
|
||||||
getConfigPath,
|
getConfigPath,
|
||||||
getConnectionCredentialsFromEnv,
|
getConnectionCredentialsFromEnv,
|
||||||
|
serveStatic,
|
||||||
startServer,
|
startServer,
|
||||||
} from "./platform";
|
} from "./platform";
|
||||||
import { makeConfig } from "adapter";
|
import { createRuntimeApp, makeConfig } from "adapter";
|
||||||
import { isBun as $isBun } from "cli/utils/sys";
|
import { isBun } from "core/utils";
|
||||||
|
|
||||||
const env_files = [".env", ".dev.vars"];
|
const env_files = [".env", ".dev.vars"];
|
||||||
dotenv.config({
|
dotenv.config({
|
||||||
path: env_files.map((file) => path.resolve(process.cwd(), file)),
|
path: env_files.map((file) => path.resolve(process.cwd(), file)),
|
||||||
});
|
});
|
||||||
const isBun = $isBun();
|
const is_bun = isBun();
|
||||||
|
|
||||||
export const run: CliCommand = (program) => {
|
export const run: CliCommand = (program) => {
|
||||||
program
|
program
|
||||||
@@ -52,7 +52,7 @@ export const run: CliCommand = (program) => {
|
|||||||
.addOption(
|
.addOption(
|
||||||
new Option("--server <server>", "server type")
|
new Option("--server <server>", "server type")
|
||||||
.choices(PLATFORMS)
|
.choices(PLATFORMS)
|
||||||
.default(isBun ? "bun" : "node"),
|
.default(is_bun ? "bun" : "node"),
|
||||||
)
|
)
|
||||||
.addOption(new Option("--no-open", "don't open browser window on start"))
|
.addOption(new Option("--no-open", "don't open browser window on start"))
|
||||||
.action(action);
|
.action(action);
|
||||||
@@ -72,23 +72,9 @@ type MakeAppConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function makeApp(config: MakeAppConfig) {
|
async function makeApp(config: MakeAppConfig) {
|
||||||
const app = App.create({ connection: config.connection });
|
return await createRuntimeApp({
|
||||||
|
serveStatic: await serveStatic(config.server?.platform ?? "node"),
|
||||||
app.emgr.onEvent(
|
});
|
||||||
App.Events.AppBuiltEvent,
|
|
||||||
async () => {
|
|
||||||
if (config.onBuilt) {
|
|
||||||
await config.onBuilt(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
await attachServeStatic(app, config.server?.platform ?? "node");
|
|
||||||
app.registerAdminController();
|
|
||||||
},
|
|
||||||
"sync",
|
|
||||||
);
|
|
||||||
|
|
||||||
await app.build();
|
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function makeConfigApp(_config: CliBkndConfig, platform?: Platform) {
|
export async function makeConfigApp(_config: CliBkndConfig, platform?: Platform) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type { CliCommand } from "cli/types";
|
|||||||
import { Argument } from "commander";
|
import { Argument } from "commander";
|
||||||
import { $console } from "core";
|
import { $console } from "core";
|
||||||
import c from "picocolors";
|
import c from "picocolors";
|
||||||
import { isBun } from "cli/utils/sys";
|
import { isBun } from "core/utils";
|
||||||
|
|
||||||
export const user: CliCommand = (program) => {
|
export const user: CliCommand = (program) => {
|
||||||
program
|
program
|
||||||
|
|||||||
@@ -4,14 +4,6 @@ import { readFile, writeFile as nodeWriteFile } from "node:fs/promises";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import url from "node:url";
|
import url from "node:url";
|
||||||
|
|
||||||
export function isBun(): boolean {
|
|
||||||
try {
|
|
||||||
return typeof Bun !== "undefined";
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRootPath() {
|
export function getRootPath() {
|
||||||
const _path = path.dirname(url.fileURLToPath(import.meta.url));
|
const _path = path.dirname(url.fileURLToPath(import.meta.url));
|
||||||
// because of "src", local needs one more level up
|
// because of "src", local needs one more level up
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ export class SchemaManager {
|
|||||||
|
|
||||||
if (config.force) {
|
if (config.force) {
|
||||||
try {
|
try {
|
||||||
$console.log("[SchemaManager]", sql);
|
$console.debug("[SchemaManager]", sql);
|
||||||
await qb.execute();
|
await qb.execute();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Failed to execute query: ${sql}: ${(e as any).message}`);
|
throw new Error(`Failed to execute query: ${sql}: ${(e as any).message}`);
|
||||||
|
|||||||
22
package.json
22
package.json
@@ -4,14 +4,7 @@
|
|||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "ALL_TESTS=1 bun test --bail",
|
|
||||||
"test:coverage": "bun test --coverage",
|
|
||||||
"types": "bun run --filter './packages/**' types",
|
|
||||||
"build": "bun run clean:dist && bun run --cwd app build:all && bun build:packages",
|
|
||||||
"build:packages": "bun run --filter './packages/{cli,plasmic}' build",
|
|
||||||
"git:pre-commit": "bun run test",
|
|
||||||
"updater": "bun x npm-check-updates -ui",
|
"updater": "bun x npm-check-updates -ui",
|
||||||
"clean:dist": "find packages -name 'dist' -type d -exec rm -rf {} +",
|
|
||||||
"ci": "find . -name 'node_modules' -type d -exec rm -rf {} + && bun install",
|
"ci": "find . -name 'node_modules' -type d -exec rm -rf {} + && bun install",
|
||||||
"npm:local": "verdaccio --config verdaccio.yml",
|
"npm:local": "verdaccio --config verdaccio.yml",
|
||||||
"format": "bunx biome format --write ./app",
|
"format": "bunx biome format --write ./app",
|
||||||
@@ -20,26 +13,15 @@
|
|||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
"@clack/prompts": "^0.10.0",
|
|
||||||
"@tsconfig/strictest": "^2.0.5",
|
"@tsconfig/strictest": "^2.0.5",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"bun-types": "^1.1.18",
|
"bun-types": "^1.1.18",
|
||||||
"dotenv": "^16.4.5",
|
|
||||||
"esbuild": "^0.23.0",
|
|
||||||
"esbuild-plugin-tsc": "^0.4.0",
|
|
||||||
"miniflare": "^3.20240806.0",
|
"miniflare": "^3.20240806.0",
|
||||||
"mitata": "^0.1.11",
|
|
||||||
"picocolors": "^1.0.1",
|
|
||||||
"semver": "^7.6.2",
|
|
||||||
"sql-formatter": "^15.3.2",
|
|
||||||
"tsd": "^0.31.1",
|
|
||||||
"tsup": "^8.1.0",
|
|
||||||
"typescript": "^5.5.3",
|
"typescript": "^5.5.3",
|
||||||
"verdaccio": "^5.32.1",
|
"verdaccio": "^5.32.1"
|
||||||
"wrangler": "^3.108.1"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.0.0"
|
"node": ">=22"
|
||||||
},
|
},
|
||||||
"workspaces": ["app", "packages/*"]
|
"workspaces": ["app", "packages/*"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user