@@ -7,6 +7,8 @@ import { updateMetadata as updateMetadataFile } from './metadata-manager'
77import  matter  from  'gray-matter' 
88import  {  analyzeContent  }  from  './metadata-analyzer' 
99import  {  MetadataResult  }  from  './types/metadata-types' 
10+ import  {  generateMetadata  }  from  './metadata-manager' 
11+ import  globby  from  'globby' 
1012
1113// @ts -ignore 
1214const  globModule  =  await  import ( 'glob' ) 
@@ -174,12 +176,12 @@ async function processFiles(files: string[], options: CliOptions): Promise<{
174176      const  content  =  await  fs . readFile ( file ,  'utf8' ) 
175177      const  {  data : frontmatter  }  =  matter ( content ) 
176178      const  analysis  =  analyzeContent ( content ,  file ,  options . verbose ) 
177-       const  result  =  await  updateMetadataFile ( file ,  {   
178-         dryRun : true , 
179-         verbose : false , 
179+       const  result  =  await  updateMetadataFile ( file ,  { 
180+         dryRun : options . dryRun , 
181+         verbose : options . verbose , 
180182        analysis, 
181-         validateOnly : true , 
182-         prMode : true 
183+         validateOnly : false , 
184+         prMode : false 
183185      } ) 
184186
185187      console . log ( `\n${ colors . blue }  📄 ${ file } ${ colors . reset }  ` ) 
@@ -199,7 +201,7 @@ async function processFiles(files: string[], options: CliOptions): Promise<{
199201        stats . needsReview ++ 
200202      }  else  { 
201203        if  ( ! options . dryRun )  { 
202-           await  updateMetadataFile ( file ,  {   
204+           await  updateMetadataFile ( file ,  { 
203205            dryRun : false , 
204206            verbose : options . verbose  ||  false , 
205207            analysis, 
@@ -231,50 +233,70 @@ async function processFiles(files: string[], options: CliOptions): Promise<{
231233
232234async  function  main ( )  { 
233235  try  { 
234-     console . log ( 'Checking metadata...' ) 
236+     const  isDryRun  =  process . argv . includes ( '--dry-run' ) 
237+     const  isVerbose  =  process . argv . includes ( '--verbose' ) 
235238
236-     let  modifiedFiles : string [ ]  =  [ ] 
237-     
238-     // Check if we have a direct glob pattern argument 
239-     const  globPattern  =  process . argv . find ( arg  =>  arg . includes ( '*.mdx' ) ) 
240-     if  ( globPattern )  { 
241-       modifiedFiles  =  await  globModule . glob ( globPattern ) 
239+     // Get files from either CHANGED_FILES or command line glob patterns 
240+     let  mdxFiles  =  [ ] 
241+     if  ( process . env . CHANGED_FILES )  { 
242+       mdxFiles  =  process . env . CHANGED_FILES . split ( '\n' ) . filter ( Boolean ) 
242243    }  else  { 
243-       // Fall back to CHANGED_FILES if no glob pattern 
244-       const  gitOutput  =  process . env . CHANGED_FILES  ||  '' 
245-       modifiedFiles  =  gitOutput 
246-         . split ( '\n' ) 
247-         . filter ( file  =>  file . trim ( ) ) 
248-         . filter ( file  =>  file . endsWith ( '.mdx' ) ) 
249-         . map ( file  =>  path . resolve ( process . cwd ( ) ,  file ) ) 
250-     } 
251- 
252-     if  ( modifiedFiles . length  ===  0 )  { 
253-       console . log ( `${ colors . green }  ✓ No MDX files to check${ colors . reset }  ` ) 
254-       process . exit ( 0 ) 
244+       // Get glob patterns from command line args (skip the first two args) 
245+       const  patterns  =  process . argv . slice ( 2 ) . filter ( arg  =>  ! arg . startsWith ( '--' ) ) 
246+       if  ( patterns . length  >  0 )  { 
247+         mdxFiles  =  await  globby ( patterns ) 
248+       } 
255249    } 
256- 
257-     // Validate file paths 
258-     const  validFiles  =  await  validateFilePaths ( modifiedFiles ) 
259250
260-     if  ( validFiles . length  ===  0 )  { 
261-       console . log ( `${ colors . yellow }  ⚠️  No valid files to check${ colors . reset }  ` ) 
251+     mdxFiles  =  mdxFiles . filter ( file  =>  file . endsWith ( '.mdx' ) ) 
252+     
253+     if  ( mdxFiles . length  ===  0 )  { 
254+       console . log ( '✓ No MDX files to check' ) 
262255      process . exit ( 0 ) 
263256    } 
264257
265-     console . log ( `Found ${ validFiles . length }   valid files to check` ) 
258+     console . log ( `Found ${ mdxFiles . length }   valid files to check\n ` ) 
266259
267-     const  options : CliOptions  =  { 
268-       dryRun : process . argv . includes ( '--dry-run' ) , 
269-       verbose : process . argv . includes ( '--verbose' ) 
260+     let  processedCount  =  0 
261+     let  needsReviewCount  =  0 
262+     
263+     for  ( const  file  of  mdxFiles )  { 
264+       try  { 
265+         const  metadata  =  await  generateMetadata ( file ) 
266+         const  result  =  await  updateMetadataFile ( file ,  { 
267+           dryRun : isDryRun , 
268+           verbose : isVerbose , 
269+           validateOnly : false , 
270+           prMode : false , 
271+           analysis : metadata 
272+         } ) 
273+         
274+         processedCount ++ 
275+         
276+         // Show metadata for each file 
277+         console . log ( `\nFile: ${ file }  ` ) 
278+         console . log ( 'Categories:' ,  metadata . categories ?. join ( ', ' )  ||  'none' ) 
279+         
280+         if  ( ! result . isValid )  { 
281+           needsReviewCount ++ 
282+           console . log ( '\x1b[33m⚠️  Review needed:\x1b[0m' ) 
283+           result . errors . forEach ( error  =>  console . log ( `  → ${ error }  ` ) ) 
284+         } 
285+       }  catch  ( error )  { 
286+         console . error ( `Error processing ${ file }  :` ,  error ) 
287+       } 
270288    } 
271289
272-     const  {  hasErrors,  stats }  =  await  processFiles ( validFiles ,  options ) 
273-     // Don't exit with error code - we want this to be non-blocking 
274-     process . exit ( 0 ) 
290+     // Summary with colors 
291+     console . log ( `\n${ processedCount }   files processed` ) 
292+     if  ( needsReviewCount  ===  0 )  { 
293+       console . log ( '\x1b[32m✓ All files have valid metadata\x1b[0m' ) 
294+     }  else  { 
295+       console . log ( `\x1b[33m⚠️  ${ needsReviewCount }   files need review\x1b[0m` ) 
296+     } 
275297  }  catch  ( error )  { 
276-     console . error ( ` ${ colors . yellow } ⚠️  Error:  ${ error } ${ colors . reset } ` ) 
277-     process . exit ( 0 ) 
298+     console . error ( '\x1b[31mError:\x1b[0m' ,   error ) 
299+     process . exit ( 1 ) 
278300  } 
279301} 
280302
0 commit comments