@voodocs/cli 0.1.0
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 +37 -0
- package/README.md +153 -0
- package/USAGE.md +314 -0
- package/cli.py +1340 -0
- package/examples/.cursorrules +437 -0
- package/examples/instructions/.claude/instructions.md +372 -0
- package/examples/instructions/.cursorrules +437 -0
- package/examples/instructions/.windsurfrules +437 -0
- package/examples/instructions/VOODOCS_INSTRUCTIONS.md +437 -0
- package/examples/math_example.py +41 -0
- package/examples/phase2_test.py +24 -0
- package/examples/test_compound_conditions.py +40 -0
- package/examples/test_math_example.py +186 -0
- package/lib/darkarts/README.md +115 -0
- package/lib/darkarts/__init__.py +16 -0
- package/lib/darkarts/annotations/__init__.py +34 -0
- package/lib/darkarts/annotations/parser.py +618 -0
- package/lib/darkarts/annotations/types.py +181 -0
- package/lib/darkarts/cli.py +128 -0
- package/lib/darkarts/core/__init__.py +32 -0
- package/lib/darkarts/core/interface.py +256 -0
- package/lib/darkarts/core/loader.py +231 -0
- package/lib/darkarts/core/plugin.py +215 -0
- package/lib/darkarts/core/registry.py +146 -0
- package/lib/darkarts/exceptions.py +51 -0
- package/lib/darkarts/parsers/typescript/dist/cli.d.ts +9 -0
- package/lib/darkarts/parsers/typescript/dist/cli.d.ts.map +1 -0
- package/lib/darkarts/parsers/typescript/dist/cli.js +69 -0
- package/lib/darkarts/parsers/typescript/dist/cli.js.map +1 -0
- package/lib/darkarts/parsers/typescript/dist/parser.d.ts +111 -0
- package/lib/darkarts/parsers/typescript/dist/parser.d.ts.map +1 -0
- package/lib/darkarts/parsers/typescript/dist/parser.js +365 -0
- package/lib/darkarts/parsers/typescript/dist/parser.js.map +1 -0
- package/lib/darkarts/parsers/typescript/package-lock.json +51 -0
- package/lib/darkarts/parsers/typescript/package.json +19 -0
- package/lib/darkarts/parsers/typescript/src/cli.ts +41 -0
- package/lib/darkarts/parsers/typescript/src/parser.ts +408 -0
- package/lib/darkarts/parsers/typescript/tsconfig.json +19 -0
- package/lib/darkarts/plugins/voodocs/__init__.py +379 -0
- package/lib/darkarts/plugins/voodocs/ai_native_plugin.py +151 -0
- package/lib/darkarts/plugins/voodocs/annotation_validator.py +280 -0
- package/lib/darkarts/plugins/voodocs/api_spec_generator.py +486 -0
- package/lib/darkarts/plugins/voodocs/documentation_generator.py +610 -0
- package/lib/darkarts/plugins/voodocs/html_exporter.py +260 -0
- package/lib/darkarts/plugins/voodocs/instruction_generator.py +706 -0
- package/lib/darkarts/plugins/voodocs/pdf_exporter.py +66 -0
- package/lib/darkarts/plugins/voodocs/test_generator.py +636 -0
- package/package.json +70 -0
- package/requirements.txt +13 -0
- package/templates/ci/github-actions.yml +73 -0
- package/templates/ci/gitlab-ci.yml +35 -0
- package/templates/ci/pre-commit-hook.sh +26 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* CLI wrapper for the TypeScript annotation parser
|
|
5
|
+
*
|
|
6
|
+
* Usage: darkarts-ts-parser <file_path>
|
|
7
|
+
* Output: JSON to stdout
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
const parser_1 = require("./parser");
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
function main() {
|
|
46
|
+
const args = process.argv.slice(2);
|
|
47
|
+
if (args.length === 0) {
|
|
48
|
+
console.error('Usage: darkarts-ts-parser <file_path>');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const filePath = args[0];
|
|
52
|
+
// Check if file exists
|
|
53
|
+
if (!fs.existsSync(filePath)) {
|
|
54
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const parser = new parser_1.TypeScriptAnnotationParser(filePath);
|
|
59
|
+
const result = parser.parse();
|
|
60
|
+
// Output JSON to stdout
|
|
61
|
+
console.log(JSON.stringify(result, null, 2));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(`Error parsing file: ${error}`);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
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,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript/JavaScript Parser for DarkArts Annotations
|
|
3
|
+
*
|
|
4
|
+
* This parser uses the TypeScript Compiler API to extract @voodocs
|
|
5
|
+
* annotations from TypeScript and JavaScript files.
|
|
6
|
+
*/
|
|
7
|
+
interface Annotation {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
interface FunctionInfo {
|
|
11
|
+
name: string;
|
|
12
|
+
line: number;
|
|
13
|
+
parameters: string[];
|
|
14
|
+
return_type: string | null;
|
|
15
|
+
annotations: Annotation;
|
|
16
|
+
is_async: boolean;
|
|
17
|
+
is_exported: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface ClassInfo {
|
|
20
|
+
name: string;
|
|
21
|
+
line: number;
|
|
22
|
+
annotations: Annotation;
|
|
23
|
+
methods: FunctionInfo[];
|
|
24
|
+
is_exported: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface ParseResult {
|
|
27
|
+
file_path: string;
|
|
28
|
+
language: string;
|
|
29
|
+
module_annotations: Annotation;
|
|
30
|
+
classes: ClassInfo[];
|
|
31
|
+
functions: FunctionInfo[];
|
|
32
|
+
interfaces: InterfaceInfo[];
|
|
33
|
+
}
|
|
34
|
+
interface InterfaceInfo {
|
|
35
|
+
name: string;
|
|
36
|
+
line: number;
|
|
37
|
+
annotations: Annotation;
|
|
38
|
+
is_exported: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare class TypeScriptAnnotationParser {
|
|
41
|
+
private filePath;
|
|
42
|
+
private sourceFile;
|
|
43
|
+
private sourceText;
|
|
44
|
+
constructor(filePath: string);
|
|
45
|
+
/**
|
|
46
|
+
* Parse the TypeScript file and extract all @voodocs annotations
|
|
47
|
+
*/
|
|
48
|
+
parse(): ParseResult;
|
|
49
|
+
/**
|
|
50
|
+
* Extract module-level annotations from the top of the file
|
|
51
|
+
*/
|
|
52
|
+
private extractModuleAnnotations;
|
|
53
|
+
/**
|
|
54
|
+
* Parse a class declaration
|
|
55
|
+
*/
|
|
56
|
+
private parseClass;
|
|
57
|
+
/**
|
|
58
|
+
* Parse a function declaration
|
|
59
|
+
*/
|
|
60
|
+
private parseFunction;
|
|
61
|
+
/**
|
|
62
|
+
* Parse a method declaration
|
|
63
|
+
*/
|
|
64
|
+
private parseMethod;
|
|
65
|
+
/**
|
|
66
|
+
* Parse an interface declaration
|
|
67
|
+
*/
|
|
68
|
+
private parseInterface;
|
|
69
|
+
/**
|
|
70
|
+
* Extract annotations from a node's JSDoc comments
|
|
71
|
+
*/
|
|
72
|
+
private extractAnnotations;
|
|
73
|
+
/**
|
|
74
|
+
* Get leading comments for a node
|
|
75
|
+
*/
|
|
76
|
+
private getLeadingComments;
|
|
77
|
+
/**
|
|
78
|
+
* Check if a comment contains @voodocs annotation
|
|
79
|
+
*/
|
|
80
|
+
private isDarkArtsComment;
|
|
81
|
+
/**
|
|
82
|
+
* Parse the annotation text and extract key-value pairs
|
|
83
|
+
*/
|
|
84
|
+
private parseAnnotationText;
|
|
85
|
+
/**
|
|
86
|
+
* Parse a value (string, array, or object)
|
|
87
|
+
*/
|
|
88
|
+
private parseValue;
|
|
89
|
+
/**
|
|
90
|
+
* Extract parameter names from a function/method
|
|
91
|
+
*/
|
|
92
|
+
private extractParameters;
|
|
93
|
+
/**
|
|
94
|
+
* Extract return type from a function/method
|
|
95
|
+
*/
|
|
96
|
+
private extractReturnType;
|
|
97
|
+
/**
|
|
98
|
+
* Check if a function/method is async
|
|
99
|
+
*/
|
|
100
|
+
private isAsync;
|
|
101
|
+
/**
|
|
102
|
+
* Check if a node is exported
|
|
103
|
+
*/
|
|
104
|
+
private isExported;
|
|
105
|
+
/**
|
|
106
|
+
* Get the line number of a node
|
|
107
|
+
*/
|
|
108
|
+
private getLineNumber;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","s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H,OAAO,CAAC,WAAW;IAenB;;OAEG;IACH,OAAO,CAAC,cAAc;IAYtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAe1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA2C3B;;OAEG;IACH,OAAO,CAAC,UAAU;IAmElB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;OAEG;IACH,OAAO,CAAC,OAAO;IAQf;;OAEG;IACH,OAAO,CAAC,UAAU;IAQlB;;OAEG;IACH,OAAO,CAAC,aAAa;CAItB"}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript/JavaScript Parser for DarkArts Annotations
|
|
4
|
+
*
|
|
5
|
+
* This parser uses the TypeScript Compiler API to extract @voodocs
|
|
6
|
+
* annotations from TypeScript and JavaScript files.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.TypeScriptAnnotationParser = void 0;
|
|
43
|
+
const ts = __importStar(require("typescript"));
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
class TypeScriptAnnotationParser {
|
|
46
|
+
constructor(filePath) {
|
|
47
|
+
this.filePath = filePath;
|
|
48
|
+
this.sourceText = fs.readFileSync(filePath, 'utf-8');
|
|
49
|
+
this.sourceFile = ts.createSourceFile(filePath, this.sourceText, ts.ScriptTarget.Latest, true);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse the TypeScript file and extract all @voodocs annotations
|
|
53
|
+
*/
|
|
54
|
+
parse() {
|
|
55
|
+
const result = {
|
|
56
|
+
file_path: this.filePath,
|
|
57
|
+
language: this.filePath.endsWith('.ts') ? 'typescript' : 'javascript',
|
|
58
|
+
module_annotations: this.extractModuleAnnotations(),
|
|
59
|
+
classes: [],
|
|
60
|
+
functions: [],
|
|
61
|
+
interfaces: []
|
|
62
|
+
};
|
|
63
|
+
// Visit all nodes in the AST
|
|
64
|
+
const visit = (node) => {
|
|
65
|
+
if (ts.isClassDeclaration(node)) {
|
|
66
|
+
const classInfo = this.parseClass(node);
|
|
67
|
+
if (classInfo) {
|
|
68
|
+
result.classes.push(classInfo);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (ts.isFunctionDeclaration(node)) {
|
|
72
|
+
const funcInfo = this.parseFunction(node);
|
|
73
|
+
if (funcInfo) {
|
|
74
|
+
result.functions.push(funcInfo);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (ts.isInterfaceDeclaration(node)) {
|
|
78
|
+
const interfaceInfo = this.parseInterface(node);
|
|
79
|
+
if (interfaceInfo) {
|
|
80
|
+
result.interfaces.push(interfaceInfo);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
ts.forEachChild(node, visit);
|
|
84
|
+
};
|
|
85
|
+
visit(this.sourceFile);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extract module-level annotations from the top of the file
|
|
90
|
+
*/
|
|
91
|
+
extractModuleAnnotations() {
|
|
92
|
+
const leadingComments = this.getLeadingComments(this.sourceFile);
|
|
93
|
+
for (const comment of leadingComments) {
|
|
94
|
+
if (this.isDarkArtsComment(comment)) {
|
|
95
|
+
return this.parseAnnotationText(comment);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Parse a class declaration
|
|
102
|
+
*/
|
|
103
|
+
parseClass(node) {
|
|
104
|
+
const name = node.name?.text;
|
|
105
|
+
if (!name)
|
|
106
|
+
return null;
|
|
107
|
+
const line = this.getLineNumber(node);
|
|
108
|
+
const annotations = this.extractAnnotations(node);
|
|
109
|
+
const methods = [];
|
|
110
|
+
// Extract methods
|
|
111
|
+
node.members.forEach(member => {
|
|
112
|
+
if (ts.isMethodDeclaration(member)) {
|
|
113
|
+
const methodInfo = this.parseMethod(member);
|
|
114
|
+
if (methodInfo) {
|
|
115
|
+
methods.push(methodInfo);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
name,
|
|
121
|
+
line,
|
|
122
|
+
annotations,
|
|
123
|
+
methods,
|
|
124
|
+
is_exported: this.isExported(node)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parse a function declaration
|
|
129
|
+
*/
|
|
130
|
+
parseFunction(node) {
|
|
131
|
+
const name = node.name?.text;
|
|
132
|
+
if (!name)
|
|
133
|
+
return null;
|
|
134
|
+
return {
|
|
135
|
+
name,
|
|
136
|
+
line: this.getLineNumber(node),
|
|
137
|
+
parameters: this.extractParameters(node),
|
|
138
|
+
return_type: this.extractReturnType(node),
|
|
139
|
+
annotations: this.extractAnnotations(node),
|
|
140
|
+
is_async: this.isAsync(node),
|
|
141
|
+
is_exported: this.isExported(node)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Parse a method declaration
|
|
146
|
+
*/
|
|
147
|
+
parseMethod(node) {
|
|
148
|
+
const name = node.name.text;
|
|
149
|
+
if (!name)
|
|
150
|
+
return null;
|
|
151
|
+
return {
|
|
152
|
+
name,
|
|
153
|
+
line: this.getLineNumber(node),
|
|
154
|
+
parameters: this.extractParameters(node),
|
|
155
|
+
return_type: this.extractReturnType(node),
|
|
156
|
+
annotations: this.extractAnnotations(node),
|
|
157
|
+
is_async: this.isAsync(node),
|
|
158
|
+
is_exported: false // Methods are not directly exported
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Parse an interface declaration
|
|
163
|
+
*/
|
|
164
|
+
parseInterface(node) {
|
|
165
|
+
const name = node.name.text;
|
|
166
|
+
if (!name)
|
|
167
|
+
return null;
|
|
168
|
+
return {
|
|
169
|
+
name,
|
|
170
|
+
line: this.getLineNumber(node),
|
|
171
|
+
annotations: this.extractAnnotations(node),
|
|
172
|
+
is_exported: this.isExported(node)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Extract annotations from a node's JSDoc comments
|
|
177
|
+
*/
|
|
178
|
+
extractAnnotations(node) {
|
|
179
|
+
const comments = this.getLeadingComments(node);
|
|
180
|
+
// Find the LAST (closest) @voodocs comment
|
|
181
|
+
let lastDarkArtsComment = null;
|
|
182
|
+
for (const comment of comments) {
|
|
183
|
+
if (this.isDarkArtsComment(comment)) {
|
|
184
|
+
lastDarkArtsComment = comment;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (lastDarkArtsComment) {
|
|
188
|
+
return this.parseAnnotationText(lastDarkArtsComment);
|
|
189
|
+
}
|
|
190
|
+
return {};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get leading comments for a node
|
|
194
|
+
*/
|
|
195
|
+
getLeadingComments(node) {
|
|
196
|
+
const comments = [];
|
|
197
|
+
const fullText = this.sourceText;
|
|
198
|
+
const nodePos = node.getFullStart();
|
|
199
|
+
const ranges = ts.getLeadingCommentRanges(fullText, nodePos);
|
|
200
|
+
if (ranges) {
|
|
201
|
+
for (const range of ranges) {
|
|
202
|
+
const commentText = fullText.substring(range.pos, range.end);
|
|
203
|
+
comments.push(commentText);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return comments;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Check if a comment contains @voodocs annotation
|
|
210
|
+
*/
|
|
211
|
+
isDarkArtsComment(comment) {
|
|
212
|
+
return comment.includes('@voodocs');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Parse the annotation text and extract key-value pairs
|
|
216
|
+
*/
|
|
217
|
+
parseAnnotationText(comment) {
|
|
218
|
+
const annotation = {};
|
|
219
|
+
// Remove comment markers
|
|
220
|
+
let text = comment.replace(/^\/\*\*?|\*\/$/g, '').trim();
|
|
221
|
+
text = text.replace(/^\s*\*\s?/gm, ''); // Remove leading asterisks
|
|
222
|
+
// Remove @voodocs marker
|
|
223
|
+
text = text.replace(/@voodocs\s*/i, '');
|
|
224
|
+
// Parse key-value pairs
|
|
225
|
+
const lines = text.split('\n');
|
|
226
|
+
let currentKey = null;
|
|
227
|
+
let currentValue = [];
|
|
228
|
+
for (const line of lines) {
|
|
229
|
+
const trimmed = line.trim();
|
|
230
|
+
if (!trimmed)
|
|
231
|
+
continue;
|
|
232
|
+
// Check if this is a new key
|
|
233
|
+
const keyMatch = trimmed.match(/^(\w+):\s*(.*)$/);
|
|
234
|
+
if (keyMatch) {
|
|
235
|
+
// Save previous key-value pair
|
|
236
|
+
if (currentKey) {
|
|
237
|
+
annotation[currentKey] = this.parseValue(currentValue.join('\n'));
|
|
238
|
+
}
|
|
239
|
+
currentKey = keyMatch[1];
|
|
240
|
+
currentValue = [keyMatch[2]];
|
|
241
|
+
}
|
|
242
|
+
else if (currentKey) {
|
|
243
|
+
// Continue current value
|
|
244
|
+
currentValue.push(trimmed);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Save last key-value pair
|
|
248
|
+
if (currentKey) {
|
|
249
|
+
annotation[currentKey] = this.parseValue(currentValue.join('\n'));
|
|
250
|
+
}
|
|
251
|
+
return annotation;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Parse a value (string, array, or object)
|
|
255
|
+
*/
|
|
256
|
+
parseValue(value) {
|
|
257
|
+
value = value.trim();
|
|
258
|
+
// Try to parse as JSON array
|
|
259
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
260
|
+
try {
|
|
261
|
+
// Extract array content
|
|
262
|
+
const content = value.slice(1, -1).trim();
|
|
263
|
+
if (!content)
|
|
264
|
+
return [];
|
|
265
|
+
// Split by newlines first (each line is typically one item)
|
|
266
|
+
const items = [];
|
|
267
|
+
let currentItem = '';
|
|
268
|
+
let inQuotes = false;
|
|
269
|
+
let quoteChar = '';
|
|
270
|
+
for (let i = 0; i < content.length; i++) {
|
|
271
|
+
const char = content[i];
|
|
272
|
+
if ((char === '"' || char === "'") && (i === 0 || content[i - 1] !== '\\')) {
|
|
273
|
+
if (!inQuotes) {
|
|
274
|
+
inQuotes = true;
|
|
275
|
+
quoteChar = char;
|
|
276
|
+
}
|
|
277
|
+
else if (char === quoteChar) {
|
|
278
|
+
inQuotes = false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (char === ',' && !inQuotes) {
|
|
282
|
+
if (currentItem.trim()) {
|
|
283
|
+
items.push(currentItem.trim());
|
|
284
|
+
}
|
|
285
|
+
currentItem = '';
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
currentItem += char;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Add the last item
|
|
292
|
+
if (currentItem.trim()) {
|
|
293
|
+
items.push(currentItem.trim());
|
|
294
|
+
}
|
|
295
|
+
// Clean up each item
|
|
296
|
+
return items.map(item => {
|
|
297
|
+
item = item.trim();
|
|
298
|
+
// Remove surrounding quotes
|
|
299
|
+
if ((item.startsWith('"') && item.endsWith('"')) ||
|
|
300
|
+
(item.startsWith("'") && item.endsWith("'"))) {
|
|
301
|
+
return item.slice(1, -1);
|
|
302
|
+
}
|
|
303
|
+
return item;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
catch (e) {
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Remove quotes if present
|
|
311
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
312
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
313
|
+
return value.slice(1, -1);
|
|
314
|
+
}
|
|
315
|
+
return value;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Extract parameter names from a function/method
|
|
319
|
+
*/
|
|
320
|
+
extractParameters(node) {
|
|
321
|
+
return node.parameters.map(param => {
|
|
322
|
+
const name = param.name.text;
|
|
323
|
+
const type = param.type ? `: ${param.type.getText(this.sourceFile)}` : '';
|
|
324
|
+
return `${name}${type}`;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Extract return type from a function/method
|
|
329
|
+
*/
|
|
330
|
+
extractReturnType(node) {
|
|
331
|
+
if (node.type) {
|
|
332
|
+
return node.type.getText(this.sourceFile);
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Check if a function/method is async
|
|
338
|
+
*/
|
|
339
|
+
isAsync(node) {
|
|
340
|
+
if (ts.canHaveModifiers(node)) {
|
|
341
|
+
const modifiers = ts.getModifiers(node);
|
|
342
|
+
return modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) || false;
|
|
343
|
+
}
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Check if a node is exported
|
|
348
|
+
*/
|
|
349
|
+
isExported(node) {
|
|
350
|
+
if (ts.canHaveModifiers(node)) {
|
|
351
|
+
const modifiers = ts.getModifiers(node);
|
|
352
|
+
return modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) || false;
|
|
353
|
+
}
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get the line number of a node
|
|
358
|
+
*/
|
|
359
|
+
getLineNumber(node) {
|
|
360
|
+
const { line } = this.sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
361
|
+
return line + 1; // Convert to 1-indexed
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
exports.TypeScriptAnnotationParser = TypeScriptAnnotationParser;
|
|
365
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AACjC,uCAAyB;AAyCzB,MAAa,0BAA0B;IAIrC,YAAoB,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;QAClC,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,CAAC;YACxC,OAAO,SAAS,EAAE,IAAI,CAAC,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC;QAC7F,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,IAAa;QAC9B,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,SAAS,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACxC,OAAO,SAAS,EAAE,IAAI,CAAC,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC;QAC9F,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,IAAa;QACjC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChF,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,uBAAuB;IAC1C,CAAC;CACF;AAtWD,gEAsWC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@darkarts/typescript-parser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "@darkarts/typescript-parser",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"typescript": "^5.3.0"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"darkarts-ts-parser": "dist/cli.js"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^20.10.0"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"node_modules/@types/node": {
|
|
21
|
+
"version": "20.19.26",
|
|
22
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.26.tgz",
|
|
23
|
+
"integrity": "sha512-0l6cjgF0XnihUpndDhk+nyD3exio3iKaYROSgvh/qSevPXax3L8p5DBRFjbvalnwatGgHEQn2R88y2fA3g4irg==",
|
|
24
|
+
"dev": true,
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"undici-types": "~6.21.0"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"node_modules/typescript": {
|
|
31
|
+
"version": "5.9.3",
|
|
32
|
+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
|
33
|
+
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
|
34
|
+
"license": "Apache-2.0",
|
|
35
|
+
"bin": {
|
|
36
|
+
"tsc": "bin/tsc",
|
|
37
|
+
"tsserver": "bin/tsserver"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=14.17"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"node_modules/undici-types": {
|
|
44
|
+
"version": "6.21.0",
|
|
45
|
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
|
46
|
+
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
|
47
|
+
"dev": true,
|
|
48
|
+
"license": "MIT"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@darkarts/typescript-parser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript/JavaScript parser for DarkArts annotations",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"darkarts-ts-parser": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"test": "node dist/test.js"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"typescript": "^5.3.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^20.10.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CLI wrapper for the TypeScript annotation parser
|
|
5
|
+
*
|
|
6
|
+
* Usage: darkarts-ts-parser <file_path>
|
|
7
|
+
* Output: JSON to stdout
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { TypeScriptAnnotationParser } from './parser';
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
|
|
13
|
+
function main() {
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
console.error('Usage: darkarts-ts-parser <file_path>');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const filePath = args[0];
|
|
22
|
+
|
|
23
|
+
// Check if file exists
|
|
24
|
+
if (!fs.existsSync(filePath)) {
|
|
25
|
+
console.error(`Error: File not found: ${filePath}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const parser = new TypeScriptAnnotationParser(filePath);
|
|
31
|
+
const result = parser.parse();
|
|
32
|
+
|
|
33
|
+
// Output JSON to stdout
|
|
34
|
+
console.log(JSON.stringify(result, null, 2));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(`Error parsing file: ${error}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
main();
|