user.js 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var shell = require('shelljs');
  2. var _ = require('lodash');
  3. var user = module.exports;
  4. /**
  5. * Git related method
  6. *
  7. * The value will come from the global scope or the project scope (it'll take
  8. * what git will use in the current context)
  9. */
  10. var usernameCache = {};
  11. var emailCache = {};
  12. user.git = {
  13. // current git user.name
  14. get username() {
  15. var username = usernameCache[process.cwd()];
  16. if (username) {
  17. return username;
  18. }
  19. username = shell.exec('git config --get user.name', { silent: true }).output.trim();
  20. usernameCache[process.cwd()] = username;
  21. return username;
  22. },
  23. // current git user.email
  24. get email() {
  25. var email = emailCache[process.cwd()];
  26. if (email) {
  27. return email;
  28. }
  29. email = shell.exec('git config --get user.email', { silent: true }).output.trim();
  30. emailCache[process.cwd()] = email;
  31. return email;
  32. }
  33. };