Skip to content

Instantly share code, notes, and snippets.

@JMBattista
Created May 1, 2015 17:49
Show Gist options
  • Save JMBattista/4860c46e84a3e8ced846 to your computer and use it in GitHub Desktop.
Save JMBattista/4860c46e84a3e8ced846 to your computer and use it in GitHub Desktop.
Use forever to run a grunt command
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
scripts: {
files: ['<The file(s) to watch'],
tasks: ['<The task to run>'],
options: {
spawn: false
}
}
},
forever: {
watch: {
options: {
index: 'gruntstart.js',
logFile: 'watch.logs',
outFile: 'watch.logs',
errFile: 'watch.logs'
}
}
}
});
// Load modules
grunt.loadNpmTasks('grunt-forever');
grunt.loadNpmTasks('grunt-contrib-watch');
// Register tasks
grunt.registerTask('default', ['forever:watch:restart']);
};
/**
* Credit to Антон Брагин
* from http://stackoverflow.com/questions/15622116/grunt-js-watch-forever
* For providing this piece of code
*/
var exec = require('child_process').exec;
exec('grunt watch > log/grunt.log',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment