8
0

tools.js 686 B

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