mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-19 05:46:04 +00:00
added a few initial plugins
This commit is contained in:
18
app/src/plugins/dev/show-routes.plugin.ts
Normal file
18
app/src/plugins/dev/show-routes.plugin.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { App, AppPlugin } from "bknd";
|
||||
import { showRoutes as showRoutesHono } from "hono/dev";
|
||||
|
||||
export type ShowRoutesOptions = {
|
||||
once?: boolean;
|
||||
};
|
||||
|
||||
export function showRoutes({ once = false }: ShowRoutesOptions = {}): AppPlugin {
|
||||
let shown = false;
|
||||
return (app: App) => ({
|
||||
name: "bknd-show-routes",
|
||||
onBuilt: () => {
|
||||
if (once && shown) return;
|
||||
shown = true;
|
||||
showRoutesHono(app.server);
|
||||
},
|
||||
});
|
||||
}
|
||||
35
app/src/plugins/dev/sync-config.plugin.ts
Normal file
35
app/src/plugins/dev/sync-config.plugin.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { App, type AppConfig, type AppPlugin } from "bknd";
|
||||
|
||||
export type SyncConfigOptions = {
|
||||
enabled?: boolean;
|
||||
includeSecrets?: boolean;
|
||||
write: (config: AppConfig) => Promise<void>;
|
||||
};
|
||||
|
||||
export function syncConfig({
|
||||
enabled = true,
|
||||
includeSecrets = false,
|
||||
write,
|
||||
}: SyncConfigOptions): AppPlugin {
|
||||
let firstBoot = true;
|
||||
return (app: App) => ({
|
||||
name: "bknd-sync-config",
|
||||
onBuilt: async () => {
|
||||
if (!enabled) return;
|
||||
app.emgr.onEvent(
|
||||
App.Events.AppConfigUpdatedEvent,
|
||||
async () => {
|
||||
await write?.(app.toJSON(includeSecrets));
|
||||
},
|
||||
{
|
||||
id: "sync-config",
|
||||
},
|
||||
);
|
||||
|
||||
if (firstBoot) {
|
||||
firstBoot = false;
|
||||
await write?.(app.toJSON(true));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
31
app/src/plugins/dev/sync-types.plugin.ts
Normal file
31
app/src/plugins/dev/sync-types.plugin.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { App, type AppPlugin } from "bknd";
|
||||
import { EntityTypescript } from "data/entities/EntityTypescript";
|
||||
|
||||
export type SyncTypesOptions = {
|
||||
enabled?: boolean;
|
||||
write: (et: EntityTypescript) => Promise<void>;
|
||||
};
|
||||
|
||||
export function syncTypes({ enabled = true, write }: SyncTypesOptions): AppPlugin {
|
||||
let firstBoot = true;
|
||||
return (app: App) => ({
|
||||
name: "bknd-sync-types",
|
||||
onBuilt: async () => {
|
||||
if (!enabled) return;
|
||||
app.emgr.onEvent(
|
||||
App.Events.AppConfigUpdatedEvent,
|
||||
async () => {
|
||||
await write?.(new EntityTypescript(app.em));
|
||||
},
|
||||
{
|
||||
id: "sync-types",
|
||||
},
|
||||
);
|
||||
|
||||
if (firstBoot) {
|
||||
firstBoot = false;
|
||||
await write?.(new EntityTypescript(app.em));
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user