@@ -9,21 +9,23 @@ import { basename } from 'node:path'
99import { Project } from 'ts-morph'
1010import { emit_dts } from './emit'
1111
12- export async function extractinator ( input : string , output : string , tsdocConfigPath ?: string ) {
12+ export interface ExtractinatorOptions {
13+ tsdocConfigPath ?: string
14+ input : string
15+ }
16+
17+ export async function extractinator ( options : ExtractinatorOptions ) {
1318 const project = new Project ( )
1419
1520 //? Generate the .d.ts files
16- const dts = await emit_dts ( input )
21+ const dts = await emit_dts ( options . input )
1722
1823 //? Load all the generated .d.ts files
1924 for ( const dts_path of dts . dts_file_map . keys ( ) ) {
2025 project . addSourceFileAtPath ( dts_path )
2126 }
2227
23- //? Make sure the output directory exists
24- await mkdir ( output , { recursive : true } )
25-
26- const tsdoc = createTSDocParser ( tsdocConfigPath )
28+ const tsdoc = createTSDocParser ( options . tsdocConfigPath )
2729
2830 //? Map of input_file_path:file
2931 const parsed_files = new Map < string , ParsedFile > ( )
@@ -87,15 +89,7 @@ export async function extractinator(input: string, output: string, tsdocConfigPa
8789 n ( )
8890 }
8991
90- for ( const [ input_file_path , file ] of parsed_files ) {
91- // todo could potentially collide
92- await writeFile (
93- `${ output } /${ basename ( input_file_path ) } .doc.json` ,
94- JSON . stringify ( file , null , 2 ) ,
95- 'utf-8' ,
96- )
97- }
98-
99- //? Cleanup
10092 await dts . cleanup ( )
93+
94+ return Array . from ( parsed_files . values ( ) )
10195}
0 commit comments