@@ -18,7 +18,7 @@ interface CommandLineOptionOfEnum extends CommandLineOptionBase {
1818}
1919
2020interface CommandLineOptionOfPrimitive extends CommandLineOptionBase {
21- type : "boolean" | "string" | "object " | "array" ;
21+ type : "boolean" | "string" | "json-array-of-objects " | "array" ;
2222}
2323
2424type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfPrimitive ;
@@ -82,7 +82,7 @@ export const optionDeclarations: CommandLineOption[] = [
8282 {
8383 name : "luaPlugins" ,
8484 description : "List of TypeScriptToLua plugins." ,
85- type : "object " ,
85+ type : "json-array-of-objects " ,
8686 } ,
8787 {
8888 name : "tstlVerbose" ,
@@ -124,7 +124,7 @@ export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine):
124124 continue ;
125125 }
126126
127- const { error, value } = readValue ( option , rawValue ) ;
127+ const { error, value } = readValue ( option , rawValue , OptionSource . TsConfig ) ;
128128 if ( error ) parsedConfigFile . errors . push ( error ) ;
129129 if ( parsedConfigFile . options [ name ] === undefined ) parsedConfigFile . options [ name ] = value ;
130130 }
@@ -164,9 +164,9 @@ function updateParsedCommandLine(parsedCommandLine: ts.ParsedCommandLine, args:
164164 if ( error ) parsedCommandLine . errors . push ( error ) ;
165165 parsedCommandLine . options [ option . name ] = value ;
166166 if ( consumed ) {
167- i += 1 ;
168167 // Values of custom options are parsed as a file name, exclude them
169- parsedCommandLine . fileNames = parsedCommandLine . fileNames . filter ( f => f !== value ) ;
168+ parsedCommandLine . fileNames = parsedCommandLine . fileNames . filter ( f => f !== args [ i + 1 ] ) ;
169+ i += 1 ;
170170 }
171171 }
172172 }
@@ -196,21 +196,25 @@ function readCommandLineArgument(option: CommandLineOption, value: any): Command
196196 } ;
197197 }
198198
199- return { ...readValue ( option , value ) , consumed : true } ;
199+ return { ...readValue ( option , value , OptionSource . CommandLine ) , consumed : true } ;
200+ }
201+
202+ enum OptionSource {
203+ CommandLine ,
204+ TsConfig ,
200205}
201206
202207interface ReadValueResult {
203208 error ?: ts . Diagnostic ;
204209 value : any ;
205210}
206211
207- function readValue ( option : CommandLineOption , value : unknown ) : ReadValueResult {
212+ function readValue ( option : CommandLineOption , value : unknown , source : OptionSource ) : ReadValueResult {
208213 if ( value === null ) return { value } ;
209214
210215 switch ( option . type ) {
211216 case "boolean" :
212- case "string" :
213- case "object" : {
217+ case "string" : {
214218 if ( typeof value !== option . type ) {
215219 return {
216220 value : undefined ,
@@ -220,15 +224,44 @@ function readValue(option: CommandLineOption, value: unknown): ReadValueResult {
220224
221225 return { value } ;
222226 }
223- case "array" : {
224- if ( ! Array . isArray ( value ) ) {
227+ case "array" :
228+ case "json-array-of-objects" : {
229+ const isInvalidNonCliValue = source === OptionSource . TsConfig && ! Array . isArray ( value ) ;
230+ const isInvalidCliValue = source === OptionSource . CommandLine && typeof value !== "string" ;
231+
232+ if ( isInvalidNonCliValue || isInvalidCliValue ) {
225233 return {
226234 value : undefined ,
227235 error : cliDiagnostics . compilerOptionRequiresAValueOfType ( option . name , option . type ) ,
228236 } ;
229237 }
230238
231- return { value } ;
239+ const shouldParseValue = source === OptionSource . CommandLine && typeof value === "string" ;
240+ if ( ! shouldParseValue ) return { value } ;
241+
242+ if ( option . type === "array" ) {
243+ const array = value . split ( "," ) ;
244+ return { value : array } ;
245+ }
246+
247+ try {
248+ const objects = JSON . parse ( value ) ;
249+ if ( ! Array . isArray ( objects ) ) {
250+ return {
251+ value : undefined ,
252+ error : cliDiagnostics . compilerOptionRequiresAValueOfType ( option . name , option . type ) ,
253+ } ;
254+ }
255+
256+ return { value : objects } ;
257+ } catch ( e ) {
258+ if ( ! ( e instanceof SyntaxError ) ) throw e ;
259+
260+ return {
261+ value : undefined ,
262+ error : cliDiagnostics . compilerOptionCouldNotParseJson ( option . name , e . message ) ,
263+ } ;
264+ }
232265 }
233266 case "enum" : {
234267 if ( typeof value !== "string" ) {
0 commit comments