2015-09-04 72 views
0

我尝试为WordPress实现plugin,我使用phpcsWordPress标准。Grunt phpcs多任务不运行

在我的情况的问题是,默认WordPress标准phpcs检查也为WordPress的-VIP是出于我的需要,我喜欢做的事情,是测试我的代码对ExtraDocsCore标准。

所以,在我的应用我有安装grunt-phpcs模块和内部我Gruntfile.js我安装的示例代码,就像下面和正常工作:

phpcs : { 
    application : { 
     src : [ 
      'includes/**/*.php', 
      'php/**/*.php', 
      'my-plugin.php' 
     ] 
    }, 
    options  : { 
     bin  : '/usr/local/bin/phpcs', 
     standard : 'WordPress-Extra' 
    } 
} 

但正如我上面描述,这不解决我的问题,所以我尝试以下方法:

phpcs : { 
     extra : { 
      application : { 
       src : [ 
        'includes/**/*.php', 
        'php/**/*.php', 
        'my-plugin.php' 
       ] 
      }, 
      options  : { 
       bin  : '/usr/local/bin/phpcs', 
       standard : 'WordPress-Extra' 
      } 
     }, 
     docs : { 
      application : { 
       src : [ 
        'includes/**/*.php', 
        'php/**/*.php', 
        'my-plugin.php' 
       ] 
      }, 
      options  : { 
       bin  : '/usr/local/bin/phpcs', 
       standard : 'WordPress-Docs' 
      } 
     }, 
     core : { 
      application : { 
       src : [ 
        'includes/**/*.php', 
        'php/**/*.php', 
        'my-plugin.php' 
       ] 
      }, 
      options  : { 
       bin  : '/usr/local/bin/phpcs', 
       standard : 'WordPress-Core' 
      } 
     } 
    } 

但是这一次,当我尝试运行grunt phpcs:extragrunt phpcs:docsgrunt phpcs:core,我得到的结果是phpcs --help,这意味着phpcs不以这种方式工作。

那么,有没有其他的方式来执行相同的任务,但这次是工作?

另一种选择,我想的是做类似如下:

grunt.registerTask('phpcs_extra', function() { 
    // do stuff 
} 

grunt.registerTask('phpcs_docs', function() { 
    // do stuff 
} 

grunt.registerTask('phpcs_core', function() { 
    // do stuff 
} 

,但我不知道是否能正常工作。

回答

1

你可以试试下面registerTask:

grunt.registerTask('phpcs_extra', function() { 

    var application = { 
     src : [ 
      'includes/**/*.php', 
      'php/**/*.php', 
      'my-plugin.php' 
     ] 
    }; 

    var options = { 
     bin  : '/usr/local/bin/phpcs', 
     standard : 'WordPress-Extra' 
    }; 

    grunt.config.set('phpcs.application', application); 
    grunt.config.set('phpcs.options', options); 
    grunt.task.run('phpcs'); 

}); 
+0

谢谢! :) 那太棒了 ... –