You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.5 KiB
JavaScript
74 lines
1.5 KiB
JavaScript
9 years ago
|
var gulp = require("gulp");
|
||
|
var psTree = require("ps-tree");
|
||
|
var nodemon = require("gulp-nodemon");
|
||
|
var presetES2015 = require("@joepie91/gulp-preset-es2015");
|
||
|
|
||
|
var source = ["src/**/*.js"];
|
||
|
|
||
|
/* The following resolves JacksonGariety/gulp-nodemon#33 */
|
||
|
process.once("SIGINT", function() {
|
||
|
process.exit(0);
|
||
|
});
|
||
|
|
||
|
/* The following resolves remy/nodemon#34 */
|
||
|
function cleanupChildren(cb) {
|
||
|
psTree(process.pid, function(err, children) {
|
||
|
children.filter(function(child) {
|
||
|
return (child.PPID === process.pid.toString() && child.COMMAND === "node");
|
||
|
}).forEach(function(child) {
|
||
|
killChildren(children, child.PID);
|
||
|
});
|
||
|
|
||
|
cb();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function killChildren(children, pid) {
|
||
|
children.forEach(function(child) {
|
||
|
if (child.PPID === pid) {
|
||
|
killChildren(children, child.PID);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
console.error("Killing child Node.js process:", pid);
|
||
|
process.kill(parseInt(pid));
|
||
|
}
|
||
|
|
||
|
process.once("uncaughtException", function(err) {
|
||
|
console.log(err.stack || err);
|
||
|
|
||
|
cleanupChildren(function() {
|
||
|
process.exit(1);
|
||
|
});
|
||
|
})
|
||
|
|
||
|
|
||
|
gulp.task('babel', function() {
|
||
|
return gulp.src(source)
|
||
|
.pipe(presetES2015({
|
||
|
basePath: __dirname
|
||
|
}))
|
||
|
.pipe(gulp.dest("lib/"));
|
||
|
});
|
||
|
|
||
|
gulp.task("watch", function () {
|
||
|
gulp.watch(source, ["babel"]);
|
||
|
});
|
||
|
|
||
|
|
||
|
gulp.task("nodemon", ["babel"], function() {
|
||
|
return nodemon({
|
||
|
script: "lib/index.js",
|
||
|
ignore: [
|
||
|
"gulpfile.js",
|
||
|
"node_modules"
|
||
|
]
|
||
|
});
|
||
|
});
|
||
|
|
||
|
gulp.task("watch", ["nodemon"], function() {
|
||
|
gulp.watch(source, ["babel"])
|
||
|
});
|
||
|
|
||
|
gulp.task('default', ["watch"]);
|