2017-08-27 50 views
0

我正在运行grunt命令,但它显示我想要删除的页眉和页脚。运行grunt命令时删除输出页眉和页脚

这是我Gruntfile.js

module.exports = function(grunt) { 
    grunt.initConfig({ 
     exec: { 
      ls: { 
       command: 'ls -la', 
       stdout: true, 
       stderr: true, 
      } 
     } 
    }); 
    grunt.loadNpmTasks('grunt-exec'); 
    grunt.registerTask('ls', ['exec:ls']); 
} 

,这就是我得到:

[编辑]

我得到了下面的图像上突出显示的标题混淆。我想强调:

Running "exec:ls" (exec) task 

enter image description here

有也许有些选项我可以使用目标中移除(黄色突出显示)?

+0

您是否突出显示了正确的文字?你的意思是隐藏标题:即'运行'exec:1s“(exec)task'而不是你运行的命令:即'$ grunt ls'? – RobC

+0

哦,是的,你是对的。固定。 – Angel

回答

1

Running "exec:ls" (exec) task可以通过安装grunt-reporter

Gruntfile.js省略

Gruntfile.js可以如下进行配置:

module.exports = function (grunt) { 

    grunt.initConfig({ 
    reporter: { 
     exec: { 
     options: { 
      tasks: ['exec:ls'], 
      header: false 
     } 
     } 
    }, 

    exec: { 
     ls: { 
     command: 'ls -la', 
     stdout: true, 
     stderr: true 
     } 
    } 
    }); 

    require('load-grunt-tasks')(grunt); 

    grunt.registerTask('ls', [ 
    'reporter:exec', //<-- The call to the reporter must be before exec. 
    'exec:ls' 
    ]); 
} 

grunt-reporter使用未加载grunt.loadNpmTasks(...)。相反它利用load-grunt-task。这也将处理加载grunt-exec,所以不需要grunt.loadNpmTasks(...)任何其他模块。


但对于Done

不幸的是grunt-reporter没有提供省略最终的Done消息的功能。

要省略Done您必须求助于完成用空函数替换grunt的内部grunt.log.success函数。这种方法并不特别好,因为它有点破解。例如,你可以添加以下内容到你的配置的顶部:

module.exports = function (grunt) { 

    grunt.log.success = function() {}; // <-- Add this before grunt.initConfig({...}) 

    // ... 

} 

同样的黑客也可以用于头,也不过是grunt-reporter IMO一个更简洁的方法。即

module.exports = function (grunt) { 

    grunt.log.header = function() {}; // <-- Blocks all header logs. 

    // ... 

} 
+0

谢谢,那工作! – Angel