tskb 0.0.1
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/LICENSE +21 -0
- package/README.md +1086 -0
- package/dist/cli/commands/build.d.ts +55 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +105 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/query.d.ts +10 -0
- package/dist/cli/commands/query.d.ts.map +1 -0
- package/dist/cli/commands/query.js +399 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/visualize.d.ts +10 -0
- package/dist/cli/commands/visualize.d.ts.map +1 -0
- package/dist/cli/commands/visualize.js +26 -0
- package/dist/cli/commands/visualize.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +109 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/extraction/documentation.d.ts +28 -0
- package/dist/core/extraction/documentation.d.ts.map +1 -0
- package/dist/core/extraction/documentation.js +330 -0
- package/dist/core/extraction/documentation.js.map +1 -0
- package/dist/core/extraction/index.d.ts +11 -0
- package/dist/core/extraction/index.d.ts.map +1 -0
- package/dist/core/extraction/index.js +9 -0
- package/dist/core/extraction/index.js.map +1 -0
- package/dist/core/extraction/registry.d.ts +40 -0
- package/dist/core/extraction/registry.d.ts.map +1 -0
- package/dist/core/extraction/registry.js +604 -0
- package/dist/core/extraction/registry.js.map +1 -0
- package/dist/core/graph/builder.d.ts +37 -0
- package/dist/core/graph/builder.d.ts.map +1 -0
- package/dist/core/graph/builder.js +421 -0
- package/dist/core/graph/builder.js.map +1 -0
- package/dist/core/graph/index.d.ts +23 -0
- package/dist/core/graph/index.d.ts.map +1 -0
- package/dist/core/graph/index.js +25 -0
- package/dist/core/graph/index.js.map +1 -0
- package/dist/core/graph/types.d.ts +128 -0
- package/dist/core/graph/types.d.ts.map +1 -0
- package/dist/core/graph/types.js +9 -0
- package/dist/core/graph/types.js.map +1 -0
- package/dist/core/visualization/dot-generator.d.ts +13 -0
- package/dist/core/visualization/dot-generator.d.ts.map +1 -0
- package/dist/core/visualization/dot-generator.js +200 -0
- package/dist/core/visualization/dot-generator.js.map +1 -0
- package/dist/core/visualization/index.d.ts +20 -0
- package/dist/core/visualization/index.d.ts.map +1 -0
- package/dist/core/visualization/index.js +23 -0
- package/dist/core/visualization/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-runtime.d.ts +7 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +11 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/runtime/jsx.d.ts +84 -0
- package/dist/runtime/jsx.d.ts.map +1 -0
- package/dist/runtime/jsx.js +93 -0
- package/dist/runtime/jsx.js.map +1 -0
- package/dist/runtime/registry.d.ts +61 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +2 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/typescript/index.d.ts +7 -0
- package/dist/typescript/index.d.ts.map +1 -0
- package/dist/typescript/index.js +7 -0
- package/dist/typescript/index.js.map +1 -0
- package/dist/typescript/program.d.ts +33 -0
- package/dist/typescript/program.d.ts.map +1 -0
- package/dist/typescript/program.js +84 -0
- package/dist/typescript/program.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* tskb CLI - TypeScript Semantic Knowledge Base
|
|
4
|
+
*
|
|
5
|
+
* Main entry point for the CLI tool.
|
|
6
|
+
* Handles command parsing and routing.
|
|
7
|
+
*/
|
|
8
|
+
import { build } from "./commands/build.js";
|
|
9
|
+
import { visualize } from "./commands/visualize.js";
|
|
10
|
+
import { query } from "./commands/query.js";
|
|
11
|
+
/**
|
|
12
|
+
* Parse command line arguments
|
|
13
|
+
*/
|
|
14
|
+
function parseArgs(args) {
|
|
15
|
+
const command = args[0];
|
|
16
|
+
if (!command) {
|
|
17
|
+
console.error("Usage:");
|
|
18
|
+
console.error(" tskb build <glob> --out <file> --tsconfig <path>");
|
|
19
|
+
console.error(" tskb visualize <graph.json> --out <file.dot>");
|
|
20
|
+
console.error(" tskb query <graph.json> <search-term> [--verbose]");
|
|
21
|
+
console.error("");
|
|
22
|
+
console.error("Examples:");
|
|
23
|
+
console.error(' tskb build "src/**/*.tsx" --out graph.json --tsconfig ./tsconfig.json');
|
|
24
|
+
console.error(" tskb visualize tskb.json --out graph.dot");
|
|
25
|
+
console.error(' tskb query tskb.json "auth" # Concise output (default)');
|
|
26
|
+
console.error(' tskb query tskb.json "auth" --verbose # Full context');
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
// If first arg doesn't look like a command, assume it's the old "build" usage
|
|
30
|
+
if (command.includes("*") || command.includes("/")) {
|
|
31
|
+
return {
|
|
32
|
+
command: "build",
|
|
33
|
+
pattern: command,
|
|
34
|
+
output: args.includes("--out") ? args[args.indexOf("--out") + 1] : "tskb.json",
|
|
35
|
+
tsconfig: args.includes("--tsconfig")
|
|
36
|
+
? args[args.indexOf("--tsconfig") + 1]
|
|
37
|
+
: "tsconfig.json",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Parse modern command format
|
|
41
|
+
if (command === "build") {
|
|
42
|
+
const pattern = args[1];
|
|
43
|
+
if (!pattern) {
|
|
44
|
+
console.error("Error: build command requires a glob pattern");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
command: "build",
|
|
49
|
+
pattern,
|
|
50
|
+
output: args.includes("--out") ? args[args.indexOf("--out") + 1] : "tskb.json",
|
|
51
|
+
tsconfig: args.includes("--tsconfig")
|
|
52
|
+
? args[args.indexOf("--tsconfig") + 1]
|
|
53
|
+
: "tsconfig.json",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (command === "visualize") {
|
|
57
|
+
const input = args[1];
|
|
58
|
+
if (!input) {
|
|
59
|
+
console.error("Error: visualize command requires an input JSON file");
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
command: "visualize",
|
|
64
|
+
input,
|
|
65
|
+
output: args.includes("--out") ? args[args.indexOf("--out") + 1] : "graph.dot",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (command === "query") {
|
|
69
|
+
const input = args[1];
|
|
70
|
+
const searchTerm = args[2];
|
|
71
|
+
if (!input || !searchTerm) {
|
|
72
|
+
console.error("Error: query command requires a graph file and search term");
|
|
73
|
+
console.error('Usage: tskb query <graph.json> "<search-term>" [--verbose]');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
command: "query",
|
|
78
|
+
input,
|
|
79
|
+
searchTerm,
|
|
80
|
+
verbose: args.includes("--verbose"),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
console.error(`Unknown command: ${command}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Main CLI entry point
|
|
88
|
+
*/
|
|
89
|
+
async function main() {
|
|
90
|
+
const args = process.argv.slice(2);
|
|
91
|
+
const config = parseArgs(args);
|
|
92
|
+
try {
|
|
93
|
+
if (config.command === "build") {
|
|
94
|
+
await build({ pattern: config.pattern, output: config.output, tsconfig: config.tsconfig });
|
|
95
|
+
}
|
|
96
|
+
else if (config.command === "visualize") {
|
|
97
|
+
await visualize(config.input, config.output);
|
|
98
|
+
}
|
|
99
|
+
else if (config.command === "query") {
|
|
100
|
+
await query(config.input, config.searchTerm, !config.verbose);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error("❌ Error:", error instanceof Error ? error.message : String(error));
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
main();
|
|
109
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C;;GAEG;AACH,SAAS,SAAS,CAChB,IAAc;IAKd,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAExB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACpE,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAChE,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACrE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,yEAAyE,CAAC,CAAC;QACzF,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC5D,OAAO,CAAC,KAAK,CAAC,uEAAuE,CAAC,CAAC;QACvF,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,8EAA8E;IAC9E,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAA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K,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7F,CAAC;aAAM,IAAI,MAAM,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;YAC1C,MAAM,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,MAAM,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YACtC,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* Extracted documentation data from a single file
|
|
4
|
+
*/
|
|
5
|
+
export interface ExtractedDoc {
|
|
6
|
+
/** Relative file path from baseDir (tsconfig root), using forward slashes */
|
|
7
|
+
filePath: string;
|
|
8
|
+
format: "tsx";
|
|
9
|
+
content: string;
|
|
10
|
+
references: {
|
|
11
|
+
modules: string[];
|
|
12
|
+
terms: string[];
|
|
13
|
+
folders: string[];
|
|
14
|
+
exports: string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts documentation from TSX files matched by the glob pattern.
|
|
19
|
+
*
|
|
20
|
+
* Extracts JSX content and finds FolderRef/ModuleRef/TermRef references.
|
|
21
|
+
*
|
|
22
|
+
* @param program - TypeScript program
|
|
23
|
+
* @param filePaths - Set of absolute file paths to process (from glob match)
|
|
24
|
+
* @param baseDir - Base directory (from tsconfig) to make paths relative to
|
|
25
|
+
* @returns Array of extracted documentation
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractDocs(program: ts.Program, filePaths: Set<string>, baseDir: string): ExtractedDoc[];
|
|
28
|
+
//# sourceMappingURL=documentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentation.d.ts","sourceRoot":"","sources":["../../../src/core/extraction/documentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,KAAK,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE;QACV,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;CACH;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,EACtB,OAAO,EAAE,MAAM,GACd,YAAY,EAAE,CAsBhB"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts documentation from TSX files matched by the glob pattern.
|
|
5
|
+
*
|
|
6
|
+
* Extracts JSX content and finds FolderRef/ModuleRef/TermRef references.
|
|
7
|
+
*
|
|
8
|
+
* @param program - TypeScript program
|
|
9
|
+
* @param filePaths - Set of absolute file paths to process (from glob match)
|
|
10
|
+
* @param baseDir - Base directory (from tsconfig) to make paths relative to
|
|
11
|
+
* @returns Array of extracted documentation
|
|
12
|
+
*/
|
|
13
|
+
export function extractDocs(program, filePaths, baseDir) {
|
|
14
|
+
const docs = [];
|
|
15
|
+
// Normalize file paths for comparison (handle different path separators)
|
|
16
|
+
const normalizedFilePaths = new Set(Array.from(filePaths).map((p) => p.replace(/\\/g, "/").toLowerCase()));
|
|
17
|
+
for (const sourceFile of program.getSourceFiles()) {
|
|
18
|
+
// Normalize source file path for comparison
|
|
19
|
+
const normalizedSourcePath = sourceFile.fileName.replace(/\\/g, "/").toLowerCase();
|
|
20
|
+
// Only process files that were explicitly matched by the glob pattern
|
|
21
|
+
if (normalizedFilePaths.has(normalizedSourcePath) && sourceFile.fileName.endsWith(".tsx")) {
|
|
22
|
+
const doc = extractFromTsxFile(sourceFile, baseDir);
|
|
23
|
+
if (doc) {
|
|
24
|
+
docs.push(doc);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return docs;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extract documentation from TSX file (JSX style)
|
|
32
|
+
*/
|
|
33
|
+
function extractFromTsxFile(sourceFile, baseDir) {
|
|
34
|
+
const references = {
|
|
35
|
+
modules: [],
|
|
36
|
+
terms: [],
|
|
37
|
+
folders: [],
|
|
38
|
+
exports: [],
|
|
39
|
+
};
|
|
40
|
+
let content = "";
|
|
41
|
+
// Build a map of constant declarations to their type assertions
|
|
42
|
+
const constantReferences = buildConstantReferencesMap(sourceFile);
|
|
43
|
+
// Find the default export
|
|
44
|
+
const defaultExport = findDefaultExport(sourceFile);
|
|
45
|
+
if (!defaultExport)
|
|
46
|
+
return null;
|
|
47
|
+
// Extract content and references from JSX
|
|
48
|
+
content = extractJsxContent(defaultExport, references, constantReferences);
|
|
49
|
+
// Convert absolute path to relative path (for portability across repos/machines)
|
|
50
|
+
const relativePath = path.relative(baseDir, sourceFile.fileName).replace(/\\/g, "/");
|
|
51
|
+
return {
|
|
52
|
+
filePath: relativePath,
|
|
53
|
+
format: "tsx",
|
|
54
|
+
content,
|
|
55
|
+
references: {
|
|
56
|
+
modules: Array.from(new Set(references.modules)),
|
|
57
|
+
terms: Array.from(new Set(references.terms)),
|
|
58
|
+
folders: Array.from(new Set(references.folders)),
|
|
59
|
+
exports: Array.from(new Set(references.exports)),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Find the default export statement
|
|
65
|
+
*/
|
|
66
|
+
function findDefaultExport(sourceFile) {
|
|
67
|
+
for (const statement of sourceFile.statements) {
|
|
68
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) {
|
|
69
|
+
return statement.expression;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a map of constant variable names to their type assertion metadata.
|
|
76
|
+
* This handles cases like: const CliIndexModule = ref as tskb.Modules["cli.index"];
|
|
77
|
+
*/
|
|
78
|
+
function buildConstantReferencesMap(sourceFile) {
|
|
79
|
+
const map = new Map();
|
|
80
|
+
function visit(node) {
|
|
81
|
+
if (ts.isVariableStatement(node)) {
|
|
82
|
+
for (const declaration of node.declarationList.declarations) {
|
|
83
|
+
if (ts.isIdentifier(declaration.name) &&
|
|
84
|
+
declaration.initializer &&
|
|
85
|
+
ts.isAsExpression(declaration.initializer)) {
|
|
86
|
+
const varName = declaration.name.text;
|
|
87
|
+
const metadata = extractTypeAssertionMetadata(declaration.initializer);
|
|
88
|
+
if (metadata) {
|
|
89
|
+
map.set(varName, metadata);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
ts.forEachChild(node, visit);
|
|
95
|
+
}
|
|
96
|
+
visit(sourceFile);
|
|
97
|
+
return map;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Extract category and name from a type assertion like: ref as tskb.Modules["cli.index"]
|
|
101
|
+
*/
|
|
102
|
+
function extractTypeAssertionMetadata(assertion) {
|
|
103
|
+
const type = assertion.type;
|
|
104
|
+
// Check for indexed access type: tskb.Folders['Name']
|
|
105
|
+
if (ts.isIndexedAccessTypeNode(type)) {
|
|
106
|
+
const objType = type.objectType;
|
|
107
|
+
const indexType = type.indexType;
|
|
108
|
+
// Ensure it's tskb.X['...'] pattern
|
|
109
|
+
if (ts.isTypeReferenceNode(objType) &&
|
|
110
|
+
ts.isQualifiedName(objType.typeName) &&
|
|
111
|
+
ts.isIdentifier(objType.typeName.left) &&
|
|
112
|
+
objType.typeName.left.text === "tskb" &&
|
|
113
|
+
ts.isIdentifier(objType.typeName.right) &&
|
|
114
|
+
ts.isLiteralTypeNode(indexType) &&
|
|
115
|
+
ts.isStringLiteral(indexType.literal)) {
|
|
116
|
+
const interfaceName = objType.typeName.right.text;
|
|
117
|
+
const refName = indexType.literal.text;
|
|
118
|
+
return { category: interfaceName, name: refName };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Extract text content and references from JSX tree.
|
|
125
|
+
*
|
|
126
|
+
* JSX TRAVERSAL STRATEGY:
|
|
127
|
+
* We recursively walk the JSX tree (depth-first) and:
|
|
128
|
+
* 1. When we hit <FolderRef name="X" /> -> add "X" to references.folders, append "[Folder: X]" to content
|
|
129
|
+
* 2. When we hit <ModuleRef name="Y" /> -> add "Y" to references.modules, append "[Module: Y]" to content
|
|
130
|
+
* 3. When we hit <TermRef name="Z" /> -> add "Z" to references.terms, append "[Term: Z]" to content
|
|
131
|
+
* 4. When we hit text nodes ("some text") -> append to content
|
|
132
|
+
* 5. For other elements (<Doc>, <H1>, <P>, etc.) -> recurse into children
|
|
133
|
+
*
|
|
134
|
+
* RESULT:
|
|
135
|
+
* - content: Full text representation of the doc (references shown as [Module: X])
|
|
136
|
+
* - references: Arrays of all referenced module/term/folder names
|
|
137
|
+
*
|
|
138
|
+
* This gives us both human-readable text AND the graph edges we need.
|
|
139
|
+
*/
|
|
140
|
+
function extractJsxContent(node, references, constantReferences) {
|
|
141
|
+
let content = "";
|
|
142
|
+
function visit(n) {
|
|
143
|
+
// Handle JSX elements
|
|
144
|
+
if (ts.isJsxElement(n) || ts.isJsxSelfClosingElement(n)) {
|
|
145
|
+
const tagName = ts.isJsxElement(n) ? n.openingElement.tagName : n.tagName;
|
|
146
|
+
if (ts.isIdentifier(tagName)) {
|
|
147
|
+
const name = tagName.text;
|
|
148
|
+
const attributes = ts.isJsxElement(n) ? n.openingElement.attributes : n.attributes;
|
|
149
|
+
// Handle Snippet component specially
|
|
150
|
+
if (name === "Snippet") {
|
|
151
|
+
const codeAttr = getCodeAttribute(attributes);
|
|
152
|
+
if (codeAttr) {
|
|
153
|
+
content += `<snippet>${codeAttr}</snippet>`;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Handle ADR component specially
|
|
158
|
+
if (name === "Adr") {
|
|
159
|
+
const adrMeta = getAdrAttributes(attributes);
|
|
160
|
+
if (adrMeta) {
|
|
161
|
+
content += `<adr ${adrMeta}>`;
|
|
162
|
+
// Process children
|
|
163
|
+
if (ts.isJsxElement(n)) {
|
|
164
|
+
n.children.forEach(visit);
|
|
165
|
+
}
|
|
166
|
+
content += `</adr>`;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Extract references
|
|
171
|
+
if (name === "ModuleRef") {
|
|
172
|
+
const refName = getNameAttribute(attributes);
|
|
173
|
+
if (refName) {
|
|
174
|
+
references.modules.push(refName);
|
|
175
|
+
content += `[Module: ${refName}]`;
|
|
176
|
+
return; // Don't process children
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (name === "TermRef") {
|
|
180
|
+
const refName = getNameAttribute(attributes);
|
|
181
|
+
if (refName) {
|
|
182
|
+
references.terms.push(refName);
|
|
183
|
+
content += `[Term: ${refName}]`;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (name === "FolderRef") {
|
|
188
|
+
const refName = getNameAttribute(attributes);
|
|
189
|
+
if (refName) {
|
|
190
|
+
references.folders.push(refName);
|
|
191
|
+
content += `[Folder: ${refName}]`;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Process children for other elements
|
|
197
|
+
if (ts.isJsxElement(n)) {
|
|
198
|
+
n.children.forEach(visit);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Handle text nodes
|
|
202
|
+
else if (ts.isJsxText(n)) {
|
|
203
|
+
const text = n.text.trim();
|
|
204
|
+
if (text) {
|
|
205
|
+
content += text + " ";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Handle JSX expressions
|
|
209
|
+
else if (ts.isJsxExpression(n) && n.expression) {
|
|
210
|
+
if (ts.isStringLiteral(n.expression)) {
|
|
211
|
+
content += n.expression.text + " ";
|
|
212
|
+
}
|
|
213
|
+
// Handle identifier references to constants: {CliIndexModule}
|
|
214
|
+
else if (ts.isIdentifier(n.expression)) {
|
|
215
|
+
const varName = n.expression.text;
|
|
216
|
+
const refMetadata = constantReferences.get(varName);
|
|
217
|
+
if (refMetadata) {
|
|
218
|
+
const refContent = createReferenceContent(refMetadata.category, refMetadata.name, references);
|
|
219
|
+
if (refContent) {
|
|
220
|
+
content += refContent;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Handle type assertions: {ref as tskb.Folders['Name']}
|
|
225
|
+
else if (ts.isAsExpression(n.expression)) {
|
|
226
|
+
const refContent = extractReferenceFromTypeAssertion(n.expression, references);
|
|
227
|
+
if (refContent) {
|
|
228
|
+
content += refContent;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Recursively visit other nodes
|
|
233
|
+
else {
|
|
234
|
+
ts.forEachChild(n, visit);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
visit(node);
|
|
238
|
+
return content.trim();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Extract references from type assertions like: {ref as tskb.Folders['Name']}
|
|
242
|
+
*/
|
|
243
|
+
function extractReferenceFromTypeAssertion(assertion, references) {
|
|
244
|
+
const metadata = extractTypeAssertionMetadata(assertion);
|
|
245
|
+
if (metadata) {
|
|
246
|
+
return createReferenceContent(metadata.category, metadata.name, references);
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Create reference content and add to the appropriate references array
|
|
252
|
+
*/
|
|
253
|
+
function createReferenceContent(category, name, references) {
|
|
254
|
+
if (category === "Folders") {
|
|
255
|
+
references.folders.push(name);
|
|
256
|
+
return `[Folder: ${name}]`;
|
|
257
|
+
}
|
|
258
|
+
else if (category === "Modules") {
|
|
259
|
+
references.modules.push(name);
|
|
260
|
+
return `[Module: ${name}]`;
|
|
261
|
+
}
|
|
262
|
+
else if (category === "Terms") {
|
|
263
|
+
references.terms.push(name);
|
|
264
|
+
return `[Term: ${name}]`;
|
|
265
|
+
}
|
|
266
|
+
else if (category === "Exports") {
|
|
267
|
+
references.exports.push(name);
|
|
268
|
+
return `[Export: ${name}]`;
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get the value of a "name" attribute from JSX attributes
|
|
274
|
+
*/
|
|
275
|
+
function getNameAttribute(attributes) {
|
|
276
|
+
for (const prop of attributes.properties) {
|
|
277
|
+
if (ts.isJsxAttribute(prop) &&
|
|
278
|
+
ts.isIdentifier(prop.name) &&
|
|
279
|
+
prop.name.text === "name" &&
|
|
280
|
+
prop.initializer &&
|
|
281
|
+
ts.isStringLiteral(prop.initializer)) {
|
|
282
|
+
return prop.initializer.text;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get the code function from a "code" attribute and convert it to string
|
|
289
|
+
*/
|
|
290
|
+
function getCodeAttribute(attributes) {
|
|
291
|
+
for (const prop of attributes.properties) {
|
|
292
|
+
if (ts.isJsxAttribute(prop) &&
|
|
293
|
+
ts.isIdentifier(prop.name) &&
|
|
294
|
+
prop.name.text === "code" &&
|
|
295
|
+
prop.initializer &&
|
|
296
|
+
ts.isJsxExpression(prop.initializer) &&
|
|
297
|
+
prop.initializer.expression) {
|
|
298
|
+
// Get the source text of the function
|
|
299
|
+
const sourceFile = prop.getSourceFile();
|
|
300
|
+
const codeText = prop.initializer.expression.getText(sourceFile);
|
|
301
|
+
return codeText;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Extract ADR metadata attributes (id, title, status, date, deciders)
|
|
308
|
+
*/
|
|
309
|
+
function getAdrAttributes(attributes) {
|
|
310
|
+
const attrs = [];
|
|
311
|
+
for (const prop of attributes.properties) {
|
|
312
|
+
if (ts.isJsxAttribute(prop) && ts.isIdentifier(prop.name)) {
|
|
313
|
+
const attrName = prop.name.text;
|
|
314
|
+
if (["id", "title", "status", "date", "deciders"].includes(attrName)) {
|
|
315
|
+
if (prop.initializer && ts.isStringLiteral(prop.initializer)) {
|
|
316
|
+
attrs.push(`${attrName}="${prop.initializer.text}"`);
|
|
317
|
+
}
|
|
318
|
+
else if (prop.initializer &&
|
|
319
|
+
ts.isJsxExpression(prop.initializer) &&
|
|
320
|
+
prop.initializer.expression) {
|
|
321
|
+
const sourceFile = prop.getSourceFile();
|
|
322
|
+
const value = prop.initializer.expression.getText(sourceFile);
|
|
323
|
+
attrs.push(`${attrName}="${value.replace(/"/g, '\\"')}"`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return attrs.length > 0 ? attrs.join(" ") : undefined;
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=documentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documentation.js","sourceRoot":"","sources":["../../../src/core/extraction/documentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAC;AAkB7B;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CACzB,OAAmB,EACnB,SAAsB,EACtB,OAAe;IAEf,MAAM,IAAI,GAAmB,EAAE,CAAC;IAEhC,yEAAyE;IACzE,MAAM,mBAAmB,GAAG,IAAI,GAAG,CACjC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CACtE,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;QAClD,4CAA4C;QAC5C,MAAM,oBAAoB,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;QAEnF,sEAAsE;QACtE,IAAI,mBAAmB,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1F,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,GAAG,EAAE,CAAC;gBACR,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,UAAyB,EAAE,OAAe;IACpE,MAAM,UAAU,GAAG;QACjB,OAAO,EAAE,EAAc;QACvB,KAAK,EAAE,EAA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UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;oBAC9D,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extraction Module - Extracts registry and documentation from TypeScript source files
|
|
3
|
+
*
|
|
4
|
+
* Public API for extracting knowledge base information from .tskb files.
|
|
5
|
+
*/
|
|
6
|
+
import { extractRegistry } from "./registry.js";
|
|
7
|
+
import { extractDocs } from "./documentation.js";
|
|
8
|
+
export type { ExtractedRegistry } from "./registry.js";
|
|
9
|
+
export type { ExtractedDoc } from "./documentation.js";
|
|
10
|
+
export { extractRegistry, extractDocs };
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/extraction/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extraction Module - Extracts registry and documentation from TypeScript source files
|
|
3
|
+
*
|
|
4
|
+
* Public API for extracting knowledge base information from .tskb files.
|
|
5
|
+
*/
|
|
6
|
+
import { extractRegistry } from "./registry.js";
|
|
7
|
+
import { extractDocs } from "./documentation.js";
|
|
8
|
+
export { extractRegistry, extractDocs };
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/extraction/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* Registry data extracted from TypeScript declaration merging
|
|
4
|
+
*/
|
|
5
|
+
export interface ExtractedRegistry {
|
|
6
|
+
folders: Map<string, {
|
|
7
|
+
desc: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
resolvedPath?: string;
|
|
10
|
+
pathExists: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
modules: Map<string, {
|
|
13
|
+
desc: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
importPath?: string;
|
|
16
|
+
resolvedPath?: string;
|
|
17
|
+
pathExists: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
terms: Map<string, string>;
|
|
20
|
+
exports: Map<string, {
|
|
21
|
+
desc: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
importPath?: string;
|
|
24
|
+
resolvedPath?: string;
|
|
25
|
+
pathExists: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extracts the vocabulary (Folders, Modules, Terms) from the TypeScript type system.
|
|
30
|
+
*
|
|
31
|
+
* This uses the TypeScript compiler API to resolve the global `tskb` namespace
|
|
32
|
+
* and extract all declaration-merged interfaces.
|
|
33
|
+
*
|
|
34
|
+
* @param program - TypeScript program containing the source files
|
|
35
|
+
* @param baseDir - Base directory for resolving and storing relative paths (typically tsconfig rootDir)
|
|
36
|
+
* @param tsconfigPath - Path to tsconfig.json (for reading additional config if needed)
|
|
37
|
+
* @returns Extracted registry data
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractRegistry(program: ts.Program, baseDir: string, tsconfigPath: string): ExtractedRegistry;
|
|
40
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/core/extraction/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAClG,OAAO,EAAE,GAAG,CACV,MAAM,EACN;QACE,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,OAAO,CAAC;KACrB,CACF,CAAC;IACF,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,EAAE,GAAG,CACV,MAAM,EACN;QACE,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,OAAO,CAAC;KACrB,CACF,CAAC;CACH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,GACnB,iBAAiB,CA4BnB"}
|