@@ -37,14 +37,17 @@ export async function run(ctx: CommandContext<typeof meta>) {
3737 const providedPath =
3838 ctx . positionals . length > 1 ? ctx . positionals [ 1 ] : undefined ;
3939 const logLevel = ctx . values [ 'log-level' ] ;
40- let root : string | undefined = undefined ;
40+ const jsonOutput = ctx . values [ 'json' ] ;
41+ let root : string | undefined ;
4142
4243 // Enable debug output based on log level
4344 if ( logLevel === 'debug' ) {
4445 enableDebug ( 'e18e:*' ) ;
4546 }
4647
47- prompts . intro ( 'Analyzing...' ) ;
48+ if ( ! jsonOutput ) {
49+ prompts . intro ( 'Analyzing...' ) ;
50+ }
4851
4952 // Path can be a directory (analyze project)
5053 if ( providedPath ) {
@@ -56,7 +59,11 @@ export async function run(ctx: CommandContext<typeof meta>) {
5659 }
5760
5861 if ( ! stat || ! stat . isDirectory ( ) ) {
59- prompts . cancel ( `Path must be a directory: ${ providedPath } ` ) ;
62+ if ( jsonOutput ) {
63+ process . stderr . write ( `Path must be a directory: ${ providedPath } \n` ) ;
64+ } else {
65+ prompts . cancel ( `Path must be a directory: ${ providedPath } ` ) ;
66+ }
6067 process . exit ( 1 ) ;
6168 }
6269
@@ -71,6 +78,19 @@ export async function run(ctx: CommandContext<typeof meta>) {
7178 manifest : customManifests
7279 } ) ;
7380
81+ const thresholdRank = FAIL_THRESHOLD_RANK [ logLevel ] ?? 0 ;
82+ const hasFailingMessages =
83+ thresholdRank > 0 &&
84+ messages . some ( ( m ) => SEVERITY_RANK [ m . severity ] >= thresholdRank ) ;
85+
86+ if ( jsonOutput ) {
87+ process . stdout . write ( JSON . stringify ( { stats, messages} , null , 2 ) + '\n' ) ;
88+ if ( hasFailingMessages ) {
89+ process . exit ( 1 ) ;
90+ }
91+ return ;
92+ }
93+
7494 prompts . log . info ( 'Summary' ) ;
7595
7696 const totalDeps =
@@ -197,10 +217,6 @@ export async function run(ctx: CommandContext<typeof meta>) {
197217 prompts . outro ( 'Done!' ) ;
198218
199219 // Exit with non-zero when messages meet the fail threshold (--log-level)
200- const thresholdRank = FAIL_THRESHOLD_RANK [ logLevel ] ?? 0 ;
201- const hasFailingMessages =
202- thresholdRank > 0 &&
203- messages . some ( ( m ) => SEVERITY_RANK [ m . severity ] >= thresholdRank ) ;
204220 if ( hasFailingMessages ) {
205221 process . exit ( 1 ) ;
206222 }
0 commit comments