Gruntjs 访问Gruntfile.js中的Grunt输出
简而言之,我想知道的是,是否有一种方法可以获取Grunt输出并在Gruntfile中访问它,以便能够发出http POST请求 长格式:我想从使用Grunt(karma和jshint)运行测试中获取数据,并利用karma和jshint在post请求中是否通过。这样做容易吗?或者我需要将Grunt的输出写入一个文件,对其进行解析,然后使用Grunt.file之类的东西将数据读入Gruntfile 感谢您的帮助。Grunt使用对象中的方法来编写日志消息。正如您在中所看到的,Gruntjs 访问Gruntfile.js中的Grunt输出,gruntjs,Gruntjs,简而言之,我想知道的是,是否有一种方法可以获取Grunt输出并在Gruntfile中访问它,以便能够发出http POST请求 长格式:我想从使用Grunt(karma和jshint)运行测试中获取数据,并利用karma和jshint在post请求中是否通过。这样做容易吗?或者我需要将Grunt的输出写入一个文件,对其进行解析,然后使用Grunt.file之类的东西将数据读入Gruntfile 感谢您的帮助。Grunt使用对象中的方法来编写日志消息。正如您在中所看到的,grunt.log现在在一
grunt.log
现在在一个单独的模块grunt legacy log
中实现。因此,无论如何,我们可以从GrunFile内部重新定义这些方法,以使用我们想要的日志执行任何操作
首先,通过npm安装grunt遗留日志
:
npm install grunt-legacy-log
然后,重新定义grunt.log
,如下所示:
module.exports = function (grunt) {
var Log = require('grunt-legacy-log').Log;
var log = new Log({grunt: grunt});
function LogExtended() {
for (var methodName in log) {
if (typeof log[methodName] === 'function') {
this[methodName] = (function (methodName) {
return function () {
var args = Array.prototype.slice.call(arguments, 0);
// Filter methods yourself here to collect data
// and perform any actions like POST to server
console.log(methodName, args);
// This will call original grunt.log method
return log[methodName].apply(log, args);
}
}(methodName));
}
}
}
LogExtended.prototype = log;
grunt.log = new LogExtended();
grunt.initConfig({ .. });
};
就这样。希望你能收集到需要的资料