@@ -7,6 +7,7 @@ export type FileSystemWriterOptions = {
77 outputDir : string ;
88 inMemoryOnly ?: boolean ;
99 logger ?: CodegenLogger ;
10+ resolveAssets ?: ( fn : string ) => string ;
1011} ;
1112
1213export type WriterOptions = FileSystemWriterOptions & {
@@ -82,7 +83,11 @@ export abstract class FileSystemWriter<T extends FileSystemWriterOptions = FileS
8283
8384 this . logger ( ) ?. debug ( `cat > '${ relPath } '` ) ;
8485 this . currentFile = { descriptor, relPath } ;
85- this . writtenFilesBuffer [ this . currentFile . relPath ] = { relPath, absPath : Path . resolve ( relPath ) , tokens : [ ] } ;
86+ this . writtenFilesBuffer [ this . currentFile . relPath ] = {
87+ relPath,
88+ absPath : Path . resolve ( relPath ) ,
89+ tokens : [ ] ,
90+ } ;
8691
8792 gen ( ) ;
8893 } finally {
@@ -100,12 +105,25 @@ export abstract class FileSystemWriter<T extends FileSystemWriterOptions = FileS
100105 buf . tokens . push ( str ) ;
101106 }
102107
108+ cp ( source : string , destination : string ) {
109+ if ( ! this . opts . resolveAssets ) throw new Error ( "resolveAssets is not defined" ) ;
110+ source = Path . resolve ( this . opts . resolveAssets ( source ) ) ;
111+ destination = Path . normalize ( `${ this . currentDir ?? this . opts . outputDir } /${ destination } ` ) ;
112+ const content = fs . readFileSync ( source , "utf8" ) ;
113+ this . writtenFilesBuffer [ destination ] = {
114+ relPath : destination ,
115+ absPath : Path . resolve ( destination ) ,
116+ tokens : [ content ] ,
117+ } ;
118+ fs . cpSync ( source , destination ) ;
119+ }
120+
103121 abstract generate ( _tsIndex : TypeSchemaIndex ) : Promise < void > ;
104122
105123 writtenFiles ( ) : FileBuffer [ ] {
106124 return Object . values ( this . writtenFilesBuffer )
107125 . map ( ( { relPath, absPath, tokens } ) => {
108- return { relPath, absPath, content : tokens . join ( ) } ;
126+ return { relPath, absPath, content : tokens . join ( "" ) } ;
109127 } )
110128 . sort ( ( a , b ) => a . relPath . localeCompare ( b . relPath ) ) ;
111129 }
0 commit comments