@@ -69,7 +69,7 @@ async function openGraphViewer(fileSystem: any): Promise<void> {
6969/**
7070 * Format and display dependency analysis summary
7171 */
72- function displaySummary ( result : AnalysisResult ) : void {
72+ function displaySummary ( result : AnalysisResult , asJson : boolean = false ) : void {
7373 const { summary, nodes, relationships, cycles } = result ;
7474
7575 // Maximum number of examples to display for each category
@@ -110,7 +110,52 @@ function displaySummary(result: AnalysisResult): void {
110110 . slice ( 0 , MAX_EXAMPLES )
111111 . filter ( ( [ _ , count ] ) => count > 0 ) ;
112112
113- // Output summary
113+ // JSON output mode
114+ if ( asJson ) {
115+ const componentTypesObj : Record < string , any > = { } ;
116+ for ( const [ type , count ] of componentTypes . entries ( ) ) {
117+ const examples = Array . from ( nodes . entries ( ) )
118+ . filter ( ( [ _ , node ] ) => node . componentType === type )
119+ . slice ( 0 , MAX_EXAMPLES )
120+ . map ( ( [ id , _ ] ) => id ) ;
121+ componentTypesObj [ type ] = { count, examples } ;
122+ }
123+
124+ const jsonOutput = {
125+ summary : {
126+ totalFiles : summary . totalFiles ,
127+ totalNodes : summary . totalNodes ,
128+ totalRelationships : summary . totalRelationships ,
129+ languages : summary . languages ,
130+ cycleCount : cycles . length ,
131+ } ,
132+ componentTypes : componentTypesObj ,
133+ topModules : topModules . map ( ( [ module , count ] ) => ( { module, dependencies : count } ) ) ,
134+ relationships : {
135+ resolved : {
136+ count : resolvedEdges . length ,
137+ examples : resolvedEdges . slice ( 0 , MAX_EXAMPLES ) . map ( edge => ( {
138+ caller : edge . caller ,
139+ callee : edge . callee ,
140+ callLine : edge . callLine ,
141+ } ) ) ,
142+ } ,
143+ unresolved : {
144+ count : unresolvedEdges . length ,
145+ examples : unresolvedEdges . slice ( 0 , MAX_EXAMPLES ) . map ( edge => ( {
146+ caller : edge . caller ,
147+ callee : edge . callee ,
148+ callLine : edge . callLine ,
149+ } ) ) ,
150+ } ,
151+ } ,
152+ } ;
153+
154+ console . log ( JSON . stringify ( jsonOutput , null , 2 ) ) ;
155+ return ;
156+ }
157+
158+ // Text output mode (original)
114159 console . log ( '\nDependency Analysis Summary' ) ;
115160 console . log ( '==========================' ) ;
116161 console . log ( `Files: ${ summary . totalFiles } ` ) ;
@@ -466,7 +511,7 @@ async function callHandler(targetPath: string | undefined, options: CommandOptio
466511 }
467512 } else {
468513 // Summary mode (default) - Task 2
469- displaySummary ( result ) ;
514+ displaySummary ( result , options . json ) ;
470515 }
471516
472517 // Display errors if any
0 commit comments