MCPcopy Create free account
hub / github.com/breck7/scroll / clone

Method clone

clone.js:19–69  ·  view source on GitHub ↗
(cwd, gitUrl, folderName)

Source from the content-addressed store, hash-verified

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) {

Callers 1

cloneCommandMethod · 0.95

Calls 8

buildCommandMethod · 0.95
resolveFunction · 0.85
replaceMethod · 0.80
splitMethod · 0.80
logMethod · 0.80
writeMethod · 0.45
toStringMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected