1
+ #!/usr/bin/env node
2
+
3
+ var pkg = require ( '../package' ) ;
4
+ var program = require ( 'commander' ) ;
5
+ var dts = require ( "./index" ) ;
6
+ var path = require ( 'path' ) ;
7
+ var os = require ( 'os' ) ;
8
+
9
+ function mapOptions ( argObj ) {
10
+ var result = argObj . configJson ? require ( path . resolve ( argObj . configJson ) ) : { } ;
11
+
12
+ var optList = [
13
+ "main" ,
14
+ "name" ,
15
+ "baseDir" ,
16
+ "out" ,
17
+ //"newline", // Manual
18
+ //"indent", // not implemented
19
+ "prefix" ,
20
+ "separator" ,
21
+ "externals" ,
22
+ //"exclude", // not implemented
23
+ "removeSource" ,
24
+ "verbose" ,
25
+ "referenceExternals" ,
26
+ "emitOnIncludedFileNotFound" ,
27
+ "emitOnNoIncludedFileNotFound"
28
+ ] ;
29
+
30
+ optList . forEach ( function ( optName ) {
31
+ if ( argObj . hasOwnProperty ( optName ) )
32
+ result [ optName ] = argObj [ optName ] ;
33
+ } , this ) ;
34
+
35
+ if ( argObj . hasOwnProperty ( "newline" ) ) {
36
+ switch ( argObj . newline ) {
37
+ case "unix" :
38
+ result . newline = "\n" ;
39
+ break ;
40
+ case "windows" :
41
+ result . newline = "\r\n" ;
42
+ break ;
43
+ case "currentOsDefault" :
44
+ result . newline = os . EOL ;
45
+ break ;
46
+ }
47
+ }
48
+ return result ;
49
+ }
50
+
51
+ function callBundle ( options ) {
52
+ if ( ! options . name || ! options . main ) {
53
+ console . log ( "'name' and 'main' parameters are required. --help for get option list." )
54
+ process . exit ( 1 ) ;
55
+ }
56
+ return dts . bundle ( options ) ;
57
+ }
58
+
59
+ program
60
+ . version ( pkg . version )
61
+ . option ( '--configJson <value>' , "path to json config file. Load it first and override options with additional parameters" )
62
+ . option ( '--name <value>' , 'name of module likein package.json *required' )
63
+ . option ( '--main <value>' , 'path to entry-point (see documentation) *required' )
64
+ . option ( '--baseDir [value]' , 'base directory to be used for discovering type declarations' )
65
+ . option ( '--out [value]' , 'path of output file. Is relative from baseDir but you can use absolute paths. ' )
66
+ . option ( '--externals' , 'include typings outside of the "baseDir" (i.e. like node.d.ts)' )
67
+ . option ( '--referenceExternals' , 'reference external modules as <reference path="..." /> tags *** Experimental, TEST NEEDED' )
68
+ //.option('--exclude ', 'filter to exclude typings, either a RegExp or a callback. match path relative to opts.baseDir')
69
+ . option ( '--removeSource' , 'delete all source typings (i.e. "<baseDir>/**/*.d.ts")' )
70
+ . option ( '--newline [style]' , 'newline style to use in output file => unix|windows|currentOsDefault' , / ^ ( u n i x | w i n d o w s | c u r r e n t O s D e f a u l t ) $ / i)
71
+ //.option('--indent', 'indentation to use in output file')
72
+ . option ( '--prefix [value]' , 'prefix for rewriting module names' )
73
+ . option ( '--separator [value]' , 'separator for rewriting module "path" names' )
74
+ . option ( '--verbose' , 'enable verbose mode, prints detailed info about all references and includes/excludes' )
75
+ . option ( '--emitOnIncludedFileNotFound' , 'emit although included files not found. See readme "Files not found" section. ' )
76
+ . option ( '--emitOnNoIncludedFileNotFound' , 'emit although no included files not found. See readme "Files not found" section. ' )
77
+ . parse ( process . argv ) ;
78
+
79
+ console . log ( "%s version %s\n%s\n" , pkg . name , pkg . version , pkg . description ) ;
80
+
81
+ var options = mapOptions ( program ) ;
82
+
83
+ var result = callBundle ( options ) ;
84
+
85
+ if ( ! result . emitted ) {
86
+ console . log ( "Result no emitted - use verbose to see details." ) ;
87
+ process . exit ( 1 ) ;
88
+ }
89
+
0 commit comments