11import * as fs from "fs" ;
22import * as path from "path" ;
3- import * as ts from "typescript" ;
43import { CompilerOptions , LuaLibImportKind } from "./CompilerOptions" ;
54import { TranspiledFile } from "./Transpile" ;
65
76const trimExt = ( filePath : string ) =>
87 path . join ( path . dirname ( filePath ) , path . basename ( filePath , path . extname ( filePath ) ) ) ;
98
9+ export interface OutputFile {
10+ name : string ;
11+ text : string ;
12+ }
13+
1014let lualibContent : string ;
1115export function emitTranspiledFiles (
1216 options : CompilerOptions ,
13- transpiledFiles : Map < string , TranspiledFile > ,
14- writeFile = ts . sys . writeFile
15- ) : void {
17+ transpiledFiles : Map < string , TranspiledFile >
18+ ) : OutputFile [ ] {
1619 const { rootDir, outDir, outFile, luaLibImport } = options ;
1720
21+ const files : OutputFile [ ] = [ ] ;
1822 for ( const [ fileName , { lua, sourceMap, declaration, declarationMap } ] of transpiledFiles ) {
1923 let outPath = fileName ;
2024 if ( outDir !== rootDir ) {
@@ -35,19 +39,19 @@ export function emitTranspiledFiles(
3539 }
3640
3741 if ( lua !== undefined ) {
38- writeFile ( outPath , lua ) ;
42+ files . push ( { name : outPath , text : lua } ) ;
3943 }
4044
4145 if ( sourceMap !== undefined && options . sourceMap ) {
42- writeFile ( outPath + ".map" , sourceMap ) ;
46+ files . push ( { name : outPath + ".map" , text : sourceMap } ) ;
4347 }
4448
4549 if ( declaration !== undefined ) {
46- writeFile ( trimExt ( outPath ) + ".d.ts" , declaration ) ;
50+ files . push ( { name : trimExt ( outPath ) + ".d.ts" , text : declaration } ) ;
4751 }
4852
4953 if ( declarationMap !== undefined ) {
50- writeFile ( trimExt ( outPath ) + ".d.ts.map" , declarationMap ) ;
54+ files . push ( { name : trimExt ( outPath ) + ".d.ts.map" , text : declarationMap } ) ;
5155 }
5256 }
5357
@@ -60,6 +64,8 @@ export function emitTranspiledFiles(
6064 }
6165
6266 const outPath = path . join ( outDir , "lualib_bundle.lua" ) ;
63- writeFile ( outPath , lualibContent ) ;
67+ files . push ( { name : outPath , text : lualibContent } ) ;
6468 }
69+
70+ return files ;
6571}
0 commit comments