@@ -12,22 +12,27 @@ var pkg = JSON.parse(
12
12
) ;
13
13
var build = require ( "../lib/build" ) ;
14
14
var serve = require ( "../lib/serve" ) ;
15
+ var install = require ( "../lib/install" ) ;
15
16
16
17
program . version ( pkg . version ) ;
17
18
18
19
const stringBooleanToBoolean = val => {
19
- console . log ( { val} ) ;
20
- if ( typeof val !== ' string' && ( val !== ' true' || val !== ' false' ) ) {
20
+ console . log ( { val } ) ;
21
+ if ( typeof val !== " string" && ( val !== " true" || val !== " false" ) ) {
21
22
throw Error ( `Incorrect string value: ${ val } ` ) ;
22
23
}
23
24
24
- return val === ' true' ;
25
+ return val === " true" ;
25
26
} ;
26
27
27
28
program
28
29
. option ( "-c --config <webpack-config>" , "additional webpack configuration" )
29
30
. option ( "-p --port <port>" , "port to serve from (default: 9000)" )
30
- . option ( "-b --babelrc <babelrc>" , "use .babelrc in root (default: true)" , stringBooleanToBoolean )
31
+ . option (
32
+ "-b --babelrc <babelrc>" ,
33
+ "use .babelrc in root (default: true)" ,
34
+ stringBooleanToBoolean
35
+ )
31
36
. option (
32
37
"-t --timeout <timeout>" ,
33
38
"function invocation timeout in seconds (default: 10)"
@@ -47,13 +52,13 @@ program
47
52
static ,
48
53
Number ( program . timeout ) || 10
49
54
) ;
50
- }
55
+ } ;
51
56
if ( static ) {
52
57
startServer ( ) ;
53
58
return ; // early terminate, don't build
54
- } ;
55
- const { config : userWebpackConfig , babelrc : useBabelrc = true } = program ;
56
- build . watch ( cmd , { userWebpackConfig, useBabelrc} , function ( err , stats ) {
59
+ }
60
+ const { config : userWebpackConfig , babelrc : useBabelrc = true } = program ;
61
+ build . watch ( cmd , { userWebpackConfig, useBabelrc } , function ( err , stats ) {
57
62
if ( err ) {
58
63
console . error ( err ) ;
59
64
return ;
@@ -75,9 +80,9 @@ program
75
80
. action ( function ( cmd , options ) {
76
81
console . log ( "netlify-lambda: Building functions" ) ;
77
82
78
- const { config : userWebpackConfig , babelrc : useBabelrc = true } = program ;
83
+ const { config : userWebpackConfig , babelrc : useBabelrc = true } = program ;
79
84
build
80
- . run ( cmd , { userWebpackConfig, useBabelrc} )
85
+ . run ( cmd , { userWebpackConfig, useBabelrc } )
81
86
. then ( function ( stats ) {
82
87
console . log ( stats . toString ( { color : true } ) ) ;
83
88
} )
@@ -87,6 +92,17 @@ program
87
92
} ) ;
88
93
} ) ;
89
94
95
+ program
96
+ . command ( "install [dir]" )
97
+ . description ( "install functions" )
98
+ . action ( function ( cmd , options ) {
99
+ console . log ( "netlify-lambda: installing function dependencies" ) ;
100
+ install . run ( cmd ) . catch ( function ( err ) {
101
+ console . error ( err ) ;
102
+ process . exit ( 1 ) ;
103
+ } ) ;
104
+ } ) ;
105
+
90
106
// error on unknown commands
91
107
// ref: https://github.com/tj/commander.js#custom-event-listeners
92
108
program . on ( "command:*" , function ( ) {
0 commit comments