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

41
bin/dev
View File

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