11#!/usr/bin/env node
22
33import { Command } from 'commander' ;
4- import * as path from 'path' ;
4+ import fs from 'fs' ;
5+ import path from 'path' ;
56import { RepositoryParser } from './parser/RepositoryParser' ;
6- import * as fs from 'fs ' ;
7+ import { JsonStreamStringify } from 'json-stream-stringify ' ;
78
89const program = new Command ( ) ;
910
@@ -43,22 +44,22 @@ program
4344
4445 // Output the repository JSON file
4546 const outputPath = path . resolve ( options . output ) ;
46- const jsonOutput = options . pretty
47- ? JSON . stringify ( repository , null , 2 )
48- : JSON . stringify ( repository ) ;
47+ const jsonStream = new JsonStreamStringify ( repository , undefined , options . pretty ? 2 : undefined ) ;
48+ const fileStream = fs . createWriteStream ( outputPath ) ;
49+ jsonStream . pipe ( fileStream ) ;
4950
50- fs . writeFileSync ( outputPath , jsonOutput ) ;
51+ fileStream . on ( 'finish' , ( ) => {
52+ console . log ( `Repository has been parsed and saved to ${ outputPath } ` ) ;
53+ } ) ;
5154
52- console . log ( `Successfully parsed repository` ) ;
53- console . log ( `Output written to: ${ outputPath } ` ) ;
54- console . log ( `Total modules: ${ Object . keys ( repository . Modules ) . length } ` ) ;
55- console . log ( `Total symbols in graph: ${ Object . keys ( repository . Graph ) . length } ` ) ;
55+ fileStream . on ( 'error' , ( err ) => {
56+ console . error ( 'Error writing to file:' , err ) ;
57+ } ) ;
5658
5759 } catch ( error ) {
5860 console . error ( 'Error parsing repository:' , error ) ;
5961 process . exit ( 1 ) ;
6062 }
6163 } ) ;
6264
63-
6465program . parse ( ) ;
0 commit comments