1
1
#!/usr/bin/env node
2
2
3
- import * as closure from 'google-closure-compiler' ;
4
3
import * as fs from 'fs' ;
5
4
import * as minimist from 'minimist' ;
6
5
import * as path from 'path' ;
@@ -18,26 +17,18 @@ const internalExternsFileName = 'tsickle_externs.js';
18
17
19
18
/** Tsickle settings passed on the command line. */
20
19
interface Settings {
21
- /** If true, write temporary .js files to disk. Useful for debugging. */
22
- saveTemporaries ? : boolean ;
23
-
24
20
/** If provided, path to save externs to. */
25
21
externsPath ? : string ;
26
-
27
- /** Path to write the final JS bundle to. */
28
- outputPath: string ;
29
22
}
30
23
31
24
function usage ( ) {
32
- console . error ( `usage: tsickle [tsickle args ] -- [tsc args ]
25
+ console . error ( `usage: tsickle [tsickle options ] -- [tsc options ]
33
26
34
27
example:
35
- tsickle --output bundle .js -- -p src --noImplicitAny
28
+ tsickle --externs=foo/externs .js -- -p src --noImplicitAny
36
29
37
30
tsickle flags are:
38
- --saveTemporaries save intermediate .js files to disk
39
31
--externs=PATH save generated Closure externs.js to PATH
40
- --output=PATH write final Closure bundle to PATH
41
32
` ) ;
42
33
}
43
34
@@ -46,10 +37,7 @@ tsickle flags are:
46
37
* the arguments to pass on to tsc.
47
38
*/
48
39
function loadSettingsFromArgs ( args : string [ ] ) : { settings: Settings , tscArgs : string [ ] } {
49
- let settings : Settings = {
50
- saveTemporaries : null ,
51
- outputPath : null ,
52
- } ;
40
+ let settings : Settings = { } ;
53
41
let parsedArgs = minimist ( args ) ;
54
42
for ( let flag of Object . keys ( parsedArgs ) ) {
55
43
switch ( flag ) {
@@ -58,15 +46,9 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
58
46
usage ( ) ;
59
47
process . exit ( 0 ) ;
60
48
break ;
61
- case 'saveTemporaries' :
62
- settings . saveTemporaries = true ;
63
- break ;
64
49
case 'externs' :
65
50
settings . externsPath = parsedArgs [ flag ] ;
66
51
break ;
67
- case 'output' :
68
- settings . outputPath = parsedArgs [ flag ] ;
69
- break ;
70
52
case '_' :
71
53
// This is part of the minimist API, and holds args after the '--'.
72
54
break ;
@@ -76,11 +58,6 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
76
58
process . exit ( 1 ) ;
77
59
}
78
60
}
79
- if ( ! settings . outputPath && ! settings . externsPath ) {
80
- console . error ( 'must specify --output or --externs path' ) ;
81
- usage ( ) ;
82
- process . exit ( 1 ) ;
83
- }
84
61
// Arguments after the '--' arg are arguments to tsc.
85
62
let tscArgs = parsedArgs [ '_' ] ;
86
63
return { settings, tscArgs} ;
@@ -220,32 +197,6 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
220
197
return { jsFiles} ;
221
198
}
222
199
223
- function closureCompile (
224
- jsFiles : { [ fileName : string ] : string } , outFile : string ,
225
- callback : ( exitCode : number , output : string ) => void ) : void {
226
- const closureOptions : closure . CompileOptions = {
227
- // Read input files from stdin as JSON.
228
- 'json_streams' : 'IN' ,
229
- // Write output file to disk.
230
- 'js_output_file' : outFile ,
231
- 'warning_level' : 'VERBOSE' ,
232
- 'language_in' : 'ECMASCRIPT6_STRICT' ,
233
- 'compilation_level' : 'ADVANCED_OPTIMIZATIONS' ,
234
- } ;
235
-
236
- let compiler = new closure . compiler ( closureOptions ) ;
237
- let process = compiler . run ( ( exitCode , stdout , stderr ) => { callback ( exitCode , stderr ) ; } ) ;
238
-
239
- let jsonInput : closure . JSONStreamFile [ ] = [ ] ;
240
- for ( let fileName of Object . keys ( jsFiles ) ) {
241
- jsonInput . push ( {
242
- path : fileName ,
243
- src : jsFiles [ fileName ] ,
244
- } ) ;
245
- }
246
- process . stdin . end ( JSON . stringify ( jsonInput ) ) ;
247
- }
248
-
249
200
function main ( args : string [ ] ) {
250
201
let { settings , tscArgs } = loadSettingsFromArgs ( args ) ;
251
202
let { options , fileNames , errors } = loadTscConfig ( tscArgs ) ;
@@ -266,23 +217,13 @@ function main(args: string[]) {
266
217
process . exit ( 1 ) ;
267
218
}
268
219
269
- if ( settings . saveTemporaries ) {
270
- for ( let fileName of Object . keys ( jsFiles ) ) {
271
- fs . writeFileSync ( fileName , jsFiles [ fileName ] ) ;
272
- }
220
+ for ( let fileName of Object . keys ( jsFiles ) ) {
221
+ fs . writeFileSync ( fileName , jsFiles [ fileName ] ) ;
273
222
}
274
223
275
224
if ( settings . externsPath ) {
276
225
fs . writeFileSync ( settings . externsPath , jsFiles [ internalExternsFileName ] ) ;
277
226
}
278
-
279
- if ( settings . outputPath ) {
280
- // Run Closure compiiler to convert JS files to output bundle.
281
- closureCompile ( jsFiles , settings . outputPath , ( exitCode , output ) => {
282
- if ( output ) console . error ( output ) ;
283
- process . exit ( exitCode ) ;
284
- } ) ;
285
- }
286
227
}
287
228
288
229
// CLI entry point
0 commit comments