Skip to content

Commit 937bdf9

Browse files
paulovitinflovilmart
authored andcommitted
Fix bugs in dev commands and organize the dev script (#5099)
1 parent 22fe390 commit 937bdf9

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

bin/dev

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
#!/usr/bin/env node
22

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');
89

910
// 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 => {
1316
console.log(sourceFile + " has changed");
1417
try {
15-
targetFile = path.relative(__dirname, sourceFile).replace(/\/src\//, '/lib/');
18+
let targetFile = path.relative(__dirname, sourceFile).replace(/\/src\//, '/lib/');
1619
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+
);
1827
} catch (e) {
1928
console.error(e.message, e.stack);
2029
}
2130
});
2231
});
2332

33+
// ignore command and file
34+
args.splice(0, 2);
35+
2436
try {
25-
// Run and watch dist
37+
// Run and watch dist
2638
nodemon({
2739
script: 'bin/parse-server',
40+
args: args,
2841
ext: 'js json',
2942
watch: 'lib'
3043
});
3144
} catch (e) {
3245
console.error(e.message, e.stack);
3346
}
3447

35-
process.once('SIGINT', function() {
36-
process.exit(0);
37-
});
48+
process.once('SIGINT', () => {
49+
process.exit(0);
50+
});

0 commit comments

Comments
 (0)