(cwd, gitUrl, folderName)
| 17 | welcomeMessage = `\n👯 WELCOME TO CLONE` |
| 18 | |
| 19 | clone(cwd, gitUrl, folderName) { |
| 20 | return new Promise((resolve, reject) => { |
| 21 | const protocolPrefix = gitUrl.startsWith("http") ? "" : "https://" |
| 22 | const url = new URL(protocolPrefix + gitUrl) |
| 23 | const { hostname, pathname } = url |
| 24 | |
| 25 | if (!folderName) { |
| 26 | folderName = pathname |
| 27 | .split("/") |
| 28 | .pop() |
| 29 | .replace(/\.git$/, "") |
| 30 | if (pathname.length < 2) folderName = hostname |
| 31 | } |
| 32 | |
| 33 | // Allow cloning of domains like: clone capitaldb.togger.com |
| 34 | let cloneUrl = protocolPrefix + gitUrl |
| 35 | if (pathname.length < 2) cloneUrl = url + hostname |
| 36 | cloneUrl = cloneUrl.replace(/\.git$/, "") + ".git" |
| 37 | |
| 38 | console.log(`Running: git clone ${cloneUrl} ${folderName}`) |
| 39 | |
| 40 | const cloneProcess = spawn("git", ["clone", cloneUrl, folderName], { cwd }) |
| 41 | |
| 42 | cloneProcess.stdout.on("data", data => { |
| 43 | process.stdout.write(data.toString()) |
| 44 | }) |
| 45 | |
| 46 | cloneProcess.stderr.on("data", data => { |
| 47 | process.stderr.write(data.toString()) |
| 48 | }) |
| 49 | |
| 50 | cloneProcess.on("error", error => { |
| 51 | reject(error) |
| 52 | }) |
| 53 | |
| 54 | cloneProcess.on("close", async code => { |
| 55 | if (code === 0) { |
| 56 | console.log(`Cloned successfully into ${folderName}`) |
| 57 | try { |
| 58 | const scrollCli = new ScrollCli() |
| 59 | await scrollCli.buildCommand(path.join(cwd, folderName)) |
| 60 | resolve() |
| 61 | } catch (error) { |
| 62 | reject(error) |
| 63 | } |
| 64 | } else { |
| 65 | reject(new Error(`git clone failed with code ${code}`)) |
| 66 | } |
| 67 | }) |
| 68 | }) |
| 69 | } |
| 70 | |
| 71 | async cloneCommand(cwd, urls) { |
| 72 | for (const gitUrl of urls) { |
no test coverage detected