@@ -3,10 +3,17 @@ import { existsSync } from "node:fs";
33import os from "node:os" ;
44import path from "node:path" ;
55import { Command } from "commander" ;
6- import { OPEN_BASE_URL , SCORE_GOOD_THRESHOLD , SCORE_OK_THRESHOLD } from "./constants.js" ;
6+ import { AMI_INSTALL_URL , AMI_RELEASES_URL , AMI_WEBSITE_URL , OPEN_BASE_URL } from "./constants.js" ;
77import { scan } from "./scan.js" ;
8- import type { Diagnostic , DiffInfo , EstimatedScoreResult , ScanOptions } from "./types.js" ;
8+ import type {
9+ Diagnostic ,
10+ DiffInfo ,
11+ EstimatedScoreResult ,
12+ ReactDoctorConfig ,
13+ ScanOptions ,
14+ } from "./types.js" ;
915import { fetchEstimatedScore } from "./utils/calculate-score.js" ;
16+ import { colorizeByScore } from "./utils/colorize-by-score.js" ;
1017import { createFramedLine , renderFramedBoxString } from "./utils/framed-box.js" ;
1118import { filterSourceFiles , getDiffInfo } from "./utils/get-diff-files.js" ;
1219import { handleError } from "./utils/handle-error.js" ;
@@ -43,6 +50,36 @@ const exitWithFixHint = () => {
4350process . on ( "SIGINT" , exitWithFixHint ) ;
4451process . on ( "SIGTERM" , exitWithFixHint ) ;
4552
53+ const AUTOMATED_ENVIRONMENT_VARIABLES = [
54+ "CI" ,
55+ "CLAUDECODE" ,
56+ "CURSOR_AGENT" ,
57+ "CODEX_CI" ,
58+ "OPENCODE" ,
59+ "AMP_HOME" ,
60+ "AMI" ,
61+ ] ;
62+
63+ const isAutomatedEnvironment = ( ) : boolean =>
64+ AUTOMATED_ENVIRONMENT_VARIABLES . some ( ( envVariable ) => Boolean ( process . env [ envVariable ] ) ) ;
65+
66+ const resolveCliScanOptions = (
67+ flags : CliFlags ,
68+ userConfig : ReactDoctorConfig | null ,
69+ programInstance : Command ,
70+ ) : ScanOptions => {
71+ const isCliOverride = ( optionName : string ) =>
72+ programInstance . getOptionValueSource ( optionName ) === "cli" ;
73+
74+ return {
75+ lint : isCliOverride ( "lint" ) ? flags . lint : ( userConfig ?. lint ?? flags . lint ) ,
76+ deadCode : isCliOverride ( "deadCode" ) ? flags . deadCode : ( userConfig ?. deadCode ?? flags . deadCode ) ,
77+ verbose : isCliOverride ( "verbose" ) ? Boolean ( flags . verbose ) : ( userConfig ?. verbose ?? false ) ,
78+ scoreOnly : flags . score ,
79+ offline : flags . offline ,
80+ } ;
81+ } ;
82+
4683const resolveDiffMode = async (
4784 diffInfo : DiffInfo | null ,
4885 effectiveDiff : boolean | string | undefined ,
@@ -105,37 +142,17 @@ const program = new Command()
105142 logger . break ( ) ;
106143 }
107144
108- const isCliOverride = ( optionName : string ) =>
109- program . getOptionValueSource ( optionName ) === "cli" ;
110-
111- const scanOptions : ScanOptions = {
112- lint : isCliOverride ( "lint" ) ? flags . lint : ( userConfig ?. lint ?? flags . lint ) ,
113- deadCode : isCliOverride ( "deadCode" )
114- ? flags . deadCode
115- : ( userConfig ?. deadCode ?? flags . deadCode ) ,
116- verbose : isCliOverride ( "verbose" ) ? Boolean ( flags . verbose ) : ( userConfig ?. verbose ?? false ) ,
117- scoreOnly : isScoreOnly ,
118- offline : flags . offline ,
119- } ;
120-
121- const isAutomatedEnvironment = [
122- process . env . CI ,
123- process . env . CLAUDECODE ,
124- process . env . CURSOR_AGENT ,
125- process . env . CODEX_CI ,
126- process . env . OPENCODE ,
127- process . env . AMP_HOME ,
128- process . env . AMI ,
129- ] . some ( Boolean ) ;
130- const shouldSkipPrompts = flags . yes || isAutomatedEnvironment || ! process . stdin . isTTY ;
145+ const scanOptions = resolveCliScanOptions ( flags , userConfig , program ) ;
146+ const shouldSkipPrompts = flags . yes || isAutomatedEnvironment ( ) || ! process . stdin . isTTY ;
131147 const shouldSkipAmiPrompts = shouldSkipPrompts || ! flags . ami ;
132148 const projectDirectories = await selectProjects (
133149 resolvedDirectory ,
134150 flags . project ,
135151 shouldSkipPrompts ,
136152 ) ;
137153
138- const effectiveDiff = isCliOverride ( "diff" ) ? flags . diff : userConfig ?. diff ;
154+ const isDiffCliOverride = program . getOptionValueSource ( "diff" ) === "cli" ;
155+ const effectiveDiff = isDiffCliOverride ? flags . diff : userConfig ?. diff ;
139156 const explicitBaseBranch = typeof effectiveDiff === "string" ? effectiveDiff : undefined ;
140157 const diffInfo = getDiffInfo ( resolvedDirectory , explicitBaseBranch ) ;
141158 const isDiffMode = await resolveDiffMode (
@@ -209,16 +226,6 @@ ${highlighter.dim("Learn more:")}
209226` ,
210227 ) ;
211228
212- const AMI_WEBSITE_URL = "https://ami.dev" ;
213- const AMI_INSTALL_URL = `${ AMI_WEBSITE_URL } /install.sh` ;
214- const AMI_RELEASES_URL = "https://github.com/millionco/ami-releases/releases" ;
215-
216- const colorizeByScore = ( text : string , score : number ) : string => {
217- if ( score >= SCORE_GOOD_THRESHOLD ) return highlighter . success ( text ) ;
218- if ( score >= SCORE_OK_THRESHOLD ) return highlighter . warn ( text ) ;
219- return highlighter . error ( text ) ;
220- } ;
221-
222229const DEEPLINK_FIX_PROMPT = "/{slash-command:ami:react-doctor}" ;
223230
224231const isAmiInstalled = ( ) : boolean => {
0 commit comments