@@ -11,7 +11,12 @@ import dedent = require("dedent")
1111import { LuaTranspiler , TranspileError } from "./Transpiler" ;
1212import { TSHelper as tsEx } from "./TSHelper" ;
1313
14- function compile ( fileNames : string [ ] , options : ts . CompilerOptions ) : void {
14+ interface CompilerOptions extends ts . CompilerOptions {
15+ addHeader ? : boolean ;
16+ luaLibDir ? : string ;
17+ }
18+
19+ function compile ( fileNames : string [ ] , options : CompilerOptions ) : void {
1520 let program = ts . createProgram ( fileNames , options ) ;
1621 let checker = program . getTypeChecker ( ) ;
1722
@@ -42,9 +47,20 @@ function compile(fileNames: string[], options: ts.CompilerOptions): void {
4247 options . outDir = options . rootDir ;
4348 }
4449
50+ if ( ! ( 'addHeader' in options ) ) {
51+ options . addHeader = true ;
52+ }
53+
54+ if ( ! options . luaLibDir ) {
55+ options . luaLibDir = options . outDir ;
56+ }
57+ else {
58+ options . luaLibDir = path . join ( options . outDir , options . luaLibDir ) ;
59+ }
60+
4561 // Copy lualib to target dir
4662 // This isnt run in sync because copyFileSync wont report errors.
47- fs . copyFile ( path . resolve ( __dirname , "../dist/lualib/typescript.lua" ) , path . join ( options . outDir , "typescript_lualib.lua" ) , ( err : NodeJS . ErrnoException ) => {
63+ fs . copyFile ( path . resolve ( __dirname , "../dist/lualib/typescript.lua" ) , path . join ( options . luaLibDir , "typescript_lualib.lua" ) , ( err : NodeJS . ErrnoException ) => {
4864 if ( err ) {
4965 console . log ( "ERROR: copying lualib to output." ) ;
5066 }
@@ -64,7 +80,7 @@ function compile(fileNames: string[], options: ts.CompilerOptions): void {
6480 }
6581
6682 // change extension
67- var fileNameLua = path . basename ( outPath , path . extname ( outPath ) ) + '.lua' ;
83+ const fileNameLua = path . basename ( outPath , path . extname ( outPath ) ) + '.lua' ;
6884 outPath = path . join ( path . dirname ( outPath ) , fileNameLua ) ;
6985
7086 // Write output
@@ -97,7 +113,7 @@ function printAST(node: ts.Node, indent: number) {
97113
98114// Removes the option and value form argv
99115function removeInvalidOptionsFromArgv ( commandLine : ReadonlyArray < string > , invalidOptions : ReadonlyArray < string > ) : ReadonlyArray < string > {
100- let result = commandLine . slice ( )
116+ let result = commandLine . slice ( ) ;
101117 for ( let opt of invalidOptions ) {
102118 let index = result . indexOf ( '--' + opt ) ;
103119 if ( index === - 1 ) {
@@ -113,32 +129,41 @@ function removeInvalidOptionsFromArgv(commandLine: ReadonlyArray<string>, invali
113129// Polyfill for report diagnostics
114130function logError ( commandLine : ts . ParsedCommandLine ) {
115131 if ( commandLine . errors . length !== 0 ) {
132+ let invalidErrorCount = 0 ;
116133 commandLine . errors . forEach ( ( err ) => {
117- console . log ( err . messageText ) ;
134+ // Allow all compiler options
135+ if ( err . code == 5023 ) {
136+ invalidErrorCount += 1 ;
137+ }
138+ else {
139+ console . log ( err . messageText ) ;
140+ }
118141 } ) ;
119- process . exit ( 1 ) ;
142+ if ( invalidErrorCount != commandLine . errors . length ) {
143+ process . exit ( 1 ) ;
144+ }
120145 }
121146}
122147
123148function executeCommandLine ( args : ReadonlyArray < string > ) {
124149 // Right now luaTarget, version and help are the only cli options, if more are added we should
125150 // add a more advanced custom parser
126- var argv = minimist ( args , {
151+ const argv = minimist ( args , {
127152 string : [ 'l' ] ,
128153 alias : { h : 'help' , v : 'version' , l : 'luaTarget' } ,
129154 default : { luaTarget : 'JIT' } ,
130155 '--' : true ,
131156 stopEarly : true ,
132157 } ) ;
133158
134- let tstlVersion
159+ let tstlVersion ;
135160 try {
136161 tstlVersion = require ( '../package' ) . version ;
137162 } catch ( e ) {
138163 tstlVersion = "0.0.0" ;
139164 }
140165
141- var helpString = dedent ( `Version: ${ tstlVersion }
166+ const helpString = dedent ( `Version: ${ tstlVersion }
142167 Syntax: tstl [options] [files...]
143168
144169 In addtion to the options listed below you can also pass options for the
@@ -165,7 +190,7 @@ function executeCommandLine(args: ReadonlyArray<string>) {
165190 }
166191
167192 // Remove tstl options otherwise ts will emit an error
168- let sanitizedArgs = removeInvalidOptionsFromArgv ( args , [ 'l' , 'luaTarget' ] )
193+ let sanitizedArgs = removeInvalidOptionsFromArgv ( args , [ 'l' , 'luaTarget' ] ) ;
169194
170195 let commandLine = ts . parseCommandLine ( sanitizedArgs ) ;
171196
@@ -207,6 +232,13 @@ function executeCommandLine(args: ReadonlyArray<string>) {
207232 if ( argv . luaTarget === "JIT" && commandLine . raw . luaTarget !== argv . luaTarget ) {
208233 commandLine . options . luaTarget = commandLine . raw . luaTarget ;
209234 }
235+
236+ // Add ignored compiler options
237+ for ( const compilerOption in commandLine . raw . compilerOptions ) {
238+ if ( ! ( compilerOption in commandLine . options ) ) {
239+ commandLine . options [ compilerOption ] = commandLine . raw . compilerOptions [ compilerOption ] ;
240+ }
241+ }
210242 }
211243
212244 if ( configPath && ! commandLine . options . rootDir ) {
0 commit comments