-
-
Save designfrontier/57771991e6928d9347de to your computer and use it in GitHub Desktop.
node restarter in gulp specifically for monument based web apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: I previously suggested doing this through Grunt, but had plenty of problems with | |
// my set up. Grunt did some weird things with scope, and I ended up using nodemon. This | |
// setup is now using Gulp. It works exactly how I expect it to and is WAY more concise. | |
var gulp = require('gulp'), | |
spawn = require('child_process').spawn, | |
node; | |
/** | |
* $ gulp server | |
* description: launch the server. If there's a server already running, kill it. | |
*/ | |
gulp.task('server', function() { | |
if (node) { | |
node.kill(); | |
} | |
node = spawn('node', ['app.js'], {stdio: 'inherit'}) | |
node.on('close', function (code) { | |
if (code === 8) { | |
gulp.log('Error detected, waiting for changes...'); | |
} | |
}); | |
}); | |
/** | |
* $ gulp | |
* description: start the development environment | |
*/ | |
gulp.task('dev', ['server'], function(){ | |
'use strict'; | |
gulp.watch([ | |
'**/*.js' | |
, 'templates/**/*.jst' | |
, '!node_modules/**/*' | |
, '!templates/**/*.js' | |
], ['server']); | |
}); | |
// clean up if an error goes unhandled. | |
process.on('exit', function() { | |
if (node) { | |
node.kill(); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment