@grafema/cli 0.1.1-alpha → 0.2.1-beta
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/cli.js +10 -0
- package/dist/commands/analyze.d.ts.map +1 -1
- package/dist/commands/analyze.js +69 -11
- package/dist/commands/check.d.ts +6 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +177 -1
- package/dist/commands/coverage.d.ts.map +1 -1
- package/dist/commands/coverage.js +7 -0
- package/dist/commands/doctor/checks.d.ts +55 -0
- package/dist/commands/doctor/checks.d.ts.map +1 -0
- package/dist/commands/doctor/checks.js +534 -0
- package/dist/commands/doctor/output.d.ts +20 -0
- package/dist/commands/doctor/output.d.ts.map +1 -0
- package/dist/commands/doctor/output.js +94 -0
- package/dist/commands/doctor/types.d.ts +42 -0
- package/dist/commands/doctor/types.d.ts.map +1 -0
- package/dist/commands/doctor/types.js +4 -0
- package/dist/commands/doctor.d.ts +17 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +80 -0
- package/dist/commands/explain.d.ts +16 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +145 -0
- package/dist/commands/explore.d.ts +7 -1
- package/dist/commands/explore.d.ts.map +1 -1
- package/dist/commands/explore.js +204 -85
- package/dist/commands/get.d.ts.map +1 -1
- package/dist/commands/get.js +16 -4
- package/dist/commands/impact.d.ts.map +1 -1
- package/dist/commands/impact.js +48 -50
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +93 -15
- package/dist/commands/ls.d.ts +14 -0
- package/dist/commands/ls.d.ts.map +1 -0
- package/dist/commands/ls.js +132 -0
- package/dist/commands/overview.d.ts.map +1 -1
- package/dist/commands/overview.js +15 -2
- package/dist/commands/query.d.ts +98 -0
- package/dist/commands/query.d.ts.map +1 -1
- package/dist/commands/query.js +549 -136
- package/dist/commands/schema.d.ts +13 -0
- package/dist/commands/schema.d.ts.map +1 -0
- package/dist/commands/schema.js +279 -0
- package/dist/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +13 -6
- package/dist/commands/stats.d.ts.map +1 -1
- package/dist/commands/stats.js +7 -0
- package/dist/commands/trace.d.ts +73 -0
- package/dist/commands/trace.d.ts.map +1 -1
- package/dist/commands/trace.js +500 -5
- package/dist/commands/types.d.ts +12 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +79 -0
- package/dist/utils/formatNode.d.ts +13 -0
- package/dist/utils/formatNode.d.ts.map +1 -1
- package/dist/utils/formatNode.js +35 -2
- package/package.json +3 -3
- package/src/cli.ts +10 -0
- package/src/commands/analyze.ts +84 -9
- package/src/commands/check.ts +201 -0
- package/src/commands/coverage.ts +7 -0
- package/src/commands/doctor/checks.ts +612 -0
- package/src/commands/doctor/output.ts +115 -0
- package/src/commands/doctor/types.ts +45 -0
- package/src/commands/doctor.ts +106 -0
- package/src/commands/explain.ts +173 -0
- package/src/commands/explore.tsx +247 -97
- package/src/commands/get.ts +20 -6
- package/src/commands/impact.ts +55 -61
- package/src/commands/init.ts +101 -14
- package/src/commands/ls.ts +166 -0
- package/src/commands/overview.ts +15 -2
- package/src/commands/query.ts +643 -149
- package/src/commands/schema.ts +345 -0
- package/src/commands/server.ts +13 -6
- package/src/commands/stats.ts +7 -0
- package/src/commands/trace.ts +647 -6
- package/src/commands/types.ts +94 -0
- package/src/utils/formatNode.ts +42 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types command - List all node types in the graph
|
|
3
|
+
*
|
|
4
|
+
* Shows all node types present in the analyzed codebase with counts.
|
|
5
|
+
* Useful for:
|
|
6
|
+
* - Discovering what types exist (standard and custom)
|
|
7
|
+
* - Understanding graph composition
|
|
8
|
+
* - Finding types to use with --type flag
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Command } from 'commander';
|
|
12
|
+
import { resolve, join } from 'path';
|
|
13
|
+
import { existsSync } from 'fs';
|
|
14
|
+
import { RFDBServerBackend } from '@grafema/core';
|
|
15
|
+
import { exitWithError } from '../utils/errorFormatter.js';
|
|
16
|
+
|
|
17
|
+
interface TypesOptions {
|
|
18
|
+
project: string;
|
|
19
|
+
json?: boolean;
|
|
20
|
+
sort?: 'count' | 'name';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const typesCommand = new Command('types')
|
|
24
|
+
.description('List all node types in the graph')
|
|
25
|
+
.option('-p, --project <path>', 'Project path', '.')
|
|
26
|
+
.option('-j, --json', 'Output as JSON')
|
|
27
|
+
.option('-s, --sort <by>', 'Sort by: count (default) or name', 'count')
|
|
28
|
+
.addHelpText('after', `
|
|
29
|
+
Examples:
|
|
30
|
+
grafema types List all node types with counts
|
|
31
|
+
grafema types --json Output as JSON for scripting
|
|
32
|
+
grafema types --sort name Sort alphabetically by type name
|
|
33
|
+
grafema types -s count Sort by count (default, descending)
|
|
34
|
+
|
|
35
|
+
Use with query --type:
|
|
36
|
+
grafema types # See available types
|
|
37
|
+
grafema query --type jsx:component "Button" # Query specific type
|
|
38
|
+
`)
|
|
39
|
+
.action(async (options: TypesOptions) => {
|
|
40
|
+
const projectPath = resolve(options.project);
|
|
41
|
+
const grafemaDir = join(projectPath, '.grafema');
|
|
42
|
+
const dbPath = join(grafemaDir, 'graph.rfdb');
|
|
43
|
+
|
|
44
|
+
if (!existsSync(dbPath)) {
|
|
45
|
+
exitWithError('No graph database found', ['Run: grafema analyze']);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const backend = new RFDBServerBackend({ dbPath });
|
|
49
|
+
await backend.connect();
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const nodeCounts = await backend.countNodesByType();
|
|
53
|
+
const entries = Object.entries(nodeCounts);
|
|
54
|
+
|
|
55
|
+
if (entries.length === 0) {
|
|
56
|
+
console.log('No nodes in graph. Run: grafema analyze');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Sort entries
|
|
61
|
+
const sortedEntries = options.sort === 'name'
|
|
62
|
+
? entries.sort((a, b) => a[0].localeCompare(b[0]))
|
|
63
|
+
: entries.sort((a, b) => b[1] - a[1]); // count descending
|
|
64
|
+
|
|
65
|
+
if (options.json) {
|
|
66
|
+
const result = {
|
|
67
|
+
types: sortedEntries.map(([type, count]) => ({ type, count })),
|
|
68
|
+
totalTypes: sortedEntries.length,
|
|
69
|
+
totalNodes: sortedEntries.reduce((sum, [, count]) => sum + count, 0),
|
|
70
|
+
};
|
|
71
|
+
console.log(JSON.stringify(result, null, 2));
|
|
72
|
+
} else {
|
|
73
|
+
console.log('Node Types in Graph:');
|
|
74
|
+
console.log('');
|
|
75
|
+
|
|
76
|
+
// Calculate max type length for alignment
|
|
77
|
+
const maxTypeLen = Math.max(...sortedEntries.map(([type]) => type.length));
|
|
78
|
+
|
|
79
|
+
for (const [type, count] of sortedEntries) {
|
|
80
|
+
const paddedType = type.padEnd(maxTypeLen);
|
|
81
|
+
const formattedCount = count.toLocaleString();
|
|
82
|
+
console.log(` ${paddedType} ${formattedCount}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log('');
|
|
86
|
+
const totalNodes = sortedEntries.reduce((sum, [, count]) => sum + count, 0);
|
|
87
|
+
console.log(`Total: ${sortedEntries.length} types, ${totalNodes.toLocaleString()} nodes`);
|
|
88
|
+
console.log('');
|
|
89
|
+
console.log('Tip: Use grafema query --type <type> "pattern" to search within a type');
|
|
90
|
+
}
|
|
91
|
+
} finally {
|
|
92
|
+
await backend.close();
|
|
93
|
+
}
|
|
94
|
+
});
|
package/src/utils/formatNode.ts
CHANGED
|
@@ -33,6 +33,45 @@ export interface DisplayableNode {
|
|
|
33
33
|
file: string;
|
|
34
34
|
/** Line number (optional) */
|
|
35
35
|
line?: number;
|
|
36
|
+
/** HTTP method (for http:route, http:request) */
|
|
37
|
+
method?: string;
|
|
38
|
+
/** Path or URL (for http:route, http:request) */
|
|
39
|
+
path?: string;
|
|
40
|
+
/** URL (for http:request) */
|
|
41
|
+
url?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the display name for a node based on its type.
|
|
46
|
+
*
|
|
47
|
+
* HTTP nodes use method + path/url instead of name.
|
|
48
|
+
* Other nodes use their name field.
|
|
49
|
+
*/
|
|
50
|
+
export function getNodeDisplayName(node: DisplayableNode): string {
|
|
51
|
+
switch (node.type) {
|
|
52
|
+
case 'http:route':
|
|
53
|
+
// Express routes: "GET /users"
|
|
54
|
+
if (node.method && node.path) {
|
|
55
|
+
return `${node.method} ${node.path}`;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'http:request':
|
|
59
|
+
// Fetch/axios requests: "POST /api/data"
|
|
60
|
+
if (node.method && node.url) {
|
|
61
|
+
return `${node.method} ${node.url}`;
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
// Default: use name, but guard against JSON metadata corruption
|
|
66
|
+
if (node.name && !node.name.startsWith('{')) {
|
|
67
|
+
return node.name;
|
|
68
|
+
}
|
|
69
|
+
// Fallback: extract name from semantic ID if possible
|
|
70
|
+
const parts = node.id.split('#');
|
|
71
|
+
if (parts.length > 1) {
|
|
72
|
+
return parts[1]; // Usually contains the key identifier
|
|
73
|
+
}
|
|
74
|
+
return node.id;
|
|
36
75
|
}
|
|
37
76
|
|
|
38
77
|
/**
|
|
@@ -47,8 +86,9 @@ export function formatNodeDisplay(node: DisplayableNode, options: FormatNodeOpti
|
|
|
47
86
|
const { projectPath, showLocation = true, indent = '' } = options;
|
|
48
87
|
const lines: string[] = [];
|
|
49
88
|
|
|
50
|
-
// Line 1: [TYPE] name
|
|
51
|
-
|
|
89
|
+
// Line 1: [TYPE] display name (type-specific)
|
|
90
|
+
const displayName = getNodeDisplayName(node);
|
|
91
|
+
lines.push(`${indent}[${node.type}] ${displayName}`);
|
|
52
92
|
|
|
53
93
|
// Line 2: ID (semantic ID)
|
|
54
94
|
lines.push(`${indent} ID: ${node.id}`);
|