11#!/usr/bin/env bun
22
3- import { readdir } from "node:fs/promises" ;
3+ import { mkdir } from "node:fs/promises" ;
44import path from "node:path" ;
55import { z } from "zod" ;
66
@@ -410,14 +410,14 @@ async function main() {
410410
411411 const apiModels = parsed . data . data ;
412412
413- // Get existing files
413+ // Get existing files (recursively)
414414 const existingFiles = new Set < string > ( ) ;
415415 try {
416- const files = await readdir ( modelsDir ) ;
417- for ( const file of files ) {
418- if ( file . endsWith ( ".toml" ) ) {
419- existingFiles . add ( file ) ;
420- }
416+ for await ( const file of new Bun . Glob ( "**/*.toml" ) . scan ( {
417+ cwd : modelsDir ,
418+ absolute : false ,
419+ } ) ) {
420+ existingFiles . add ( file ) ;
421421 }
422422 } catch {
423423 // Directory might not exist yet
@@ -435,41 +435,40 @@ async function main() {
435435 let unchanged = 0 ;
436436
437437 for ( const apiModel of apiModels ) {
438- const safeId = apiModel . id . replace ( / \/ / g , "-" ) ;
439- const filename = ` ${ safeId } .toml` ;
440- const filePath = path . join ( modelsDir , filename ) ;
438+ const relativePath = ` ${ apiModel . id } .toml` ;
439+ const filePath = path . join ( modelsDir , relativePath ) ;
440+ const dirPath = path . dirname ( filePath ) ;
441441
442- apiModelIds . add ( filename ) ;
442+ apiModelIds . add ( relativePath ) ;
443443
444444 const existing = await loadExistingModel ( filePath ) ;
445445 const merged = mergeModel ( apiModel , existing ) ;
446446 const tomlContent = formatToml ( merged ) ;
447447
448448 if ( existing === null ) {
449- // New file
450449 created ++ ;
451450 if ( dryRun ) {
452- console . log ( `[DRY RUN] Would create: ${ filename } ` ) ;
451+ console . log ( `[DRY RUN] Would create: ${ relativePath } ` ) ;
453452 console . log ( ` name = "${ merged . name } "` ) ;
454453 if ( merged . family ) {
455454 console . log ( ` family = "${ merged . family } " (inferred)` ) ;
456455 }
457456 console . log ( "" ) ;
458457 } else {
458+ await mkdir ( dirPath , { recursive : true } ) ;
459459 await Bun . write ( filePath , tomlContent ) ;
460- console . log ( `Created: ${ filename } ` ) ;
460+ console . log ( `Created: ${ relativePath } ` ) ;
461461 }
462462 } else {
463- // Check for changes
464463 const changes = detectChanges ( existing , merged ) ;
465464
466465 if ( changes . length > 0 ) {
467466 updated ++ ;
468467 if ( dryRun ) {
469- console . log ( `[DRY RUN] Would update: ${ filename } ` ) ;
468+ console . log ( `[DRY RUN] Would update: ${ relativePath } ` ) ;
470469 } else {
471470 await Bun . write ( filePath , tomlContent ) ;
472- console . log ( `Updated: ${ filename } ` ) ;
471+ console . log ( `Updated: ${ relativePath } ` ) ;
473472 }
474473 for ( const change of changes ) {
475474 console . log ( ` ${ change . field } : ${ change . oldValue } → ${ change . newValue } ` ) ;
0 commit comments