12345678910111213141516171819202122232425262728293031323334353637 |
- const simpleGit = require('simple-git')
- const fs = require('fs')
- const { resolve } = require('path')
- const SimpleGitOptions = {
- baseDir: `${process.cwd()}/projects`,
- binary: 'git',
- maxConcurrentProcesses: 6,
- }
- function git (name) {
- const isExists = fs.existsSync(`${process.cwd()}/projects/${name}`)
- this.git = simpleGit( isExists ? `${process.cwd()}/projects/${name}` : `${process.cwd()}/projects`)
- return this
- }
- git.prototype.clone = function (repoPath, name) {
- return new Promise(resolve => {
- const isExists = fs.existsSync(`${process.cwd()}/projects/${name}`)
- console.log(isExists, `${process.cwd()}/projects/${name}`)
- if (!isExists) {
- this.git.clone(repoPath).then(res => {
- resolve()
- })
- } else {
- resolve()
- }
- })
- }
- git.prototype.pull = function () {
- return this.git.pull()
- }
- git.prototype.checkout = function (branch) {
- return this.git.checkout(branch)
- }
- module.exports = git
|