@opensyntaxhq/autodocs-core 1.0.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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @opensyntaxhq/autodocs-core
2
+
3
+ Core parsing and extraction engine for Autodocs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @opensyntaxhq/autodocs-core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { VERSION } from '@opensyntaxhq/autodocs-core';
15
+
16
+ console.log(VERSION);
17
+ ```
@@ -0,0 +1,236 @@
1
+ import ts from 'typescript';
2
+
3
+ interface ParserOptions {
4
+ configFile?: string;
5
+ compilerOptions?: ts.CompilerOptions;
6
+ exclude?: string[];
7
+ include?: string[];
8
+ skipLibCheck?: boolean;
9
+ }
10
+ interface ParseResult {
11
+ program: ts.Program;
12
+ typeChecker: ts.TypeChecker;
13
+ sourceFiles: ts.SourceFile[];
14
+ diagnostics: ts.Diagnostic[];
15
+ rootDir: string;
16
+ }
17
+ declare function createProgram(entryFiles: string[], options?: ParserOptions): ParseResult;
18
+ declare function resolveModules(_program: ts.Program, sourceFile: ts.SourceFile): string[];
19
+ declare function getDependencies(program: ts.Program, filePath: string): string[];
20
+
21
+ type DocKind = 'interface' | 'type' | 'class' | 'function' | 'enum' | 'variable' | 'guide';
22
+ interface DocEntry {
23
+ id: string;
24
+ name: string;
25
+ kind: DocKind;
26
+ fileName: string;
27
+ module?: string;
28
+ source?: SourceLocation;
29
+ position: {
30
+ line: number;
31
+ column: number;
32
+ };
33
+ signature: string;
34
+ documentation?: DocComment;
35
+ metadata?: Record<string, unknown>;
36
+ typeParameters?: TypeParameter[];
37
+ members?: Member[];
38
+ parameters?: Parameter[];
39
+ returnType?: TypeInfo;
40
+ heritage?: Heritage[];
41
+ modifiers?: string[];
42
+ references?: Reference[];
43
+ }
44
+ interface SourceLocation {
45
+ file: string;
46
+ line: number;
47
+ column: number;
48
+ }
49
+ interface DocComment {
50
+ summary: string;
51
+ description?: string;
52
+ tags: DocTag[];
53
+ examples?: CodeExample[];
54
+ params?: DocParam[];
55
+ returns?: string;
56
+ deprecated?: string;
57
+ }
58
+ interface DocTag {
59
+ name: string;
60
+ text: string;
61
+ type?: string;
62
+ paramName?: string;
63
+ }
64
+ interface DocParam {
65
+ name: string;
66
+ type?: string;
67
+ text: string;
68
+ }
69
+ interface TypeParameter {
70
+ name: string;
71
+ constraint?: string;
72
+ default?: string;
73
+ }
74
+ interface Member {
75
+ name: string;
76
+ type: string;
77
+ optional: boolean;
78
+ readonly: boolean;
79
+ documentation?: string;
80
+ kind?: 'property' | 'method' | 'enum';
81
+ value?: string;
82
+ }
83
+ interface Parameter {
84
+ name: string;
85
+ type: string;
86
+ optional: boolean;
87
+ defaultValue?: string;
88
+ rest: boolean;
89
+ documentation?: string;
90
+ }
91
+ interface TypeInfo {
92
+ text: string;
93
+ kind: string;
94
+ }
95
+ interface Heritage {
96
+ id: string;
97
+ name: string;
98
+ kind: 'extends' | 'implements';
99
+ }
100
+ interface Reference {
101
+ id: string;
102
+ name: string;
103
+ }
104
+ interface CodeExample {
105
+ code: string;
106
+ language: string;
107
+ }
108
+
109
+ interface ExtractOptions {
110
+ rootDir?: string;
111
+ }
112
+ declare function extractDocs(program: ts.Program, options?: ExtractOptions): DocEntry[];
113
+ declare function extractDocsFromFiles(program: ts.Program, files: string[], options?: ExtractOptions): DocEntry[];
114
+
115
+ interface JsonGeneratorOptions {
116
+ pretty?: boolean;
117
+ splitByModule?: boolean;
118
+ rootDir?: string;
119
+ }
120
+ declare function generateJson(docs: DocEntry[], outputDir: string, options?: JsonGeneratorOptions): Promise<void>;
121
+
122
+ declare function generateMarkdown(docs: DocEntry[], outputDir: string): Promise<void>;
123
+
124
+ declare function generateHtml(docs: DocEntry[], outputDir: string): Promise<void>;
125
+
126
+ interface Plugin {
127
+ name: string;
128
+ version: string;
129
+ initialize?(context: PluginContext): void | Promise<void>;
130
+ beforeParse?(files: string[]): string[] | Promise<string[]>;
131
+ afterParse?(program: ts.Program): void | Promise<void>;
132
+ beforeExtract?(sourceFiles: ts.SourceFile[]): void | Promise<void>;
133
+ afterExtract?(docs: DocEntry[]): DocEntry[] | Promise<DocEntry[]>;
134
+ beforeGenerate?(docs: DocEntry[]): DocEntry[] | Promise<DocEntry[]>;
135
+ afterGenerate?(outputDir: string): void | Promise<void>;
136
+ cleanup?(): void | Promise<void>;
137
+ }
138
+ interface PluginContext {
139
+ config: unknown;
140
+ logger: Logger;
141
+ cache: Map<string, unknown>;
142
+ emitEvent(name: string, data: unknown): void;
143
+ addHook(name: string, handler: (data: unknown) => void): void;
144
+ }
145
+ interface Logger {
146
+ info(message: string): void;
147
+ warn(message: string): void;
148
+ error(message: string): void;
149
+ debug(message: string): void;
150
+ }
151
+
152
+ declare class PluginManager {
153
+ private plugins;
154
+ private context;
155
+ constructor(config: unknown, logger?: Logger);
156
+ loadPlugin(plugin: Plugin | string): Promise<void>;
157
+ runHook<T>(hookName: keyof Plugin, value: T): Promise<T>;
158
+ cleanup(): Promise<void>;
159
+ private resolvePlugin;
160
+ private resolvePluginExport;
161
+ private getModuleExport;
162
+ private createContext;
163
+ }
164
+
165
+ interface CacheEntry {
166
+ fileHash: string;
167
+ timestamp: number;
168
+ docsFile: string | null;
169
+ dependencies: string[];
170
+ metadata: CacheMetadata;
171
+ }
172
+ interface CacheMetadata {
173
+ version: string;
174
+ tsVersion: string;
175
+ configHash: string;
176
+ }
177
+ interface CacheOptions {
178
+ cacheDir: string;
179
+ enabled?: boolean;
180
+ }
181
+
182
+ declare class FileCache {
183
+ private index;
184
+ private options;
185
+ private indexPath;
186
+ private docsDir;
187
+ private ready;
188
+ constructor(options: CacheOptions);
189
+ getCacheDir(): string;
190
+ getEntry(filePath: string): Promise<CacheEntry | null>;
191
+ readDocs<T = unknown>(entry: CacheEntry): Promise<T[]>;
192
+ getFileHash(filePath: string): Promise<string>;
193
+ set(filePath: string, docs: unknown[], dependencies: string[], metadata: CacheMetadata): Promise<void>;
194
+ invalidate(filePath: string): Promise<void>;
195
+ clear(): Promise<void>;
196
+ private normalize;
197
+ private resolveDocsPath;
198
+ private createDocsFileName;
199
+ private writeDocs;
200
+ private removeDocsFile;
201
+ private pruneOrphanDocs;
202
+ private load;
203
+ private persist;
204
+ private writeJsonAtomic;
205
+ }
206
+
207
+ interface IncrementalBuildOptions {
208
+ files: string[];
209
+ cache: FileCache;
210
+ tsconfig?: string;
211
+ compilerOptions?: ts.CompilerOptions;
212
+ configHash: string;
213
+ onProgram?: (program: ts.Program, sourceFiles: ts.SourceFile[]) => Promise<void> | void;
214
+ }
215
+ interface IncrementalBuildResult {
216
+ docs: DocEntry[];
217
+ changedFiles: string[];
218
+ fromCache: number;
219
+ parsed: number;
220
+ program: ts.Program;
221
+ sourceFiles: ts.SourceFile[];
222
+ rootDir: string;
223
+ diagnostics: ts.Diagnostic[];
224
+ }
225
+ declare function incrementalBuild(options: IncrementalBuildOptions): Promise<IncrementalBuildResult>;
226
+
227
+ interface StaticSiteOptions {
228
+ outputDir: string;
229
+ siteUrl?: string;
230
+ siteName: string;
231
+ }
232
+ declare function generateStaticSite(options: StaticSiteOptions): Promise<void>;
233
+
234
+ declare const VERSION = "1.0.0";
235
+
236
+ export { type CacheEntry, type CacheMetadata, type CacheOptions, type CodeExample, type DocComment, type DocEntry, type DocKind, type DocTag, FileCache, type Heritage, type Logger, type Member, type Parameter, type ParseResult, type ParserOptions, type Plugin, type PluginContext, PluginManager, type Reference, type StaticSiteOptions, type TypeInfo, type TypeParameter, VERSION, createProgram, extractDocs, extractDocsFromFiles, generateHtml, generateJson, generateMarkdown, generateStaticSite, getDependencies, incrementalBuild, resolveModules };
@@ -0,0 +1,236 @@
1
+ import ts from 'typescript';
2
+
3
+ interface ParserOptions {
4
+ configFile?: string;
5
+ compilerOptions?: ts.CompilerOptions;
6
+ exclude?: string[];
7
+ include?: string[];
8
+ skipLibCheck?: boolean;
9
+ }
10
+ interface ParseResult {
11
+ program: ts.Program;
12
+ typeChecker: ts.TypeChecker;
13
+ sourceFiles: ts.SourceFile[];
14
+ diagnostics: ts.Diagnostic[];
15
+ rootDir: string;
16
+ }
17
+ declare function createProgram(entryFiles: string[], options?: ParserOptions): ParseResult;
18
+ declare function resolveModules(_program: ts.Program, sourceFile: ts.SourceFile): string[];
19
+ declare function getDependencies(program: ts.Program, filePath: string): string[];
20
+
21
+ type DocKind = 'interface' | 'type' | 'class' | 'function' | 'enum' | 'variable' | 'guide';
22
+ interface DocEntry {
23
+ id: string;
24
+ name: string;
25
+ kind: DocKind;
26
+ fileName: string;
27
+ module?: string;
28
+ source?: SourceLocation;
29
+ position: {
30
+ line: number;
31
+ column: number;
32
+ };
33
+ signature: string;
34
+ documentation?: DocComment;
35
+ metadata?: Record<string, unknown>;
36
+ typeParameters?: TypeParameter[];
37
+ members?: Member[];
38
+ parameters?: Parameter[];
39
+ returnType?: TypeInfo;
40
+ heritage?: Heritage[];
41
+ modifiers?: string[];
42
+ references?: Reference[];
43
+ }
44
+ interface SourceLocation {
45
+ file: string;
46
+ line: number;
47
+ column: number;
48
+ }
49
+ interface DocComment {
50
+ summary: string;
51
+ description?: string;
52
+ tags: DocTag[];
53
+ examples?: CodeExample[];
54
+ params?: DocParam[];
55
+ returns?: string;
56
+ deprecated?: string;
57
+ }
58
+ interface DocTag {
59
+ name: string;
60
+ text: string;
61
+ type?: string;
62
+ paramName?: string;
63
+ }
64
+ interface DocParam {
65
+ name: string;
66
+ type?: string;
67
+ text: string;
68
+ }
69
+ interface TypeParameter {
70
+ name: string;
71
+ constraint?: string;
72
+ default?: string;
73
+ }
74
+ interface Member {
75
+ name: string;
76
+ type: string;
77
+ optional: boolean;
78
+ readonly: boolean;
79
+ documentation?: string;
80
+ kind?: 'property' | 'method' | 'enum';
81
+ value?: string;
82
+ }
83
+ interface Parameter {
84
+ name: string;
85
+ type: string;
86
+ optional: boolean;
87
+ defaultValue?: string;
88
+ rest: boolean;
89
+ documentation?: string;
90
+ }
91
+ interface TypeInfo {
92
+ text: string;
93
+ kind: string;
94
+ }
95
+ interface Heritage {
96
+ id: string;
97
+ name: string;
98
+ kind: 'extends' | 'implements';
99
+ }
100
+ interface Reference {
101
+ id: string;
102
+ name: string;
103
+ }
104
+ interface CodeExample {
105
+ code: string;
106
+ language: string;
107
+ }
108
+
109
+ interface ExtractOptions {
110
+ rootDir?: string;
111
+ }
112
+ declare function extractDocs(program: ts.Program, options?: ExtractOptions): DocEntry[];
113
+ declare function extractDocsFromFiles(program: ts.Program, files: string[], options?: ExtractOptions): DocEntry[];
114
+
115
+ interface JsonGeneratorOptions {
116
+ pretty?: boolean;
117
+ splitByModule?: boolean;
118
+ rootDir?: string;
119
+ }
120
+ declare function generateJson(docs: DocEntry[], outputDir: string, options?: JsonGeneratorOptions): Promise<void>;
121
+
122
+ declare function generateMarkdown(docs: DocEntry[], outputDir: string): Promise<void>;
123
+
124
+ declare function generateHtml(docs: DocEntry[], outputDir: string): Promise<void>;
125
+
126
+ interface Plugin {
127
+ name: string;
128
+ version: string;
129
+ initialize?(context: PluginContext): void | Promise<void>;
130
+ beforeParse?(files: string[]): string[] | Promise<string[]>;
131
+ afterParse?(program: ts.Program): void | Promise<void>;
132
+ beforeExtract?(sourceFiles: ts.SourceFile[]): void | Promise<void>;
133
+ afterExtract?(docs: DocEntry[]): DocEntry[] | Promise<DocEntry[]>;
134
+ beforeGenerate?(docs: DocEntry[]): DocEntry[] | Promise<DocEntry[]>;
135
+ afterGenerate?(outputDir: string): void | Promise<void>;
136
+ cleanup?(): void | Promise<void>;
137
+ }
138
+ interface PluginContext {
139
+ config: unknown;
140
+ logger: Logger;
141
+ cache: Map<string, unknown>;
142
+ emitEvent(name: string, data: unknown): void;
143
+ addHook(name: string, handler: (data: unknown) => void): void;
144
+ }
145
+ interface Logger {
146
+ info(message: string): void;
147
+ warn(message: string): void;
148
+ error(message: string): void;
149
+ debug(message: string): void;
150
+ }
151
+
152
+ declare class PluginManager {
153
+ private plugins;
154
+ private context;
155
+ constructor(config: unknown, logger?: Logger);
156
+ loadPlugin(plugin: Plugin | string): Promise<void>;
157
+ runHook<T>(hookName: keyof Plugin, value: T): Promise<T>;
158
+ cleanup(): Promise<void>;
159
+ private resolvePlugin;
160
+ private resolvePluginExport;
161
+ private getModuleExport;
162
+ private createContext;
163
+ }
164
+
165
+ interface CacheEntry {
166
+ fileHash: string;
167
+ timestamp: number;
168
+ docsFile: string | null;
169
+ dependencies: string[];
170
+ metadata: CacheMetadata;
171
+ }
172
+ interface CacheMetadata {
173
+ version: string;
174
+ tsVersion: string;
175
+ configHash: string;
176
+ }
177
+ interface CacheOptions {
178
+ cacheDir: string;
179
+ enabled?: boolean;
180
+ }
181
+
182
+ declare class FileCache {
183
+ private index;
184
+ private options;
185
+ private indexPath;
186
+ private docsDir;
187
+ private ready;
188
+ constructor(options: CacheOptions);
189
+ getCacheDir(): string;
190
+ getEntry(filePath: string): Promise<CacheEntry | null>;
191
+ readDocs<T = unknown>(entry: CacheEntry): Promise<T[]>;
192
+ getFileHash(filePath: string): Promise<string>;
193
+ set(filePath: string, docs: unknown[], dependencies: string[], metadata: CacheMetadata): Promise<void>;
194
+ invalidate(filePath: string): Promise<void>;
195
+ clear(): Promise<void>;
196
+ private normalize;
197
+ private resolveDocsPath;
198
+ private createDocsFileName;
199
+ private writeDocs;
200
+ private removeDocsFile;
201
+ private pruneOrphanDocs;
202
+ private load;
203
+ private persist;
204
+ private writeJsonAtomic;
205
+ }
206
+
207
+ interface IncrementalBuildOptions {
208
+ files: string[];
209
+ cache: FileCache;
210
+ tsconfig?: string;
211
+ compilerOptions?: ts.CompilerOptions;
212
+ configHash: string;
213
+ onProgram?: (program: ts.Program, sourceFiles: ts.SourceFile[]) => Promise<void> | void;
214
+ }
215
+ interface IncrementalBuildResult {
216
+ docs: DocEntry[];
217
+ changedFiles: string[];
218
+ fromCache: number;
219
+ parsed: number;
220
+ program: ts.Program;
221
+ sourceFiles: ts.SourceFile[];
222
+ rootDir: string;
223
+ diagnostics: ts.Diagnostic[];
224
+ }
225
+ declare function incrementalBuild(options: IncrementalBuildOptions): Promise<IncrementalBuildResult>;
226
+
227
+ interface StaticSiteOptions {
228
+ outputDir: string;
229
+ siteUrl?: string;
230
+ siteName: string;
231
+ }
232
+ declare function generateStaticSite(options: StaticSiteOptions): Promise<void>;
233
+
234
+ declare const VERSION = "1.0.0";
235
+
236
+ export { type CacheEntry, type CacheMetadata, type CacheOptions, type CodeExample, type DocComment, type DocEntry, type DocKind, type DocTag, FileCache, type Heritage, type Logger, type Member, type Parameter, type ParseResult, type ParserOptions, type Plugin, type PluginContext, PluginManager, type Reference, type StaticSiteOptions, type TypeInfo, type TypeParameter, VERSION, createProgram, extractDocs, extractDocsFromFiles, generateHtml, generateJson, generateMarkdown, generateStaticSite, getDependencies, incrementalBuild, resolveModules };