tools.js 703 B

12345678910111213141516171819202122232425262728293031323334
  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. if ( dirtyFiles.length == 1 && !dirtyFiles[ 0 ] ) {
  11. dirtyFiles = [];
  12. }
  13. }
  14. return dirtyFiles;
  15. },
  16. shExec: function( command ) {
  17. var sh = require( 'shelljs' );
  18. sh.config.silent = true;
  19. var ret = sh.exec( command );
  20. if ( ret.code ) {
  21. throw new Error(
  22. 'Error while executing `' + command + '`:\n\n' +
  23. ret.output
  24. );
  25. }
  26. return ret.output;
  27. }
  28. };