Stop Gulp Task if Conditions are met

后端 未结 3 2281
别跟我提以往
别跟我提以往 2021-02-20 18:01

I am trying to make it so if a --theme flag isn\'t specified it stops the gulp task and wondering the best way to do it in a DRY way.

I would like each individual task t

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 18:22

    Some sort of async function might help you here. Maybe like this:

    function processArgs(callback) {
      if(typeof(args.theme) == 'undefined' || args.theme === true) {
        return callback(new Error('Theme Not Defined'));
      }
      return callback();
    }
    
    gulp.task('test', function(done) {
      processArgs(function(err) {
        if(err) {
          console.log(err); 
          return done(err);
         }
    
        //else run my task
      })
    });
    

提交回复
热议问题