Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
#!/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'
});
} catch (e) {
console.error(e.message, e.stack);
}

process.once('SIGINT', function() {
process.exit(0);
});
process.once('SIGINT', () => {
process.exit(0);
});