2014-06-17 3 views
0

즉, Grunt 출력을 가져 와서 내 Gruntfile 내에서 http POST 요청을 할 수 있도록 액세스하는 방법이 있는지 궁금합니다.Gruntfile.js의 Grunt 출력에 액세스하기

긴 형식 : 나는 Grunt (karma 및 jshint)를 사용하여 실행중인 테스트에서 데이터를 가져 와서 게시 요청에서 karma 및 jshint가 성공했는지 여부를 확인합니다. 이것을 쉽게 할 수 있습니까? 또는 그르 넛의 출력물을 파일에 쓰고 파싱 한 다음 grunt.file과 같은 것을 사용하여 데이터를 내 그란트 파일로 읽는 것과 같은 작업을 수행해야합니까?

도움 주셔서 감사합니다.

답변

0

그란트는 로그 메시지 작성을위한 grunt.log 개체를 사용합니다. sources에서 볼 수 있듯이 이제 grunt.log은 별도의 모듈 grunt-legacy-log에 구현되었습니다. 어쨌든, 우리는 Gruntfile 내부에서이 메소드들을 재정 의하여 우리가 원하는 로그로 어떤 액션을 수행 할 수 있습니다.

첫째, NPM을 통해 grunt-legacy-log를 설치

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({ .. }); 
}; 

합니다. 희망하는 데이터를 수집하고 직접 작업을 작성할 수 있기를 바랍니다.

관련 문제