3

I'm trying to gather 3 tasks needed to debug in a 1. Of course, since nature of gulp is asynchronous, I have problems with that. So I searched and find a soulution to use run-sequence module for solving that issue. I tried the following code, but it doesn't seem to be working as intended. It's not getting synchronous. Here's what I tried. Any thoughts guys? I don't want to run all this three commands to complete all the tasks. How can I do that?

var gulp = require('gulp'),
    useref = require('gulp-useref'),
    gulpif = require('gulp-if'),
    debug = require('gulp-debug'),
    rename = require("gulp-rename"),    
    replace = require('gulp-replace'),
    runSequence = require('run-sequence'),
    path = '../dotNet/VolleyManagement.UI';  

gulp.task('debug', function () {
    gulp.src('client/*.html')
        .pipe(debug())
        .pipe(gulp.dest(path + '/Areas/WebAPI/Views/Shared'));
});

gulp.task('rename', function () {    
    gulp.src(path + '/Areas/WebAPI/Views/Shared/index.html')
        .pipe(rename('/Areas/WebAPI/Views/Shared/_Layout.cshtml'))
        .pipe(gulp.dest(path));        

    gulp.src(path + '/Areas/WebAPI/Views/Shared/index.html', {read: false})
        .pipe(clean({force: true})); 
});

gulp.task('final', function(){
    gulp.src([path + '/Areas/WebAPI/Views/Shared/_Layout.cshtml'])
        .pipe(replace('href="', 'href="~/Content'))
        .pipe(replace('src="', 'src="~/Scripts'))
        .pipe(gulp.dest(path + '/Areas/WebAPI/Views/Shared/'));
}); 

gulp.task('debugAll', runSequence('debug', 'rename', 'final'));
Ivan
  • 157
  • 11

2 Answers2

3

 In gulp you can actually set dependant task. Try this:

gulp.task('debug', function () {
    //run debug task
});

gulp.task('rename',['debug'], function () {    
    //run rename once debug is done
});
ramesh
  • 2,296
  • 4
  • 19
  • 29
  • 1
    I tried, but the thing is that it runs asynchronously too... 'debug' task is finished after 'rename' – Ivan Jul 19 '15 at 12:31
1

I think you are not defining the 'debugAll' task right. Try like this:

gulp.task('debugAll', function () { 
    runSequence('debug', 'rename', 'final');
});

And also you need to return the stream for those tasks, just add 'return' in front of gulp.src for each of them: debug, rename, final. Here is the example for 'debug' task:

gulp.task('debug', function () {
    return gulp.src('client/*.html')
        .pipe(debug())
        .pipe(gulp.dest(path + '/Areas/WebAPI/Views/Shared'));
});

Both items are mentioned in the docs: https://www.npmjs.com/package/run-sequence

Liviu Costea
  • 3,624
  • 14
  • 17
  • Yeah, my bad. But I tried now with correct syntax and it doesn't work one after another anyway... – Ivan Jul 19 '15 at 12:33
  • 1
    Didn't see it at begining, but you actually need to return the stream of those tasks. Just add 'return' in front of gulp.src for each of your tasks - debug, rename, final. The same problem is for @ramesh answer above - you don't return the stream. This is also mentioned in the docs: https://www.npmjs.com/package/run-sequence – Liviu Costea Jul 19 '15 at 14:33
  • That's exactly what I missed! Thank you for pointing that out, now all is working just fine :) P.S. can you edit please your answer with information above so I can mark your answer as accepted? – Ivan Jul 19 '15 at 17:44