@@ -4,7 +4,7 @@ import {readFileSync,writeFileSync} from "fs";
44import { LuaTranspiler , TranspileError } from "./Transpiler" ;
55import { TSHelper as tsEx } from "./TSHelper" ;
66
7- function compile ( fileNames : string [ ] , options : ts . CompilerOptions ) : void {
7+ function compile ( fileNames : string [ ] , options : ts . CompilerOptions , projectRoot : string ) : void {
88 // Verify target
99 if ( ( < string > < any > options . target ) != "lua" ) {
1010 console . error ( "Wrong compilation target! Add \"target\": \"lua\" to your tsconfig.json!" ) ;
@@ -41,8 +41,15 @@ function compile(fileNames: string[], options: ts.CompilerOptions): void {
4141 try {
4242 // Transpile AST
4343 let lua = LuaTranspiler . transpileSourceFile ( sourceFile , checker ) ;
44- const outPath = sourceFile . fileName . substring ( 0 , sourceFile . fileName . lastIndexOf ( "." ) ) + ".lua" ;
45- //console.log(outPath);
44+ let outPath = sourceFile . fileName . substring ( 0 , sourceFile . fileName . lastIndexOf ( "." ) ) + ".lua" ;
45+
46+ if ( options . outDir ) {
47+ var extension = options . outDir ;
48+ if ( extension [ extension . length - 1 ] != "/" ) extension = extension + "/" ;
49+ outPath = outPath . replace ( projectRoot + "/" , projectRoot + "/" + extension ) ;
50+ console . log ( outPath ) ;
51+ }
52+
4653 // Write output
4754 ts . sys . writeFile ( outPath , lua ) ;
4855 } catch ( exception ) {
@@ -88,7 +95,7 @@ if (configPath) {
8895 console . error ( "Error occured:" ) ;
8996 console . error ( configFile . error ) ;
9097 } else {
91- compile ( files , configFile . config . compilerOptions ) ;
98+ compile ( files , configFile . config . compilerOptions , projectRoot ) ;
9299 }
93100} else {
94101 console . error ( "Could not find tsconfig.json, place one in your project root!" ) ;
0 commit comments