Merge pull request #84 from bknd-io/feat/debug-routes

added deboug routes cli action
This commit is contained in:
dswbx
2025-02-18 10:21:17 +01:00
committed by GitHub
4 changed files with 48 additions and 13 deletions

View File

@@ -106,8 +106,6 @@ export class App {
await this.emgr.emit(new AppBuiltEvent({ app: this }));
server.all("/api/*", async (c) => c.notFound());
// first boot is set from ModuleManager when there wasn't a config table
if (this.trigger_first_boot) {
this.trigger_first_boot = false;

View File

@@ -1,20 +1,45 @@
import path from "node:path";
import url from "node:url";
import { createApp } from "App";
import { getConnectionCredentialsFromEnv } from "cli/commands/run/platform";
import { getDistPath, getRelativeDistPath, getRootPath } from "cli/utils/sys";
import { Argument } from "commander";
import { showRoutes } from "hono/dev";
import type { CliCommand } from "../types";
export const debug: CliCommand = (program) => {
program
.command("debug")
.description("debug path resolution")
.action(() => {
console.log("paths", {
rootpath: getRootPath(),
distPath: getDistPath(),
relativeDistPath: getRelativeDistPath(),
cwd: process.cwd(),
dir: path.dirname(url.fileURLToPath(import.meta.url)),
resolvedPkg: path.resolve(getRootPath(), "package.json")
});
});
.description("debug bknd")
.addArgument(new Argument("<subject>", "subject to debug").choices(Object.keys(subjects)))
.action(action);
};
const subjects = {
paths: async () => {
console.log("[PATHS]", {
rootpath: getRootPath(),
distPath: getDistPath(),
relativeDistPath: getRelativeDistPath(),
cwd: process.cwd(),
dir: path.dirname(url.fileURLToPath(import.meta.url)),
resolvedPkg: path.resolve(getRootPath(), "package.json")
});
},
routes: async () => {
console.log("[APP ROUTES]");
const credentials = getConnectionCredentialsFromEnv();
const app = createApp({ connection: credentials });
await app.build();
showRoutes(app.server);
}
};
async function action(subject: string) {
console.log("debug", { subject });
if (subject in subjects) {
await subjects[subject]();
} else {
console.error("Invalid subject: ", subject);
}
}

View File

@@ -63,6 +63,8 @@ export class AppFlows extends Module<typeof flowsConfigSchema> {
});
});
hono.all("*", (c) => c.notFound());
this.ctx.server.route(this.config.basepath, hono);
// register flows