-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone.js
47 lines (38 loc) · 1.09 KB
/
clone.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require('fs')
const { exec } = require('child_process')
const { readJson } = require('./shared/json')
const { enquire } = require('./shared/enquire')
const { Log } = require('./shared/log')
const log = new Log()
main()
async function main() {
const { configPath } = await enquire([
['configPath', 'repository config file path'],
])
const configs = readJson(configPath)
cloneRepositoryGroup(configs)
}
function cloneRepositoryGroup(configs) {
if (Array.isArray(configs)) {
configs.forEach(c => cloneRepositories(c))
return
}
cloneRepositories(configs)
}
function cloneRepositories({ target, repositories }) {
repositories.forEach(r => cloneRepository(target, r))
}
function cloneRepository(targetPath, repository) {
const url = repository.http_url_to_repo || repository.ssh_url_to_repo
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath)
}
const command = `git clone ${url}`
exec(command, { cwd: targetPath }, error => {
if (error) {
log.error(`clone ${url}: ${error.message}`)
return
}
log.success(`cloned ${url}`)
})
}