8
0

tools.js 622 B

12345678910111213141516171819202122232425262728293031
  1. /* global module */
  2. /* global require */
  3. 'use strict';
  4. var dirtyFiles;
  5. module.exports = {
  6. getGitDirtyFiles: function() {
  7. // Cache it, so it is executed only once when running multiple tasks.
  8. if ( !dirtyFiles ) {
  9. dirtyFiles = this.shExec( 'git diff-index --name-only HEAD' ).replace( /\s*$/, '' ).split( '\n' );
  10. }
  11. return dirtyFiles;
  12. },
  13. shExec: function( command ) {
  14. var sh = require( 'shelljs' );
  15. sh.config.silent = true;
  16. var ret = sh.exec( command );
  17. if ( ret.code ) {
  18. throw new Error(
  19. 'Error while executing `' + command + '`:\n\n' +
  20. ret.output
  21. );
  22. }
  23. return ret.output;
  24. }
  25. };