@bitcobblers/wod-wiki-tools 0.0.0-stage → 0.36.2134
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/wod.cjs +3543 -0
- package/dist/bin/wod.cjs.map +1 -0
- package/dist/bin/wod.d.cts +1 -0
- package/dist/bin/wod.d.ts +1 -0
- package/dist/bin/wod.mjs +27 -0
- package/dist/bin/wod.mjs.map +1 -0
- package/dist/chunk-32FASQP5.mjs +123 -0
- package/dist/chunk-32FASQP5.mjs.map +1 -0
- package/dist/chunk-6L5ZDZJ7.mjs +15 -0
- package/dist/chunk-6L5ZDZJ7.mjs.map +1 -0
- package/dist/chunk-B3QJYJVI.mjs +2061 -0
- package/dist/chunk-B3QJYJVI.mjs.map +1 -0
- package/dist/chunk-EUQWEX6Z.mjs +253 -0
- package/dist/chunk-EUQWEX6Z.mjs.map +1 -0
- package/dist/chunk-K3GZZFAC.mjs +300 -0
- package/dist/chunk-K3GZZFAC.mjs.map +1 -0
- package/dist/compiler-KT6P3AC6.mjs +730 -0
- package/dist/compiler-KT6P3AC6.mjs.map +1 -0
- package/dist/index.cjs +3548 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +356 -0
- package/dist/index.d.ts +356 -0
- package/dist/index.mjs +12 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server/app.cjs +299 -0
- package/dist/server/app.cjs.map +1 -0
- package/dist/server/app.d.cts +24 -0
- package/dist/server/app.d.ts +24 -0
- package/dist/server/app.mjs +9 -0
- package/dist/server/app.mjs.map +1 -0
- package/dist/server-3TJZDKQC.mjs +11 -0
- package/dist/server-3TJZDKQC.mjs.map +1 -0
- package/dist/web/playground/ai-skills/parse.md +656 -0
- package/dist/web/playground/assets/main-Bhn9NHgQ.css +2 -0
- package/dist/web/playground/assets/main-Bj_mxNMk.js +212 -0
- package/dist/web/playground/assets/rolldown-runtime-C0FnF6B9.js +1 -0
- package/dist/web/playground/assets/statementBuilderFlow-DXlHS86r.js +2 -0
- package/dist/web/playground/assets/vendor-BlJqgFME.js +201 -0
- package/dist/web/playground/assets/vendor-codemirror-BtJgoBjf.js +40 -0
- package/dist/web/playground/fonts/Inter-Regular.woff2 +0 -0
- package/dist/web/playground/fonts/Inter-SemiBold.woff2 +0 -0
- package/dist/web/playground/images/hero/editing.png +0 -0
- package/dist/web/playground/images/hero/journal.png +0 -0
- package/dist/web/playground/images/hero/results.png +0 -0
- package/dist/web/playground/images/hero/timer.png +0 -0
- package/dist/web/playground/images/wod-wiki-logo-dark.png +0 -0
- package/dist/web/playground/images/wod-wiki-logo-light.png +0 -0
- package/dist/web/playground/index.html +60 -0
- package/dist/web/playground/seed/core/chunks/canvas.054cd7db.json +1 -0
- package/dist/web/playground/seed/core/chunks/template.e5e0e82d.json +1 -0
- package/dist/web/playground/seed/core/manifest.json +24 -0
- package/dist/web/playground/seed/core/report.html +43 -0
- package/dist/web/server/ai-skills/parse.md +656 -0
- package/dist/web/server/assets/main-Bhn9NHgQ.css +2 -0
- package/dist/web/server/assets/main-CfAVkURA.js +211 -0
- package/dist/web/server/assets/rolldown-runtime-C0FnF6B9.js +1 -0
- package/dist/web/server/assets/statementBuilderFlow-CXugzTXB.js +2 -0
- package/dist/web/server/assets/vendor-BlJqgFME.js +201 -0
- package/dist/web/server/assets/vendor-codemirror-BtJgoBjf.js +40 -0
- package/dist/web/server/fonts/Inter-Regular.woff2 +0 -0
- package/dist/web/server/fonts/Inter-SemiBold.woff2 +0 -0
- package/dist/web/server/images/hero/editing.png +0 -0
- package/dist/web/server/images/hero/journal.png +0 -0
- package/dist/web/server/images/hero/results.png +0 -0
- package/dist/web/server/images/hero/timer.png +0 -0
- package/dist/web/server/images/wod-wiki-logo-dark.png +0 -0
- package/dist/web/server/images/wod-wiki-logo-light.png +0 -0
- package/dist/web/server/index.html +60 -0
- package/dist/web/server/seed/core/chunks/canvas.054cd7db.json +1 -0
- package/dist/web/server/seed/core/chunks/template.e5e0e82d.json +1 -0
- package/dist/web/server/seed/core/manifest.json +24 -0
- package/dist/web/server/seed/core/report.html +43 -0
- package/package.json +46 -4
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin/wod.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { cliMain } from '../chunk-B3QJYJVI.mjs';
|
|
4
|
+
import '../chunk-EUQWEX6Z.mjs';
|
|
5
|
+
import '../chunk-6L5ZDZJ7.mjs';
|
|
6
|
+
import { spawnSync } from 'child_process';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
|
|
9
|
+
if (typeof globalThis.require === 'undefined') {
|
|
10
|
+
try { globalThis.require = createRequire(import.meta.url); } catch {}
|
|
11
|
+
}
|
|
12
|
+
var isBun = typeof globalThis.Bun !== "undefined";
|
|
13
|
+
if (!isBun) {
|
|
14
|
+
const check = spawnSync("bun", ["--version"], { stdio: "ignore" });
|
|
15
|
+
if (check.status === 0) {
|
|
16
|
+
const res = spawnSync("bun", ["--no-env-file", fileURLToPath(import.meta.url), ...process.argv.slice(2)], {
|
|
17
|
+
stdio: "inherit"
|
|
18
|
+
});
|
|
19
|
+
process.exit(res.status ?? 0);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
void (async () => {
|
|
23
|
+
const exitCode = await cliMain(process.argv.slice(2));
|
|
24
|
+
process.exitCode = exitCode;
|
|
25
|
+
})();
|
|
26
|
+
//# sourceMappingURL=wod.mjs.map
|
|
27
|
+
//# sourceMappingURL=wod.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/wod.ts"],"names":[],"mappings":";;;;;;;;;;;AAYA,IAAM,KAAA,GAAQ,OAAQ,UAAA,CAAiC,GAAA,KAAQ,WAAA;AAC/D,IAAI,CAAC,KAAA,EAAO;AAEV,EAAA,MAAM,KAAA,GAAQ,UAAU,KAAA,EAAO,CAAC,WAAW,CAAA,EAAG,EAAE,KAAA,EAAO,QAAA,EAAU,CAAA;AACjE,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,IAAA,MAAM,GAAA,GAAM,SAAA,CAAU,KAAA,EAAO,CAAC,iBAAiB,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA,EAAG,GAAG,OAAA,CAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA,EAAG;AAAA,MACxG,KAAA,EAAO;AAAA,KACR,CAAA;AACD,IAAA,OAAA,CAAQ,IAAA,CAAK,GAAA,CAAI,MAAA,IAAU,CAAC,CAAA;AAAA,EAC9B;AACF;AAIA,KAAA,CAAM,YAAY;AAChB,EAAA,MAAM,WAAW,MAAM,OAAA,CAAQ,QAAQ,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA;AACpD,EAAA,OAAA,CAAQ,QAAA,GAAW,QAAA;AACrB,CAAA,GAAG","file":"wod.mjs","sourcesContent":["#!/usr/bin/env node\n/**\n * wod CLI Entry Point\n *\n * Dispatches to cliMain(process.argv.slice(2)).\n * Runs under Node or Bun: SQLite/Postgres/Turso commands (init, parse, run,\n * query, import, export, build, seed) run on both runtimes; server/playground\n * hosting commands require Bun.\n */\nimport { spawnSync } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\n\nconst isBun = typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined';\nif (!isBun) {\n // If invoked via Node but Bun is installed, re-exec with Bun so server/playground work out of the box.\n const check = spawnSync('bun', ['--version'], { stdio: 'ignore' });\n if (check.status === 0) {\n const res = spawnSync('bun', ['--no-env-file', fileURLToPath(import.meta.url), ...process.argv.slice(2)], {\n stdio: 'inherit',\n });\n process.exit(res.status ?? 0);\n }\n}\n\nimport { cliMain } from '../cli/runner';\n\nvoid (async () => {\n const exitCode = await cliMain(process.argv.slice(2));\n process.exitCode = exitCode;\n})();\n"]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { openCliDb, nodePath, nodeFs } from './chunk-EUQWEX6Z.mjs';
|
|
3
|
+
import { createHandler } from './chunk-K3GZZFAC.mjs';
|
|
4
|
+
|
|
5
|
+
if (typeof globalThis.require === 'undefined') {
|
|
6
|
+
try { globalThis.require = createRequire(import.meta.url); } catch {}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// src/cli/server.ts
|
|
10
|
+
function bun() {
|
|
11
|
+
const b = globalThis.Bun;
|
|
12
|
+
if (!b) {
|
|
13
|
+
throw new Error("wod server/playground requires the Bun runtime (https://bun.sh)");
|
|
14
|
+
}
|
|
15
|
+
return b;
|
|
16
|
+
}
|
|
17
|
+
function moduleDir() {
|
|
18
|
+
const p = nodePath();
|
|
19
|
+
const meta = import.meta;
|
|
20
|
+
if (typeof meta.dir === "string") return p.resolve(meta.dir);
|
|
21
|
+
if (typeof meta.url === "string" && meta.url.startsWith("file:")) {
|
|
22
|
+
return p.resolve(p.dirname(decodeURIComponent(new URL(".", meta.url).pathname)));
|
|
23
|
+
}
|
|
24
|
+
throw new Error("wod server/playground: cannot determine the installed engine module directory");
|
|
25
|
+
}
|
|
26
|
+
function engineRoot() {
|
|
27
|
+
const p = nodePath();
|
|
28
|
+
const fs = nodeFs();
|
|
29
|
+
for (let dir = moduleDir(); ; dir = p.dirname(dir)) {
|
|
30
|
+
try {
|
|
31
|
+
if (JSON.parse(fs.readFileSync(p.resolve(dir, "package.json"), "utf8")).name === "@bitcobblers/wod-wiki-tools") return dir;
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
const parent = p.dirname(dir);
|
|
35
|
+
if (parent === dir) break;
|
|
36
|
+
}
|
|
37
|
+
throw new Error("wod server/playground: cannot locate the installed @bitcobblers/wod-wiki-tools package");
|
|
38
|
+
}
|
|
39
|
+
function resolveDist(mode, options) {
|
|
40
|
+
const p = nodePath();
|
|
41
|
+
const explicit = options.dist?.trim() || options.env.PLAYGROUND_DIST?.trim() || void 0;
|
|
42
|
+
if (explicit) {
|
|
43
|
+
const dist2 = p.resolve(explicit);
|
|
44
|
+
if (!nodeFs().existsSync(p.resolve(dist2, "index.html"))) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`wod ${mode}: no built frontend (index.html) at ${dist2} \u2014 --dist/PLAYGROUND_DIST must point at an already-built directory (the CLI never builds frontends at runtime)`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return dist2;
|
|
50
|
+
}
|
|
51
|
+
const dist = p.resolve(engineRoot(), "dist", "web", mode === "playground" ? "playground" : "server");
|
|
52
|
+
if (!nodeFs().existsSync(p.resolve(dist, "index.html"))) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`wod ${mode}: packaged frontend missing \u2014 expected ${dist}/index.html. Reinstall @bitcobblers/wod-wiki-tools (bun add @bitcobblers/wod-wiki-tools), or rebuild the release assets from a checkout (bun run build:cli) and reinstall the package.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return dist;
|
|
58
|
+
}
|
|
59
|
+
function resolveBind(mode, options) {
|
|
60
|
+
const host = options.host?.trim() || options.env.HOST?.trim() || "127.0.0.1";
|
|
61
|
+
const rawPort = options.port?.trim() || options.env.PORT?.trim() || "3000";
|
|
62
|
+
const port = Number(rawPort);
|
|
63
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
64
|
+
throw new Error(`wod ${mode}: invalid port ${JSON.stringify(rawPort)} (need integer 1..65535)`);
|
|
65
|
+
}
|
|
66
|
+
return { host, port };
|
|
67
|
+
}
|
|
68
|
+
async function runCliServer(mode, options, writeOut) {
|
|
69
|
+
const runtime = bun();
|
|
70
|
+
const { host, port } = resolveBind(mode, options);
|
|
71
|
+
let db;
|
|
72
|
+
let dbLabel = "no database";
|
|
73
|
+
if (mode === "server") {
|
|
74
|
+
const database = options.database;
|
|
75
|
+
if (!database) {
|
|
76
|
+
throw new Error("wod server: no database configuration resolved \u2014 this is a runner bug (expected resolveDatabaseConfig output)");
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
db = await openCliDb(database, { initialize: false });
|
|
80
|
+
} catch (e) {
|
|
81
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
82
|
+
throw new Error(`wod server: database not ready \u2014 run \`wod init\` first. ${message}`, { cause: e });
|
|
83
|
+
}
|
|
84
|
+
dbLabel = db.path;
|
|
85
|
+
}
|
|
86
|
+
let server;
|
|
87
|
+
try {
|
|
88
|
+
const dist = resolveDist(mode, options);
|
|
89
|
+
const handler = createHandler(db?.db ?? null, { playgroundDist: dist });
|
|
90
|
+
server = runtime.serve({ port, hostname: host, fetch: handler });
|
|
91
|
+
if (mode === "server") {
|
|
92
|
+
writeOut(`wod server: http://${host}:${port} \u2014 ${dbLabel} \xB7 dist ${dist}`);
|
|
93
|
+
} else {
|
|
94
|
+
writeOut(`wod playground: http://${host}:${port} \u2014 in-browser storage (no database) \xB7 dist ${dist}`);
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
if (db) await db.close();
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
let closing = false;
|
|
101
|
+
const shutdown = async () => {
|
|
102
|
+
if (closing) process.exit(0);
|
|
103
|
+
closing = true;
|
|
104
|
+
try {
|
|
105
|
+
await server.stop();
|
|
106
|
+
} finally {
|
|
107
|
+
if (db) await db.close();
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
process.on("SIGINT", () => {
|
|
112
|
+
void shutdown();
|
|
113
|
+
});
|
|
114
|
+
process.on("SIGTERM", () => {
|
|
115
|
+
void shutdown();
|
|
116
|
+
});
|
|
117
|
+
await new Promise(() => {
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { runCliServer };
|
|
122
|
+
//# sourceMappingURL=chun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AA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF,CAAA;AACA,EAAA,OAAA,CAAQ,EAAA,CAAG,UAAU,MAAM;AAAE,IAAA,KAAK,QAAA,EAAS;AAAA,EAAG,CAAC,CAAA;AAC/C,EAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,MAAM;AAAE,IAAA,KAAK,QAAA,EAAS;AAAA,EAAG,CAAC,CAAA;AAGhD,EAAA,MAAM,IAAI,QAAe,MAAM;AAAA,EAAC,CAAC,CAAA;AACnC","file":"chunk-32FASQP5.mjs","sourcesContent":["/**\n * server.ts — `wod server` (alias `serve`) / `wod playground` (Bun-only front\n * door).\n *\n * Serves the packaged engine stack: the shared fetch handler shipped in this\n * package (the same code the Docker image serves) plus the frontend build\n * packaged under the engine's dist/web/ — no repository checkout, no runtime\n * build.\n *\n * server probes the configured database first (never creates schema —\n * that's `wod init`), then serves API + SPA.\n * playground serves the browser-storage SPA build and never opens a database\n * (every /api request answers 404).\n *\n * Retains the event loop until SIGINT/SIGTERM; shutdown drains in-flight\n * requests before closing the database.\n */\n\nimport { openCliDb, nodeFs, nodePath } from './db';\nimport type { CliDatabaseConfig } from './config';\nimport type { CliDb } from './db';\nimport { createHandler } from '../server/app';\ntype WriteOut = (text: string) => void;\n\nexport type CliServerMode = 'server' | 'playground';\n\nexport interface CliServerOptions {\n /** Resolved database configuration. REQUIRED for 'server'; ignored — never\n * opened or validated — for 'playground'. */\n database?: CliDatabaseConfig;\n host?: string;\n port?: string;\n /** Explicit dist directory (flag or PLAYGROUND_DIST); must already exist. */\n dist?: string;\n /** Merged CLI environment (process env + .env). */\n env: Record<string, string | undefined>;\n}\n\ninterface BunServerLike { stop(): Promise<void> }\ninterface BunGlobalLike { serve(options: { port: number; hostname: string; fetch: (request: Request) => Promise<Response> }): BunServerLike }\n\nfunction bun(): BunGlobalLike {\n // Bun-specific global, absent from the ambient TS lib shapes on purpose\n // (engine stays Node-compilable); the access chain is proven at runtime.\n const b = (globalThis as { Bun?: BunGlobalLike }).Bun;\n if (!b) {\n throw new Error('wod server/playground requires the Bun runtime (https://bun.sh)');\n }\n return b;\n}\n\n/**\n * This module's directory, robust across shipped layouts: ESM via\n * import.meta.url (works under node and Bun; esbuild shims it in CJS too) and\n * Bun's import.meta.dir. ESM code splitting may relocate this module to a\n * chunk at dist/ root, so never assume dist/cli.\n */\nfunction moduleDir(): string {\n const p = nodePath();\n const meta: { dir?: unknown; url?: unknown } = import.meta; // Bun adds `dir`; the TS lib knows neither.\n if (typeof meta.dir === 'string') return p.resolve(meta.dir);\n if (typeof meta.url === 'string' && meta.url.startsWith('file:')) {\n return p.resolve(p.dirname(decodeURIComponent(new URL('.', meta.url).pathname)));\n }\n throw new Error('wod server/playground: cannot determine the installed engine module directory');\n}\n\n/**\n * The installed engine package root: nearest enclosing package.json belonging\n * to this package, walking up from the executing module (dist/cli, a split\n * chunk at dist/ root, dist/bin, or src/cli in a checkout).\n */\nfunction engineRoot(): string {\n const p = nodePath();\n const fs = nodeFs();\n for (let dir = moduleDir(); ; dir = p.dirname(dir)) {\n try {\n if (JSON.parse(fs.readFileSync(p.resolve(dir, 'package.json'), 'utf8')).name === '@bitcobblers/wod-wiki-tools') return dir;\n } catch { /* no manifest here — keep walking */ }\n const parent = p.dirname(dir);\n if (parent === dir) break;\n }\n throw new Error('wod server/playground: cannot locate the installed @bitcobblers/wod-wiki-tools package');\n}\n\n/**\n * Resolve the frontend dist directory. The packaged default lives inside the\n * installed engine module (dist/web/server or dist/web/playground); an\n * explicit --dist/PLAYGROUND_DIST is cwd-relative and must already contain a\n * built SPA (index.html). Nothing is built at runtime.\n */\nfunction resolveDist(mode: CliServerMode, options: CliServerOptions): string {\n const p = nodePath();\n const explicit = options.dist?.trim() || options.env.PLAYGROUND_DIST?.trim() || undefined;\n if (explicit) {\n const dist = p.resolve(explicit); // cwd-relative override\n if (!nodeFs().existsSync(p.resolve(dist, 'index.html'))) {\n throw new Error(\n `wod ${mode}: no built frontend (index.html) at ${dist} — --dist/PLAYGROUND_DIST must `\n + 'point at an already-built directory (the CLI never builds frontends at runtime)',\n );\n }\n return dist;\n }\n const dist = p.resolve(engineRoot(), 'dist', 'web', mode === 'playground' ? 'playground' : 'server');\n if (!nodeFs().existsSync(p.resolve(dist, 'index.html'))) {\n throw new Error(\n `wod ${mode}: packaged frontend missing — expected ${dist}/index.html. `\n + 'Reinstall @bitcobblers/wod-wiki-tools (bun add @bitcobblers/wod-wiki-tools), '\n + 'or rebuild the release assets from a checkout (bun run build:cli) and reinstall the package.',\n );\n }\n return dist;\n}\n\n/** Validate bind address first: flag > HOST/PORT env > loopback:3000. */\nfunction resolveBind(mode: CliServerMode, options: CliServerOptions): { host: string; port: number } {\n const host = options.host?.trim() || options.env.HOST?.trim() || '127.0.0.1';\n const rawPort = options.port?.trim() || options.env.PORT?.trim() || '3000';\n const port = Number(rawPort);\n if (!Number.isInteger(port) || port < 1 || port > 65535) {\n throw new Error(`wod ${mode}: invalid port ${JSON.stringify(rawPort)} (need integer 1..65535)`);\n }\n return { host, port };\n}\n\n/**\n * Start the shared server for `wod server` / `wod playground`. Throws on any\n * startup failure; on success it never returns until SIGINT/SIGTERM (drain,\n * close database, exit 0).\n */\nexport async function runCliServer(\n mode: CliServerMode,\n options: CliServerOptions,\n writeOut: WriteOut,\n): Promise<void> {\n const runtime = bun(); // Fail before any side effect when not under Bun.\n const { host, port } = resolveBind(mode, options); // Validate bind before opening anything.\n\n // Server probes the database BEFORE binding a socket: a missing/uninitialized\n // database refuses with `wod init` guidance.\n let db: CliDb | undefined;\n let dbLabel = 'no database';\n if (mode === 'server') {\n const database = options.database; // hoisted so the guard's narrowing sticks\n if (!database) {\n throw new Error('wod server: no database configuration resolved — this is a runner bug (expected resolveDatabaseConfig output)');\n }\n try {\n db = await openCliDb(database, { initialize: false });\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n throw new Error(`wod server: database not ready — run \\`wod init\\` first. ${message}`, { cause: e });\n }\n dbLabel = db.path;\n }\n\n let server: BunServerLike;\n try {\n const dist = resolveDist(mode, options);\n // Bundled server handler\n const handler = createHandler(db?.db ?? null, { playgroundDist: dist });\n // Playground: no database exists to close — createHandler(null) answers\n server = runtime.serve({ port, hostname: host, fetch: handler });\n if (mode === 'server') {\n writeOut(`wod server: http://${host}:${port} — ${dbLabel} · dist ${dist}`);\n } else {\n writeOut(`wod playground: http://${host}:${port} — in-browser storage (no database) · dist ${dist}`);\n }\n } catch (e) {\n if (db) await db.close(); // never leak the probe connection when startup fails\n throw e;\n }\n\n let closing = false;\n const shutdown = async (): Promise<void> => {\n if (closing) process.exit(0); // second signal forces the exit\n closing = true;\n try {\n await server.stop();\n } finally {\n if (db) await db.close();\n process.exit(0);\n }\n };\n process.on('SIGINT', () => { void shutdown(); });\n process.on('SIGTERM', () => { void shutdown(); });\n\n // Park until a signal handler exits the process.\n await new Promise<never>(() => {});\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
|
|
3
|
+
if (typeof globalThis.require === 'undefined') {
|
|
4
|
+
try { globalThis.require = createRequire(import.meta.url); } catch {}
|
|
5
|
+
}
|
|
6
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
7
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
8
|
+
}) : x)(function(x) {
|
|
9
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
10
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export { __require };
|
|
14
|
+
//# sourceMappingURL=chunk-6L5ZDZJ7.mjs.map
|
|
15
|
+
//# sourceMappingURL=chunk-6L5ZDZJ7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-6L5ZDZJ7.mjs"}
|