Fix bugs in dev commands and organize the dev script (#5099)

This commit is contained in:
Paulo Reis
2018-10-03 08:33:53 -03:00
committed by Florent Vilmart
parent 22fe390be6
commit 937bdf9058

35
bin/dev
View File

@@ -1,30 +1,43 @@
#!/usr/bin/env node #!/usr/bin/env node
var nodemon = require('nodemon'); const args = process.argv;
var babel = require("babel-core"); const babel = require("@babel/core");
var gaze = require('gaze'); const fs = require('fs');
var fs = require('fs'); const gaze = require('gaze');
var path = require('path'); const nodemon = require('nodemon');
const path = require('path');
// Watch the src and transpile when changed // Watch the src and transpile when changed
gaze('src/**/*', function(err, watcher) { gaze('src/**/*', (err, watcher) => {
if (err) throw err; if (err) {
watcher.on('changed', function(sourceFile) { throw err;
}
watcher.on('changed', sourceFile => {
console.log(sourceFile + " has changed"); console.log(sourceFile + " has changed");
try { try {
targetFile = path.relative(__dirname, sourceFile).replace(/\/src\//, '/lib/'); let targetFile = path.relative(__dirname, sourceFile).replace(/\/src\//, '/lib/');
targetFile = path.resolve(__dirname, targetFile); targetFile = path.resolve(__dirname, targetFile);
fs.writeFile(targetFile, babel.transformFileSync(sourceFile).code); fs.writeFile(
targetFile,
babel.transformFileSync(sourceFile).code,
() => {
console.log('Re-running the parse-server...')
},
);
} catch (e) { } catch (e) {
console.error(e.message, e.stack); console.error(e.message, e.stack);
} }
}); });
}); });
// ignore command and file
args.splice(0, 2);
try { try {
// Run and watch dist // Run and watch dist
nodemon({ nodemon({
script: 'bin/parse-server', script: 'bin/parse-server',
args: args,
ext: 'js json', ext: 'js json',
watch: 'lib' watch: 'lib'
}); });
@@ -32,6 +45,6 @@ try {
console.error(e.message, e.stack); console.error(e.message, e.stack);
} }
process.once('SIGINT', function() { process.once('SIGINT', () => {
process.exit(0); process.exit(0);
}); });