Skip to content

Commit

Permalink
feat: cloneRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Jun 29, 2023
1 parent 986902d commit 0ba1465
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/utils/cloneRepo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { exec } from 'node:child_process'
import { promises as fs } from 'node:fs'
import { join } from 'node:path'

async function removeGitFolder(localPath: string): Promise<void> {
const gitFolderPath = join(localPath, '.git')
await fs.rm(gitFolderPath, { recursive: true, force: true })
}

export function cloneRepo(gitUrl: string, localPath: string): Promise<void> {
return new Promise((resolve, reject) => {
exec(`git clone ${gitUrl} ${localPath}`, async (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`)
reject(error)
return
}
console.log(`stdout: ${stdout}`)

Check failure on line 18 in src/utils/cloneRepo.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.error(`stderr: ${stderr}`)

try {
await removeGitFolder(localPath)
resolve()
}
catch (error) {
console.error('Failed to remove .git folder: ', error)
reject(error)
}
})
})
}

0 comments on commit 0ba1465

Please sign in to comment.