mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
cli now uses adapter logic, require node v22
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import path from "node:path";
|
||||
import type { Config } from "@libsql/client/node";
|
||||
import { $console, config } from "core";
|
||||
import { $console } from "core";
|
||||
import type { MiddlewareHandler } from "hono";
|
||||
import open from "open";
|
||||
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(
|
||||
server: Platform,
|
||||
app: App,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Config } from "@libsql/client/node";
|
||||
import { App, type CreateAppConfig } from "App";
|
||||
import { StorageLocalAdapter } from "adapter/node";
|
||||
import type { App, CreateAppConfig } from "App";
|
||||
import { StorageLocalAdapter } from "adapter/node/storage";
|
||||
import type { CliBkndConfig, CliCommand } from "cli/types";
|
||||
import { Option } from "commander";
|
||||
import { colorizeConsole, config } from "core";
|
||||
@@ -11,19 +11,19 @@ import path from "node:path";
|
||||
import {
|
||||
PLATFORMS,
|
||||
type Platform,
|
||||
attachServeStatic,
|
||||
getConfigPath,
|
||||
getConnectionCredentialsFromEnv,
|
||||
serveStatic,
|
||||
startServer,
|
||||
} from "./platform";
|
||||
import { makeConfig } from "adapter";
|
||||
import { isBun as $isBun } from "cli/utils/sys";
|
||||
import { createRuntimeApp, makeConfig } from "adapter";
|
||||
import { isBun } from "core/utils";
|
||||
|
||||
const env_files = [".env", ".dev.vars"];
|
||||
dotenv.config({
|
||||
path: env_files.map((file) => path.resolve(process.cwd(), file)),
|
||||
});
|
||||
const isBun = $isBun();
|
||||
const is_bun = isBun();
|
||||
|
||||
export const run: CliCommand = (program) => {
|
||||
program
|
||||
@@ -52,7 +52,7 @@ export const run: CliCommand = (program) => {
|
||||
.addOption(
|
||||
new Option("--server <server>", "server type")
|
||||
.choices(PLATFORMS)
|
||||
.default(isBun ? "bun" : "node"),
|
||||
.default(is_bun ? "bun" : "node"),
|
||||
)
|
||||
.addOption(new Option("--no-open", "don't open browser window on start"))
|
||||
.action(action);
|
||||
@@ -72,23 +72,9 @@ type MakeAppConfig = {
|
||||
};
|
||||
|
||||
async function makeApp(config: MakeAppConfig) {
|
||||
const app = App.create({ connection: config.connection });
|
||||
|
||||
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;
|
||||
return await createRuntimeApp({
|
||||
serveStatic: await serveStatic(config.server?.platform ?? "node"),
|
||||
});
|
||||
}
|
||||
|
||||
export async function makeConfigApp(_config: CliBkndConfig, platform?: Platform) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { CliCommand } from "cli/types";
|
||||
import { Argument } from "commander";
|
||||
import { $console } from "core";
|
||||
import c from "picocolors";
|
||||
import { isBun } from "cli/utils/sys";
|
||||
import { isBun } from "core/utils";
|
||||
|
||||
export const user: CliCommand = (program) => {
|
||||
program
|
||||
|
||||
@@ -4,14 +4,6 @@ import { readFile, writeFile as nodeWriteFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import url from "node:url";
|
||||
|
||||
export function isBun(): boolean {
|
||||
try {
|
||||
return typeof Bun !== "undefined";
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function getRootPath() {
|
||||
const _path = path.dirname(url.fileURLToPath(import.meta.url));
|
||||
// because of "src", local needs one more level up
|
||||
|
||||
Reference in New Issue
Block a user