Defining and running Gulp tasks for each environment on the fly
On a recent project we were deploying to parse.com using Gulp and I found this idea to be very useful:
var gulp = require('gulp');
var path = require('path');
var sequence = require('run-sequence');
var environments = ['mine', 'beta', 'prod', 'test'];
var deploy = function (environment, done) {
var dir = path.join(__dirname, '..', 'environments', environment);
gulp.task('config', function () {
// The config stuff
});
gulp.task('minify', function () {
// The minify stuff
});
sequence('clean', 'config', 'minify', 'deploy', done);
};
environments.forEach(function (environment) {
gulp.task('deploy:' + environment, function (done) {
deploy(environment, done);
});
});
So basically the tasks are not there till you run one "main" task like deploy:beta
.
What do you think?
Written by Eduardo García Sanz
Related protips
5 Responses
@riyadhalnur, thank you for the feedback!
over 1 year ago
·
Excellent idea! This works great.
over 1 year ago
·
@azanebrain, thank you!
over 1 year ago
·
How do you single out a task if you were to run in alone for a specific env?
over 1 year ago
·
hello @afhammad!,
The scoped tasks are isolated and can't be reached without running their parent task, check this https://gist.github.com/coma/55692304b951945c4c49
as you can see there, common tasks like clean and index are not wrapped as others like deploy > script
cheers
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Workflow
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#