git.js 948 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const simpleGit = require('simple-git')
  2. const fs = require('fs')
  3. const { resolve } = require('path')
  4. const SimpleGitOptions = {
  5. baseDir: `${process.cwd()}/projects`,
  6. binary: 'git',
  7. maxConcurrentProcesses: 6,
  8. }
  9. function git (name) {
  10. const isExists = fs.existsSync(`${process.cwd()}/projects/${name}`)
  11. this.git = simpleGit( isExists ? `${process.cwd()}/projects/${name}` : `${process.cwd()}/projects`)
  12. return this
  13. }
  14. git.prototype.clone = function (repoPath, name) {
  15. return new Promise(resolve => {
  16. const isExists = fs.existsSync(`${process.cwd()}/projects/${name}`)
  17. console.log(isExists, `${process.cwd()}/projects/${name}`)
  18. if (!isExists) {
  19. this.git.clone(repoPath).then(res => {
  20. resolve()
  21. })
  22. } else {
  23. resolve()
  24. }
  25. })
  26. }
  27. git.prototype.pull = function () {
  28. return this.git.pull()
  29. }
  30. git.prototype.checkout = function (branch) {
  31. return this.git.checkout(branch)
  32. }
  33. module.exports = git