1
1
#!/usr/bin/env node
2
2
3
- var nodemon = require ( 'nodemon' ) ;
4
- var babel = require ( "babel-core" ) ;
5
- var gaze = require ( 'gaze' ) ;
6
- var fs = require ( 'fs' ) ;
7
- var path = require ( 'path' ) ;
3
+ const args = process . argv ;
4
+ const babel = require ( "@babel/core" ) ;
5
+ const fs = require ( 'fs' ) ;
6
+ const gaze = require ( 'gaze' ) ;
7
+ const nodemon = require ( 'nodemon' ) ;
8
+ const path = require ( 'path' ) ;
8
9
9
10
// Watch the src and transpile when changed
10
- gaze ( 'src/**/*' , function ( err , watcher ) {
11
- if ( err ) throw err ;
12
- watcher . on ( 'changed' , function ( sourceFile ) {
11
+ gaze ( 'src/**/*' , ( err , watcher ) => {
12
+ if ( err ) {
13
+ throw err ;
14
+ }
15
+ watcher . on ( 'changed' , sourceFile => {
13
16
console . log ( sourceFile + " has changed" ) ;
14
17
try {
15
- targetFile = path . relative ( __dirname , sourceFile ) . replace ( / \/ s r c \/ / , '/lib/' ) ;
18
+ let targetFile = path . relative ( __dirname , sourceFile ) . replace ( / \/ s r c \/ / , '/lib/' ) ;
16
19
targetFile = path . resolve ( __dirname , targetFile ) ;
17
- fs . writeFile ( targetFile , babel . transformFileSync ( sourceFile ) . code ) ;
20
+ fs . writeFile (
21
+ targetFile ,
22
+ babel . transformFileSync ( sourceFile ) . code ,
23
+ ( ) => {
24
+ console . log ( 'Re-running the parse-server...' )
25
+ } ,
26
+ ) ;
18
27
} catch ( e ) {
19
28
console . error ( e . message , e . stack ) ;
20
29
}
21
30
} ) ;
22
31
} ) ;
23
32
33
+ // ignore command and file
34
+ args . splice ( 0 , 2 ) ;
35
+
24
36
try {
25
- // Run and watch dist
37
+ // Run and watch dist
26
38
nodemon ( {
27
39
script : 'bin/parse-server' ,
40
+ args : args ,
28
41
ext : 'js json' ,
29
42
watch : 'lib'
30
43
} ) ;
31
44
} catch ( e ) {
32
45
console . error ( e . message , e . stack ) ;
33
46
}
34
47
35
- process . once ( 'SIGINT' , function ( ) {
36
- process . exit ( 0 ) ;
37
- } ) ;
48
+ process . once ( 'SIGINT' , ( ) => {
49
+ process . exit ( 0 ) ;
50
+ } ) ;
0 commit comments