@velajs/cli 0.3.1 → 0.3.2

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/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Type, VelaApplication } from '@velajs/vela';
1
+ import { Type, VelaApplication } from "@velajs/vela";
2
+ //#region src/config.d.ts
2
3
  /**
3
4
  * A `vela.config.{js,mjs,ts}` default-exports (or exports `config`) this shape.
4
5
  * You wire your runtime bindings inside `createApp` — e.g. via miniflare for a
@@ -15,19 +16,22 @@ import type { Type, VelaApplication } from '@velajs/vela';
15
16
  * });
16
17
  * ```
17
18
  */
18
- export interface VelaConfig {
19
- createApp(): Promise<VelaApplication> | VelaApplication;
20
- /**
21
- * The app's root module class — needed only by commands that work from
22
- * module metadata rather than the built app (`vela openapi dump`).
23
- */
24
- rootModule?: Type;
19
+ interface VelaConfig {
20
+ createApp(): Promise<VelaApplication> | VelaApplication;
21
+ /**
22
+ * The app's root module class — needed only by commands that work from
23
+ * module metadata rather than the built app (`vela openapi dump`).
24
+ */
25
+ rootModule?: Type;
25
26
  }
26
27
  /** Identity helper for type-safe config files. */
27
- export declare function defineVelaConfig(config: VelaConfig): VelaConfig;
28
+ declare function defineVelaConfig(config: VelaConfig): VelaConfig;
28
29
  /**
29
30
  * Locate + import the vela config. `.ts` requires a runtime that strips types
30
31
  * (Node 22+ `--experimental-strip-types`, or tsx/ts-node); `.js`/`.mjs` load
31
32
  * directly.
32
33
  */
33
- export declare function loadConfig(cwd?: string, explicitPath?: string): Promise<VelaConfig>;
34
+ declare function loadConfig(cwd?: string, explicitPath?: string): Promise<VelaConfig>;
35
+ //#endregion
36
+ export { VelaConfig, defineVelaConfig, loadConfig };
37
+ //# sourceMappingURL=config.d.ts.map
package/dist/config.js CHANGED
@@ -1,42 +1,39 @@
1
- import { access } from 'node:fs/promises';
2
- import { isAbsolute, join, resolve } from 'node:path';
3
- import { pathToFileURL } from 'node:url';
1
+ import { access } from "node:fs/promises";
2
+ import { isAbsolute, join, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ //#region src/config.ts
4
5
  /** Identity helper for type-safe config files. */
5
- export function defineVelaConfig(config) {
6
- return config;
6
+ function defineVelaConfig(config) {
7
+ return config;
7
8
  }
8
- const CANDIDATES = ['vela.config.js', 'vela.config.mjs', 'vela.config.ts'];
9
+ const CANDIDATES = [
10
+ "vela.config.js",
11
+ "vela.config.mjs",
12
+ "vela.config.ts"
13
+ ];
9
14
  /**
10
- * Locate + import the vela config. `.ts` requires a runtime that strips types
11
- * (Node 22+ `--experimental-strip-types`, or tsx/ts-node); `.js`/`.mjs` load
12
- * directly.
13
- */
14
- export async function loadConfig(cwd = process.cwd(), explicitPath) {
15
- const path = explicitPath
16
- ? isAbsolute(explicitPath)
17
- ? explicitPath
18
- : resolve(cwd, explicitPath)
19
- : await findConfig(cwd);
20
- if (!path) {
21
- throw new Error(`No vela config found. Create one of: ${CANDIDATES.join(', ')} (or pass --config <path>).`);
22
- }
23
- const mod = (await import(pathToFileURL(path).href));
24
- const config = mod.default ?? mod.config;
25
- if (!config || typeof config.createApp !== 'function') {
26
- throw new Error(`Config at ${path} must export { createApp(): Promise<VelaApplication> } (default export or a named 'config').`);
27
- }
28
- return config;
15
+ * Locate + import the vela config. `.ts` requires a runtime that strips types
16
+ * (Node 22+ `--experimental-strip-types`, or tsx/ts-node); `.js`/`.mjs` load
17
+ * directly.
18
+ */
19
+ async function loadConfig(cwd = process.cwd(), explicitPath) {
20
+ const path = explicitPath ? isAbsolute(explicitPath) ? explicitPath : resolve(cwd, explicitPath) : await findConfig(cwd);
21
+ if (!path) throw new Error(`No vela config found. Create one of: ${CANDIDATES.join(", ")} (or pass --config <path>).`);
22
+ const mod = await import(pathToFileURL(path).href);
23
+ const config = mod.default ?? mod.config;
24
+ if (!config || typeof config.createApp !== "function") throw new Error(`Config at ${path} must export { createApp(): Promise<VelaApplication> } (default export or a named 'config').`);
25
+ return config;
29
26
  }
30
27
  async function findConfig(cwd) {
31
- for (const name of CANDIDATES) {
32
- const candidate = join(cwd, name);
33
- try {
34
- await access(candidate);
35
- return candidate;
36
- }
37
- catch {
38
- // try next
39
- }
40
- }
41
- return undefined;
28
+ for (const name of CANDIDATES) {
29
+ const candidate = join(cwd, name);
30
+ try {
31
+ await access(candidate);
32
+ return candidate;
33
+ } catch {}
34
+ }
42
35
  }
36
+ //#endregion
37
+ export { defineVelaConfig, loadConfig };
38
+
39
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { access } from 'node:fs/promises';\nimport { isAbsolute, join, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { Type, VelaApplication } from '@velajs/vela';\n\n/**\n * A `vela.config.{js,mjs,ts}` default-exports (or exports `config`) this shape.\n * You wire your runtime bindings inside `createApp` — e.g. via miniflare for a\n * Cloudflare Worker, or a plain Node adapter — and return a built app.\n *\n * ```ts\n * // vela.config.ts\n * import { defineVelaConfig } from '@velajs/cli/config';\n * export default defineVelaConfig({\n * async createApp() {\n * const { createCloudflareApp } = await import('@velajs/cloudflare');\n * return createCloudflareApp(AppModule);\n * },\n * });\n * ```\n */\nexport interface VelaConfig {\n createApp(): Promise<VelaApplication> | VelaApplication;\n /**\n * The app's root module class — needed only by commands that work from\n * module metadata rather than the built app (`vela openapi dump`).\n */\n rootModule?: Type;\n}\n\n/** Identity helper for type-safe config files. */\nexport function defineVelaConfig(config: VelaConfig): VelaConfig {\n return config;\n}\n\nconst CANDIDATES = ['vela.config.js', 'vela.config.mjs', 'vela.config.ts'];\n\n/**\n * Locate + import the vela config. `.ts` requires a runtime that strips types\n * (Node 22+ `--experimental-strip-types`, or tsx/ts-node); `.js`/`.mjs` load\n * directly.\n */\nexport async function loadConfig(\n cwd: string = process.cwd(),\n explicitPath?: string,\n): Promise<VelaConfig> {\n const path = explicitPath\n ? isAbsolute(explicitPath)\n ? explicitPath\n : resolve(cwd, explicitPath)\n : await findConfig(cwd);\n\n if (!path) {\n throw new Error(\n `No vela config found. Create one of: ${CANDIDATES.join(', ')} (or pass --config <path>).`,\n );\n }\n\n const mod = (await import(pathToFileURL(path).href)) as {\n default?: VelaConfig;\n config?: VelaConfig;\n };\n const config = mod.default ?? mod.config;\n if (!config || typeof config.createApp !== 'function') {\n throw new Error(\n `Config at ${path} must export { createApp(): Promise<VelaApplication> } (default export or a named 'config').`,\n );\n }\n return config;\n}\n\nasync function findConfig(cwd: string): Promise<string | undefined> {\n for (const name of CANDIDATES) {\n const candidate = join(cwd, name);\n try {\n await access(candidate);\n return candidate;\n } catch {\n // try next\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;AA+BA,SAAgB,iBAAiB,QAAgC;CAC/D,OAAO;AACT;AAEA,MAAM,aAAa;CAAC;CAAkB;CAAmB;AAAgB;;;;;;AAOzE,eAAsB,WACpB,MAAc,QAAQ,IAAI,GAC1B,cACqB;CACrB,MAAM,OAAO,eACT,WAAW,YAAY,IACrB,eACA,QAAQ,KAAK,YAAY,IAC3B,MAAM,WAAW,GAAG;CAExB,IAAI,CAAC,MACH,MAAM,IAAI,MACR,wCAAwC,WAAW,KAAK,IAAI,EAAE,4BAChE;CAGF,MAAM,MAAO,MAAM,OAAO,cAAc,IAAI,CAAC,CAAC;CAI9C,MAAM,SAAS,IAAI,WAAW,IAAI;CAClC,IAAI,CAAC,UAAU,OAAO,OAAO,cAAc,YACzC,MAAM,IAAI,MACR,aAAa,KAAK,6FACpB;CAEF,OAAO;AACT;AAEA,eAAe,WAAW,KAA0C;CAClE,KAAK,MAAM,QAAQ,YAAY;EAC7B,MAAM,YAAY,KAAK,KAAK,IAAI;EAChC,IAAI;GACF,MAAM,OAAO,SAAS;GACtB,OAAO;EACT,QAAQ,CAER;CACF;AAEF"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,114 @@
1
- #!/usr/bin/env node
2
- export { SeedCommand } from './commands/seed.command.js';
3
- export { EntrypointListCommand, ModuleGraphCommand, OpenApiDumpCommand, RouteListCommand, } from './commands/introspect.commands.js';
4
- export { McpServeCommand } from './commands/mcp.command.js';
5
- export { collectRoutes, collectModules, collectEntrypoints, renderModuleTree } from './introspect.js';
6
- export type { RouteRow, EntrypointRow } from './introspect.js';
7
- export { renderTable } from './format.js';
8
- export { loadConfig, defineVelaConfig } from './config.js';
9
- export type { VelaConfig } from './config.js';
10
- export { formatSeedResults } from './format.js';
1
+ import { VelaConfig, defineVelaConfig, loadConfig } from "./config.js";
2
+ import { Command } from "clipanion";
3
+ import { ModuleDescription, VelaApplication } from "@velajs/vela";
4
+ import { SeederResult } from "@velajs/vela/seeder";
5
+ //#region src/commands/seed.command.d.ts
6
+ /** `vela db seed` build the app from vela.config and run its seeders. */
7
+ declare class SeedCommand extends Command {
8
+ static paths: string[][];
9
+ static usage: import("clipanion").Usage;
10
+ config: string | undefined;
11
+ continueOnError: boolean;
12
+ execute(): Promise<number>;
13
+ }
14
+ //#endregion
15
+ //#region src/commands/introspect.commands.d.ts
16
+ /** Shared shell: load config → createApp → run → best-effort dispose. */
17
+ declare abstract class AppCommand extends Command {
18
+ config: string | undefined;
19
+ json: boolean;
20
+ protected abstract run(app: VelaApplication): Promise<number>;
21
+ execute(): Promise<number>;
22
+ protected print(text: string): void;
23
+ }
24
+ /** `vela route list` — the app's HTTP route table. */
25
+ declare class RouteListCommand extends AppCommand {
26
+ static paths: string[][];
27
+ static usage: import("clipanion").Usage;
28
+ protected run(app: VelaApplication): Promise<number>;
29
+ }
30
+ /** `vela module graph` — the loaded module graph. */
31
+ declare class ModuleGraphCommand extends AppCommand {
32
+ static paths: string[][];
33
+ static usage: import("clipanion").Usage;
34
+ protected run(app: VelaApplication): Promise<number>;
35
+ }
36
+ /** `vela entrypoint list` — declared entrypoint kinds and their entries. */
37
+ declare class EntrypointListCommand extends AppCommand {
38
+ static paths: string[][];
39
+ static usage: import("clipanion").Usage;
40
+ protected run(app: VelaApplication): Promise<number>;
41
+ }
42
+ /** `vela openapi dump` — emit the OpenAPI document. */
43
+ declare class OpenApiDumpCommand extends Command {
44
+ static paths: string[][];
45
+ static usage: import("clipanion").Usage;
46
+ config: string | undefined;
47
+ out: string | undefined;
48
+ title: string | undefined;
49
+ apiVersion: string | undefined;
50
+ globalPrefix: string | undefined;
51
+ execute(): Promise<number>;
52
+ }
53
+ //#endregion
54
+ //#region src/commands/mcp.command.d.ts
55
+ /**
56
+ * `vela mcp serve` — an MCP stdio server exposing the same READ-ONLY
57
+ * introspection as the `route`/`module`/`entrypoint`/`openapi` commands, so an
58
+ * AI agent can query a Vela app's shape over the Model Context Protocol.
59
+ *
60
+ * Deliberately does NOT extend `AppCommand`: that base disposes the app in its
61
+ * `finally` the moment `run()` returns, but an MCP server must stay alive until
62
+ * the transport closes. stdout is reserved for JSON-RPC framing; every human
63
+ * message goes to stderr.
64
+ */
65
+ declare class McpServeCommand extends Command {
66
+ static paths: string[][];
67
+ static usage: import("clipanion").Usage;
68
+ config: string | undefined;
69
+ execute(): Promise<number>;
70
+ }
71
+ //#endregion
72
+ //#region src/introspect.d.ts
73
+ /** One row of `vela route list`. */
74
+ interface RouteRow {
75
+ method: string;
76
+ path: string;
77
+ /** `Controller#handler`, or `(mounted)` for routes vela did not compose
78
+ * itself (RouteContributor/CRUD, OpenAPI UI mounts, manual Hono routes). */
79
+ handler: string;
80
+ source: 'controller' | 'mounted';
81
+ }
82
+ /**
83
+ * The app's route table: `describeRoutes()` rows (framework-composed truth)
84
+ * plus everything else present on the Hono router, deduped and labeled
85
+ * `(mounted)`. Returns null when the app never built HTTP routes.
86
+ */
87
+ declare function collectRoutes(app: VelaApplication): RouteRow[] | null;
88
+ /** `vela module graph` tree lines (or raw descriptions for --json). */
89
+ declare function collectModules(app: VelaApplication): ModuleDescription[];
90
+ declare function renderModuleTree(modules: ModuleDescription[]): string[];
91
+ /** One row of `vela entrypoint list`. */
92
+ interface EntrypointRow {
93
+ kind: string;
94
+ target: string;
95
+ meta: string;
96
+ }
97
+ /**
98
+ * Every DECLARED entrypoint kind (from the global kind store — includes kinds
99
+ * with zero entries) joined with the app's entries. Metadata-only entries of
100
+ * lazy modules list fine; nothing materializes.
101
+ */
102
+ declare function collectEntrypoints(app: VelaApplication): EntrypointRow[];
103
+ //#endregion
104
+ //#region src/format.d.ts
105
+ /**
106
+ * Render seeder results to a logger and return a process exit code
107
+ * (0 = all ran, 1 = at least one failed). Pure — no I/O beyond the logger.
108
+ */
109
+ declare function formatSeedResults(results: SeederResult[], log?: (message: string) => void): number;
110
+ /** Aligned plain-text table. Pure; returns lines. */
111
+ declare function renderTable(headers: string[], rows: string[][]): string[];
112
+ //#endregion
113
+ export { EntrypointListCommand, type EntrypointRow, McpServeCommand, ModuleGraphCommand, OpenApiDumpCommand, RouteListCommand, type RouteRow, SeedCommand, type VelaConfig, collectEntrypoints, collectModules, collectRoutes, defineVelaConfig, formatSeedResults, loadConfig, renderModuleTree, renderTable };
114
+ //# sourceMappingURL=index.d.ts.map