4
4
* Module dependencies.
5
5
*/
6
6
7
- var program = require ( " commander" ) ;
8
- var fs = require ( "fs" ) ;
9
- var path = require ( " path" ) ;
7
+ var program = require ( ' commander' ) ;
8
+ var fs = require ( 'fs' ) ;
9
+ var path = require ( ' path' ) ;
10
10
var pkg = JSON . parse (
11
- fs . readFileSync ( path . join ( __dirname , ".." , " package.json" ) )
11
+ fs . readFileSync ( path . join ( __dirname , '..' , ' package.json' ) ) ,
12
12
) ;
13
- var build = require ( " ../lib/build" ) ;
14
- var serve = require ( " ../lib/serve" ) ;
15
- var install = require ( " ../lib/install" ) ;
13
+ var build = require ( ' ../lib/build' ) ;
14
+ var serve = require ( ' ../lib/serve' ) ;
15
+ var install = require ( ' ../lib/install' ) ;
16
16
17
17
program . version ( pkg . version ) ;
18
18
19
- const stringBooleanToBoolean = val => {
19
+ const stringBooleanToBoolean = ( val ) => {
20
20
console . log ( { val } ) ;
21
- if ( typeof val !== " string" && ( val !== " true" || val !== " false" ) ) {
21
+ if ( typeof val !== ' string' && ( val !== ' true' || val !== ' false' ) ) {
22
22
throw Error ( `Incorrect string value: ${ val } ` ) ;
23
23
}
24
24
25
- return val === " true" ;
25
+ return val === ' true' ;
26
26
} ;
27
27
28
28
program
29
- . option ( " -c --config <webpack-config>" , " additional webpack configuration" )
30
- . option ( " -p --port <port>" , " port to serve from (default: 9000)" )
29
+ . option ( ' -c --config <webpack-config>' , ' additional webpack configuration' )
30
+ . option ( ' -p --port <port>' , ' port to serve from (default: 9000)' )
31
31
. option (
32
- " -b --babelrc <babelrc>" ,
33
- " use .babelrc in root (default: true)" ,
34
- stringBooleanToBoolean
32
+ ' -b --babelrc <babelrc>' ,
33
+ ' use .babelrc in root (default: true)' ,
34
+ stringBooleanToBoolean ,
35
35
)
36
36
. option (
37
- " -t --timeout <timeout>" ,
38
- " function invocation timeout in seconds (default: 10)"
37
+ ' -t --timeout <timeout>' ,
38
+ ' function invocation timeout in seconds (default: 10)' ,
39
39
)
40
- . option ( " -s --static" , " serve pre-built lambda files" ) ;
40
+ . option ( ' -s --static' , ' serve pre-built lambda files' ) ;
41
41
42
42
program
43
- . command ( " serve <dir>" )
44
- . description ( " serve and watch functions" )
45
- . action ( function ( cmd , options ) {
46
- console . log ( " netlify-lambda: Starting server" ) ;
43
+ . command ( ' serve <dir>' )
44
+ . description ( ' serve and watch functions' )
45
+ . action ( function ( cmd ) {
46
+ console . log ( ' netlify-lambda: Starting server' ) ;
47
47
var static = Boolean ( program . static ) ;
48
48
var server ;
49
- var startServer = function ( ) {
49
+ var startServer = function ( ) {
50
50
server = serve . listen (
51
51
program . port || 9000 ,
52
52
static ,
53
- Number ( program . timeout ) || 10
53
+ Number ( program . timeout ) || 10 ,
54
54
) ;
55
55
} ;
56
56
if ( static ) {
57
57
startServer ( ) ;
58
58
return ; // early terminate, don't build
59
59
}
60
60
const { config : userWebpackConfig , babelrc : useBabelrc = true } = program ;
61
- build . watch ( cmd , { userWebpackConfig, useBabelrc } , function ( err , stats ) {
61
+ build . watch ( cmd , { userWebpackConfig, useBabelrc } , function ( err , stats ) {
62
62
if ( err ) {
63
63
console . error ( err ) ;
64
64
return ;
@@ -67,47 +67,47 @@ program
67
67
if ( ! server ) {
68
68
startServer ( ) ;
69
69
}
70
- stats . compilation . chunks . forEach ( function ( chunk ) {
70
+ stats . compilation . chunks . forEach ( function ( chunk ) {
71
71
server . clearCache ( chunk . name || chunk . id . toString ( ) ) ;
72
72
} ) ;
73
73
} ) ;
74
74
} ) ;
75
75
76
76
program
77
- . command ( " build <dir>" )
78
- . description ( " build functions" )
79
- . action ( function ( cmd , options ) {
80
- console . log ( " netlify-lambda: Building functions" ) ;
77
+ . command ( ' build <dir>' )
78
+ . description ( ' build functions' )
79
+ . action ( function ( cmd ) {
80
+ console . log ( ' netlify-lambda: Building functions' ) ;
81
81
82
82
const { config : userWebpackConfig , babelrc : useBabelrc = true } = program ;
83
83
build
84
84
. run ( cmd , { userWebpackConfig, useBabelrc } )
85
- . then ( function ( stats ) {
85
+ . then ( function ( stats ) {
86
86
console . log ( stats . toString ( stats . compilation . options . stats ) ) ;
87
87
} )
88
- . catch ( function ( err ) {
88
+ . catch ( function ( err ) {
89
89
console . error ( err ) ;
90
90
process . exit ( 1 ) ;
91
91
} ) ;
92
92
} ) ;
93
93
94
94
program
95
- . command ( " install [dir]" )
96
- . description ( " install functions" )
97
- . action ( function ( cmd , options ) {
98
- console . log ( " netlify-lambda: installing function dependencies" ) ;
99
- install . run ( cmd ) . catch ( function ( err ) {
95
+ . command ( ' install [dir]' )
96
+ . description ( ' install functions' )
97
+ . action ( function ( cmd ) {
98
+ console . log ( ' netlify-lambda: installing function dependencies' ) ;
99
+ install . run ( cmd ) . catch ( function ( err ) {
100
100
console . error ( err ) ;
101
101
process . exit ( 1 ) ;
102
102
} ) ;
103
103
} ) ;
104
104
105
105
// error on unknown commands
106
106
// ref: https://github.com/tj/commander.js#custom-event-listeners
107
- program . on ( " command:*" , function ( ) {
107
+ program . on ( ' command:*' , function ( ) {
108
108
console . error (
109
- " Invalid command: %s\nSee --help for a list of available commands." ,
110
- program . args . join ( " " )
109
+ ' Invalid command: %s\nSee --help for a list of available commands.' ,
110
+ program . args . join ( ' ' ) ,
111
111
) ;
112
112
process . exit ( 1 ) ;
113
113
} ) ;
0 commit comments