Stop Gulp Task if Conditions are met

后端 未结 3 2356
别跟我提以往
别跟我提以往 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条回答
  •  离开以前
    2021-02-20 18:39

    I think the easiest way would be to create a verifyArgs function which throws an error when the requirements aren't met:

    function verifyArgs() {
      if(typeof(args.theme) == 'undefined' || args.theme === true) {
        throw Error(msg.noTheme);
      }
    }
    
    gulp.task('test', function() {
        verifyArgs();
        // run rest of task...
    });
    
    gulp.task('test-2', function() {
        verifyArgs();
        // run rest of task...
    });
    
    gulp.task('default', ['test-1', 'test-2']);
    

提交回复
热议问题