Skip to content

Instantly share code, notes, and snippets.

@nullstyle
Created October 28, 2014 19:57
Show Gist options
  • Save nullstyle/017f4f896d445d37bebd to your computer and use it in GitHub Desktop.
Save nullstyle/017f4f896d445d37bebd to your computer and use it in GitHub Desktop.
var gulp = require('gulp');
var spawn = require('child_process').spawn;
var _ = require("lodash");
gulp.task("test", ['db:ensure-created-test'], function() {
log("running tests here");
});
gulp.task("db:ensure-created", function() {
log("creating db");
});
gulp.task("db:ensure-created-test", function(done) {
if(process.env.NODE_ENV === 'test') {
gulp.start("db:ensure-created", done);
} else {
log("spawning child process to create db");
var options = {
stdio: 'inherit',
env: _.defaults({NODE_ENV: "test"}, process.env),
cwd: process.cwd
};
spawn("gulp", ["db:ensure-created-test"], options).once('close', done);
}
});
function log(message) {
var nodeEnv = process.env.NODE_ENV || "dev ";
console.log(nodeEnv + " PID:" + process.pid + " - " + message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment