Skip to content

Instantly share code, notes, and snippets.

@TylerK
Last active August 29, 2015 14:10
Show Gist options
  • Save TylerK/67c554cefe6148156567 to your computer and use it in GitHub Desktop.
Save TylerK/67c554cefe6148156567 to your computer and use it in GitHub Desktop.
Select a local sub project to run
//
// Deps
//---------------------------------------------------------
var
inquirer = require('inquirer'),
path = require('path'),
exec = require('child_process').exec,
spawn = require('child_process').spawn
;
//
// Select which project to spin up
//---------------------------------------------------------
// Get all the sub apps in /apps/
var projectsArr;
var projects = exec('ls apps', function(error, stdout, stderr) {
// Format the stdout return in to something usable.
projectsArr = stdout.split('\n')
projectsArr.pop();
// Since child_process exec is async, and Ivan is making me write
// this in raw Node, welcome to sweet, sweet call back land ;)
devProjectSelector();
});
function devProjectSelector() {
// Select which sub app to run
var projectSelect = [
{
type: 'list',
name: 'project',
message: 'Which project would you like to spin up?',
choices: projectsArr
}
];
// Spin up the dev environment for the selected project
inquirer.prompt(projectSelect, function (selected) {
var project = selected.project,
projectDir = path.join('apps', project);
// Spin up a new process and run the project's 'gulp dev' command
var devProject = spawn('gulp', ['dev'], { cwd: projectDir, stdio: 'inherit' });
// Kill child processes if the parent is killed
devProject.on('exit', function() {
console.log('Murdering Gulp');
exec('killall gulp');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment