当 运行 一个 grunt 命令时删除输出 header 和页脚
remove output header and footer when running a grunt command
我是 运行 一个 grunt
命令,但它显示了一个 header 和我想删除的页脚。
这是我的 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']);
}
这就是我得到的:
[编辑]
我对下图中突出显示的 header 感到困惑。我想强调:
Running "exec:ls" (exec) task
我可以在目标内部使用一些选项来删除它(黄色突出显示)吗?
可以省略headerRunning "exec:ls" (exec) task
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
函数。这种方法不是特别好,因为它有点 hack。例如,您可以将以下内容添加到配置的顶部:
module.exports = function (grunt) {
grunt.log.success = function () {}; // <-- Add this before grunt.initConfig({...})
// ...
}
同样的 hack 也可以用于 header,但是 grunt-reporter
是 IMO 更简洁的方法。即
module.exports = function (grunt) {
grunt.log.header = function () {}; // <-- Blocks all header logs.
// ...
}
我是 运行 一个 grunt
命令,但它显示了一个 header 和我想删除的页脚。
这是我的 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']);
}
这就是我得到的:
[编辑]
我对下图中突出显示的 header 感到困惑。我想强调:
Running "exec:ls" (exec) task
我可以在目标内部使用一些选项来删除它(黄色突出显示)吗?
Running "exec:ls" (exec) task
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
函数。这种方法不是特别好,因为它有点 hack。例如,您可以将以下内容添加到配置的顶部:
module.exports = function (grunt) {
grunt.log.success = function () {}; // <-- Add this before grunt.initConfig({...})
// ...
}
同样的 hack 也可以用于 header,但是 grunt-reporter
是 IMO 更简洁的方法。即
module.exports = function (grunt) {
grunt.log.header = function () {}; // <-- Blocks all header logs.
// ...
}