Created
September 24, 2014 05:26
-
-
Save thesabbir/d59eedc44eeae1ecfdd5 to your computer and use it in GitHub Desktop.
Run Gulp With Sails lift
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
/** | |
* Bootstrap | |
* (sails.config.bootstrap) | |
* | |
* An asynchronous bootstrap function that runs before your Sails app gets lifted. | |
* This gives you an opportunity to set up your data model, run jobs, or perform some special chalkic. | |
* | |
* For more information on bootstrapping your app, check out: | |
* http://sailsjs.org/#/documentation/reference/sails.config/sails.config.bootstrap.html | |
*/ | |
/* | |
Requires Spwan and Chalk | |
*/ | |
var sp = require('child_process').spawn; | |
var chalk = require('chalk'); | |
/* | |
Print function for pretty logging (Requires 'chalk' module) | |
*/ | |
var print = function (data) { | |
console.log(chalk.cyan('Gulp :: '), chalk.magenta(data)); | |
}; | |
/* | |
Logs gulp process outputs | |
*/ | |
var log = function (gulp) { | |
gulp.stdout.on('data', function (data) { | |
print(data); | |
}); | |
gulp.stderr.on('data', function (data) { | |
print(data); | |
}); | |
gulp.on('close', function (data) { | |
print(data); | |
}); | |
}; | |
module.exports.bootstrap = function (cb) { | |
(function () { | |
var gulp = ''; | |
if (sails.config.environment != "development") { | |
/* | |
Runs in production replace 'dist-inject with our production gulp task | |
*/ | |
gulp = sp('gulp', ['dist-inject']); | |
} else { | |
/* | |
Runs Default task in development environment with loging enabled | |
*/ | |
gulp = sp('gulp'); | |
log(gulp); | |
} | |
})(); | |
// It's very important to trigger this callback method when you are finished | |
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) | |
cb(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment