Advertisement
oclement

oGulpSample

Aug 4th, 2014
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     'use strict';
  2.     var gulp = require('gulp'),
  3.     g = require('gulp-load-plugins')({lazy:true}), // Very useful gulp plugin that "aggregate all your installed gulp-plugins without you needing to require them individually
  4.     args = require('yargs').argv, // Allow you to evaluate the command and params used to run this script
  5.     run = require('run-sequence'); // This is a bit of a hackish workaround made by IverZealous
  6.  
  7.  
  8.     var isWatching = !!args.watch; // If you want to use it like so: gulp --watch (this would run the default task, and set isWatching to true);
  9.  
  10.     // If you define a watch task like so, you don't need the args.isWatching above
  11.     gulp.task('watch', ['build'], function() {
  12.         isWatching = true;
  13.         gulp.watch('**/*.coffee', ['coffee']);
  14.     });
  15.  
  16.     // default task; will execute 'build' if you just run 'gulp', then be done
  17.     gulp.task('default', ['build']);
  18.  
  19.     // Assuming you need some compilation step or something. But before doing so, run the 'git' task
  20.     gulp.task('coffee', ['git'], function() {
  21.         // according to the doc, you MUST return the stream to notify gulp when this task finishes
  22.         // personally, I add mixed results with this, and had more success by calling the callback instead (see example below)
  23.         return gulp.src('./app/**/*.coffee')
  24.             .pipe(g.coffee())
  25.             .pipe(gulp.dest('./build/);
  26.    });
  27.  
  28.    // if I understand correctly, this is where you want your condition in your case
  29.    gulp.task('git', function(done) {
  30.        if(isWatching) {
  31.            // Do you git stuff
  32.        }
  33.        
  34.        // you need to notify gulp when it's done by executing the callback.
  35.         // Alternatively, you can return a promise
  36.         done();
  37.     });
  38.  
  39.     // You can define a task that runs 'everything'
  40.     gulp.task('build', ['git', 'coffee'], function() {
  41.         // whatever else you need. This block will execute after 'git' and 'coffee' are done, in that order (because 'coffee' also depends on 'git')
  42.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement