@@ -20,6 +20,7 @@ import { formatFixOptions } from '@/utils/styles';
2020import type { CodeRefError , FixOptions , FixResult } from '@/utils/types' ;
2121import { extractCodeRefs , findMarkdownFiles , validateCodeRef } from '@/core/validate' ;
2222import { loadFixConfig , getDocsPath , type CodeRefFixConfig } from '@/config' ;
23+ import { msg } from '@/utils/message-formatter' ;
2324
2425// Parse command line arguments
2526function parseArgs ( ) : FixOptions {
@@ -86,23 +87,28 @@ export async function main(): Promise<void> {
8687 verbose : options . verbose ,
8788 } ) ;
8889
89- console . log ( '🔧 Starting CODE_REF error fixes...\n' ) ;
90+ // Set verbose mode for message formatter
91+ msg . setVerbose ( options . verbose ) ;
92+
93+ console . log ( `${ msg . startFix ( 'Starting CODE_REF error fixes...' ) } \n` ) ;
9094
9195 if ( options . dryRun ) {
92- console . log ( '⚠️ DRY RUN mode: No actual changes will be made\n' ) ;
96+ console . log ( ` ${ msg . warning ( ' DRY RUN mode: No actual changes will be made' ) } \n` ) ;
9397 }
9498
9599 // Collect errors
96100 const errorGroups = collectErrors ( config ) ;
97101
98102 if ( errorGroups . length === 0 ) {
99- console . log ( '✅ No fixable errors found') ;
103+ console . log ( msg . success ( ' No fixable errors found') ) ;
100104 process . exit ( 0 ) ;
101105 }
102106
103107 // Statistics
104108 const totalErrors = errorGroups . reduce ( ( sum , g ) => sum + g . errors . length , 0 ) ;
105- console . log ( `📊 Detected ${ totalErrors } fixable error(s) in ${ errorGroups . length } file(s)\n` ) ;
109+ console . log (
110+ `${ msg . info ( `Detected ${ totalErrors } fixable error(s) in ${ errorGroups . length } file(s)` ) } \n`
111+ ) ;
106112
107113 // Interactive interface
108114 const rl = createPromptInterface ( ) ;
@@ -111,8 +117,8 @@ export async function main(): Promise<void> {
111117
112118 try {
113119 for ( const group of errorGroups ) {
114- console . log ( `\n📄 ${ path . relative ( config . projectRoot , group . docFile ) } ` ) ;
115- console . log ( ` ${ group . errors . length } error(s)\n` ) ;
120+ console . log ( `\n${ msg . file ( path . relative ( config . projectRoot , group . docFile ) ) } ` ) ;
121+ console . log ( `${ msg . context ( ` ${ group . errors . length } error(s)` ) } \n` ) ;
116122
117123 // Sort errors in descending order by docLineNumber (bottom to top)
118124 // To prevent fixes at the bottom from affecting line numbers at the top
@@ -125,10 +131,8 @@ export async function main(): Promise<void> {
125131 let _lineOffset = 0 ; // Track cumulative offset (for future edge case handling)
126132
127133 for ( const error of sortedErrors ) {
128- console . log ( `\n❌ ${ error . type } : ${ error . message } ` ) ;
129- console . log (
130- ` Reference: ${ path . relative ( config . projectRoot , error . ref . docFile ) } ${ error . ref . docLineNumber ? `:${ error . ref . docLineNumber } ` : '' } `
131- ) ;
134+ const location = `${ path . relative ( config . projectRoot , error . ref . docFile ) } ${ error . ref . docLineNumber ? `:${ error . ref . docLineNumber } ` : '' } ` ;
135+ console . log ( `\n${ msg . errorDetail ( error . type , error . message , location ) } ` ) ;
132136
133137 // Create fix action
134138 let action ;
@@ -141,12 +145,12 @@ export async function main(): Promise<void> {
141145
142146 // If there are multiple options, let the user choose
143147 if ( Array . isArray ( fixActionResult ) ) {
144- console . log ( '\n🛠️ Please select a fix method:\n' ) ;
148+ console . log ( `\n ${ msg . info ( ' Please select a fix method:' ) } \n` ) ;
145149 console . log ( formatFixOptions ( fixActionResult ) ) ;
146150
147151 if ( options . auto ) {
148152 // Auto-select first option in auto mode
149- console . log ( ' ℹ️ Auto-selecting option 1 in auto mode\n' ) ;
153+ console . log ( ` ${ msg . context ( ' Auto-selecting option 1 in auto mode' ) } \n` ) ;
150154 action = fixActionResult [ 0 ] ;
151155 } else {
152156 // Let user choose
@@ -156,14 +160,14 @@ export async function main(): Promise<void> {
156160 if ( num >= 1 && num <= fixActionResult . length ) {
157161 resolve ( num - 1 ) ;
158162 } else {
159- console . log ( ' ⚠️ Invalid selection. Skipping.') ;
163+ console . log ( msg . context ( ' Invalid selection. Skipping.') ) ;
160164 resolve ( - 1 ) ;
161165 }
162166 } ) ;
163167 } ) ;
164168
165169 if ( selection === - 1 ) {
166- console . log ( ' ⏭️ Skipped') ;
170+ console . log ( msg . context ( ' Skipped') ) ;
167171 continue ;
168172 }
169173
@@ -175,7 +179,7 @@ export async function main(): Promise<void> {
175179 }
176180
177181 if ( ! action ) {
178- console . log ( ' ⚠️ This error cannot be fixed') ;
182+ console . log ( msg . context ( ' This error cannot be fixed') ) ;
179183 continue ;
180184 }
181185
@@ -191,13 +195,13 @@ export async function main(): Promise<void> {
191195 }
192196
193197 if ( ! shouldFix ) {
194- console . log ( ' ⏭️ Skipped') ;
198+ console . log ( msg . context ( ' Skipped') ) ;
195199 continue ;
196200 }
197201
198202 // Dry run check
199203 if ( options . dryRun ) {
200- console . log ( ' ✅ [DRY RUN] Simulated fix') ;
204+ console . log ( msg . context ( ' [DRY RUN] Simulated fix') ) ;
201205 fixResults . push ( { success : true , action } ) ;
202206 continue ;
203207 }
@@ -207,7 +211,7 @@ export async function main(): Promise<void> {
207211 if ( ! options . noBackup && ! backupFiles . has ( group . docFile ) ) {
208212 backupPath = createBackup ( group . docFile ) ;
209213 backupFiles . add ( group . docFile ) ;
210- console . log ( ` 💾 Backup created: ${ path . basename ( backupPath ) } `) ;
214+ console . log ( msg . context ( ` Backup created: ${ path . basename ( backupPath ) } `) ) ;
211215 }
212216
213217 // Apply fix
@@ -216,15 +220,15 @@ export async function main(): Promise<void> {
216220 _lineOffset += lineDelta ; // Accumulate offset
217221
218222 // Debug log
219- if ( lineDelta !== 0 ) {
220- console . log ( ` 📊 Line delta: ${ lineDelta > 0 ? '+' : '' } ${ lineDelta } ` ) ;
223+ if ( lineDelta !== 0 && options . verbose ) {
224+ console . log ( msg . debug ( ` Line delta: ${ lineDelta > 0 ? '+' : '' } ${ lineDelta } ` ) ) ;
221225 }
222226
223- console . log ( ' ✅ Fix applied') ;
227+ console . log ( msg . context ( ' Fix applied') ) ;
224228 fixResults . push ( { success : true , action, backupPath } ) ;
225229 } catch ( err ) {
226230 const errorMsg = err instanceof Error ? err . message : String ( err ) ;
227- console . log ( ` ❌ Fix failed: ${ errorMsg } `) ;
231+ console . log ( msg . context ( ` Fix failed: ${ errorMsg } `) ) ;
228232 fixResults . push ( { success : false , action, error : errorMsg , backupPath } ) ;
229233 }
230234 }
@@ -234,30 +238,23 @@ export async function main(): Promise<void> {
234238 }
235239
236240 // Result summary
237- console . log ( `\n${ '=' . repeat ( 60 ) } ` ) ;
238- console . log ( '📊 Fix Results Summary\n' ) ;
239-
240241 const successful = fixResults . filter ( ( r ) => r . success ) . length ;
241242 const failed = fixResults . filter ( ( r ) => ! r . success ) . length ;
242243
243- console . log ( `✅ Successful: ${ successful } ` ) ;
244- console . log ( `❌ Failed: ${ failed } ` ) ;
244+ const backupPaths =
245+ ! options . noBackup && backupFiles . size > 0
246+ ? Array . from ( backupFiles ) . map ( ( file ) => path . relative ( config . projectRoot , `${ file } .backup` ) )
247+ : [ ] ;
245248
246- if ( backupFiles . size > 0 && ! options . noBackup ) {
247- console . log ( `\n💾 Backup files: ${ backupFiles . size } ` ) ;
248- for ( const file of backupFiles ) {
249- const backupPath = `${ file } .backup` ;
250- console . log ( ` ${ path . relative ( config . projectRoot , backupPath ) } ` ) ;
251- }
252- }
249+ console . log ( msg . summary ( successful , failed , backupPaths ) ) ;
253250
254251 process . exit ( failed > 0 ? 1 : 0 ) ;
255252}
256253
257254// When executed as a script
258255if ( require . main === module ) {
259256 main ( ) . catch ( ( error ) => {
260- console . error ( '\n❌ An error occurred:' , error ) ;
257+ console . error ( `\n ${ msg . error ( ` An error occurred: ${ error } ` ) } ` ) ;
261258 process . exit ( 1 ) ;
262259 } ) ;
263260}
0 commit comments