@@ -31,22 +31,6 @@ export const generate = async (config?: GenerateConfig): Promise<void> => {
3131 const { dirname } = await import ( "node:path" ) ;
3232 const { pathToFileURL } = await import ( "node:url" ) ;
3333
34- const writeFile = async ( path : string , data : ReadableStream < Uint8Array > ) => {
35- if ( typeof Deno === "object" ) {
36- return Deno . writeFile ( path , data ) ;
37- } else {
38- const { createWriteStream } = await import ( "node:fs" ) ;
39- const { Readable } = await import ( "node:stream" ) ;
40- return new Promise < void > ( ( resolve , reject ) =>
41- // deno-lint-ignore no-explicit-any
42- Readable . fromWeb ( data as any )
43- . pipe ( createWriteStream ( path ) )
44- . on ( "finish" , resolve )
45- . on ( "error" , reject )
46- ) ;
47- }
48- } ;
49-
5034 const { outFolder = "generated" , pregenerateOnly = false } = config || { } ;
5135 const pregenerateAll = ! pregenerateOnly ;
5236
@@ -63,7 +47,22 @@ export const generate = async (config?: GenerateConfig): Promise<void> => {
6347 await fs . mkdir ( dirname ( outFilePath ) , { recursive : true } ) ;
6448 const { body } = file . response ;
6549 if ( body ) {
66- writeFile ( outFilePath , body ) ;
50+ if ( typeof Deno === "object" ) {
51+ return Deno . writeFile ( outFilePath , body ) ;
52+ } else if ( process . versions . bun ) {
53+ // deno-lint-ignore no-explicit-any
54+ return ( globalThis as any ) . Bun . write ( outFilePath , file . response ) ;
55+ } else {
56+ const { createWriteStream } = await import ( "node:fs" ) ;
57+ const { Readable } = await import ( "node:stream" ) ;
58+ return new Promise < void > ( ( resolve , reject ) =>
59+ // deno-lint-ignore no-explicit-any
60+ Readable . fromWeb ( body as any )
61+ . pipe ( createWriteStream ( outFilePath ) )
62+ . on ( "finish" , resolve )
63+ . on ( "error" , reject )
64+ ) ;
65+ }
6766 }
6867 }
6968 }
0 commit comments