@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.
@@ -1,103 +0,0 @@
1
- import { describeToken, getEntrypointKinds } from '@velajs/vela';
2
- /**
3
- * The app's route table: `describeRoutes()` rows (framework-composed truth)
4
- * plus everything else present on the Hono router, deduped and labeled
5
- * `(mounted)`. Returns null when the app never built HTTP routes.
6
- */
7
- export function collectRoutes(app) {
8
- let described;
9
- try {
10
- described = app.describeRoutes();
11
- }
12
- catch {
13
- return null; // no HTTP routes built (slim/non-HTTP app)
14
- }
15
- const rows = described.map((r) => ({
16
- method: r.method,
17
- path: r.path,
18
- handler: `${r.controller}#${r.handler}`,
19
- source: 'controller',
20
- }));
21
- const covered = new Set(described.map((r) => `${r.method} ${r.path}`));
22
- for (const r of described) {
23
- // @Head handlers are served by Hono under GET — claim that row too so it
24
- // doesn't reappear as a mounted duplicate.
25
- if (r.method === 'HEAD')
26
- covered.add(`GET ${r.path}`);
27
- }
28
- const seenMounted = new Set();
29
- for (const honoRoute of app.getHonoApp().routes) {
30
- // 'ALL' entries are middleware mounts (framework-internal disposal/context
31
- // wrappers, global + scoped middleware) — not endpoints.
32
- if (honoRoute.method === 'ALL')
33
- continue;
34
- const key = `${honoRoute.method} ${honoRoute.path}`;
35
- if (covered.has(key) || seenMounted.has(key))
36
- continue;
37
- seenMounted.add(key);
38
- rows.push({ method: honoRoute.method, path: honoRoute.path, handler: '(mounted)', source: 'mounted' });
39
- }
40
- return rows.sort((a, b) => a.path.localeCompare(b.path) || a.method.localeCompare(b.method));
41
- }
42
- /** `vela module graph` tree lines (or raw descriptions for --json). */
43
- export function collectModules(app) {
44
- return app.getContainer().getModuleDescriptions();
45
- }
46
- export function renderModuleTree(modules) {
47
- const byId = new Map(modules.map((m) => [m.moduleId, m]));
48
- const imported = new Set(modules.flatMap((m) => m.imports));
49
- const roots = modules.filter((m) => !imported.has(m.moduleId));
50
- const lines = [];
51
- const render = (id, depth, trail) => {
52
- const mod = byId.get(id);
53
- const flags = mod
54
- ? [mod.isGlobal ? 'global' : null, mod.lazy ? 'lazy' : null].filter(Boolean)
55
- : [];
56
- const suffix = flags.length > 0 ? ` (${flags.join(', ')})` : '';
57
- const providers = mod ? ` — ${mod.providers.length} provider${mod.providers.length === 1 ? '' : 's'}` : '';
58
- lines.push(`${' '.repeat(depth)}${id}${suffix}${providers}`);
59
- if (!mod || trail.has(id))
60
- return;
61
- const nextTrail = new Set(trail).add(id);
62
- for (const child of mod.imports)
63
- render(child, depth + 1, nextTrail);
64
- };
65
- for (const root of roots)
66
- render(root.moduleId, 0, new Set());
67
- return lines;
68
- }
69
- function safeMeta(meta) {
70
- try {
71
- return JSON.stringify(meta, (_key, value) => typeof value === 'function'
72
- ? '[function]'
73
- : typeof value === 'object' && value !== null && value.constructor !== Object && !Array.isArray(value)
74
- ? `[${value.constructor.name}]`
75
- : value) ?? 'undefined';
76
- }
77
- catch {
78
- return '[unserializable]';
79
- }
80
- }
81
- /**
82
- * Every DECLARED entrypoint kind (from the global kind store — includes kinds
83
- * with zero entries) joined with the app's entries. Metadata-only entries of
84
- * lazy modules list fine; nothing materializes.
85
- */
86
- export function collectEntrypoints(app) {
87
- const rows = [];
88
- const declared = getEntrypointKinds().map((k) => k.kind);
89
- const populated = app.entrypoints.kinds();
90
- const kinds = [...new Set([...declared, ...populated])];
91
- for (const kind of kinds) {
92
- const entries = app.entrypoints.ofKind(kind);
93
- if (entries.length === 0) {
94
- rows.push({ kind, target: '(no entrypoints)', meta: '' });
95
- continue;
96
- }
97
- for (const ep of entries) {
98
- const method = ep.methodName !== undefined ? `#${String(ep.methodName)}` : '';
99
- rows.push({ kind, target: `${describeToken(ep.token)}${method}`, meta: safeMeta(ep.meta) });
100
- }
101
- }
102
- return rows;
103
- }