@@ -6,26 +6,28 @@ import microbundle from '.';
66let { version } = require ( '../package' ) ;
77let prog = sade ( 'microbundle' ) ;
88
9+ let toArray = val => Array . isArray ( val ) ? val : val == null ? [ ] : [ val ] ;
10+
911prog
1012 . version ( version )
11- . option ( '--cwd' , 'Use an alternative working directory' , '.' )
1213 . option ( '--entry, -i' , 'Entry module(s)' )
1314 . option ( '--output, -o' , 'Directory to place build files into' )
1415 . option ( '--format, -f' , 'Only build specified formats' , 'es,cjs,umd' )
1516 . option ( '--external' , `Specify external dependencies, or 'all'` )
1617 . option ( '--compress' , 'Compress output using UglifyJS' , true )
1718 . option ( '--strict' , 'Enforce undefined global context and add "use strict"' )
18- . option ( '--name' , 'Specify name exposed in UMD builds' ) ;
19+ . option ( '--name' , 'Specify name exposed in UMD builds' )
20+ . option ( '--cwd' , 'Use an alternative working directory' , '.' ) ;
1921
2022prog
21- . command ( 'build [entries]' , '' , { default : true } )
23+ . command ( 'build [... entries]' , '' , { default :true } )
2224 . describe ( 'Build once and exit' )
2325 . action ( run ) ;
2426
2527prog
26- . command ( 'watch [entries]' )
28+ . command ( 'watch [... entries]' )
2729 . describe ( 'Rebuilds on any change' )
28- . action ( opts => run ( opts , true ) ) ;
30+ . action ( ( str , opts ) => run ( str , opts , true ) ) ;
2931
3032// Parse argv; add extra aliases
3133prog . parse ( process . argv , {
@@ -35,15 +37,13 @@ prog.parse(process.argv, {
3537 }
3638} ) ;
3739
38- function run ( options , watch ) {
39- options . entries = options . _ ;
40- options . watch = watch === true ;
41- microbundle ( options )
40+ function run ( str , opts , isWatch ) {
41+ opts . watch = ! ! isWatch ;
42+ opts . entries = toArray ( str || opts . entry ) . concat ( opts . _ ) ;
43+ microbundle ( opts )
4244 . then ( output => {
4345 if ( output != null ) process . stdout . write ( output + '\n' ) ;
44- if ( ! watch ) {
45- process . exit ( 0 ) ;
46- }
46+ if ( ! opts . watch ) process . exit ( 0 ) ;
4747 } )
4848 . catch ( err => {
4949 process . stderr . write ( String ( err ) + '\n' ) ;
0 commit comments