How do you make grunt.js not crash on warnings by default?

后端 未结 2 1076
别跟我提以往
别跟我提以往 2021-02-07 04:37

I\'m using Grunt to compile CoffeeScript and Stylus with a watch task. I also have my editor (SublimeText) set to save files every time I page away from them (I hate losing work

2条回答
  •  再見小時候
    2021-02-07 05:14

    I tried asgoth's solution with Adam Hutchinson's suggestion, but found that the force flag was being set back immediately to false. Reading the grunt.task API docs for grunt.task.run, it states that

    Every specified task in taskList will be run immediately after the current task completes, in the order specified.

    Which meant that I couldn't simply set the force flag back to false immediately after calling grunt.task.run. The solution I found was to have explicit tasks setting the force flag to false afterwards:

    grunt.registerTask('task-that-might-fail-wrapper','Runs the task that might fail wrapped around a force wrapper', function() {
        var tasks;
        if ( grunt.option('force') ) {
            tasks = ['task-that-might-fail'];
        } else {
            tasks = ['forceon', 'task-that-might-fail', 'forceoff'];
        }
        grunt.task.run(tasks);
    });
    
    grunt.registerTask('forceoff', 'Forces the force flag off', function() {
        grunt.option('force', false);
    });
    
    grunt.registerTask('forceon', 'Forces the force flag on', function() {
        grunt.option('force', true);
    });
    

提交回复
热议问题