Last active
December 12, 2015 06:09
-
-
Save thanpolas/4727303 to your computer and use it in GitHub Desktop.
Grunt Task for node
This file contains 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
module.exports = function(grunt) { | |
grunt.loadNpmTasks('grunt-exec'); | |
grunt.loadNpmTasks('grunt-shell'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
// Project configuration. | |
grunt.initConfig({ | |
watch: { | |
node: { | |
files: ['lib/front/*.js'], | |
tasks: 'stopNode startNode' | |
} | |
} | |
}); | |
var nodeChild; | |
grunt.registerTask('startNode', function() { | |
var sp = require('child_process').spawn; | |
nodeChild = sp('node', ['dep']); | |
console.log('Started node on pid: ' + nodeChild.pid); | |
nodeChild.stdout.on('data', function (data) { | |
console.log('stdout: ' + data); | |
}); | |
nodeChild.stderr.on('data', function (data) { | |
console.log('stderr: ' + data); | |
}); | |
nodeChild.on('exit', function (code) { | |
console.log('child process exited with code ' + code); | |
}); | |
}); | |
grunt.registerTask('stopNode', function() { | |
nodeChild.kill(9); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment