-
Notifications
You must be signed in to change notification settings - Fork 1
/
jst-nuke-clone
executable file
·65 lines (59 loc) · 2.01 KB
/
jst-nuke-clone
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
/*
* Clone all repos under the jstransformer organization
* Copyright © 2015 Tiancheng “Timothy” Gu
* MIT-licensed
*/
var repos = require('./repos')
, config = require('./read-config')
, exec = require('child_process').exec
, readdir = require('fs').readdirSync
, async = require('async')
, assert = require('assert')
, argv = require('commander')
.description('Clone all repos under the jstransformer '
+ 'organization.')
.option('-r, --root <dir>', 'directory to host all Git repos')
.option('-j, --max-jobs <n>'
, 'maximum number of cloning process running '
+ 'simultaneously', parseInt)
.parse(process.argv)
var p = require('path').join.bind(this, argv.root || config.root || '')
repos(function (err, obj) {
if (err) {
console.log(err)
process.exit(1)
}
var each = argv.maxJobs ? async.eachLimit.bind(this, obj, argv.maxJobs)
: async.each.bind(this, obj)
, errored = []
, TOTAL = obj.length
, c = 1
each(function (repo, cb) {
var name = repo.name
try {
if (!readdir(p(name)).length) throw new Error('now, clone it.')
var tail = '\t' + name + '\t(' + (c++) + '/' + TOTAL + ')'
console.log('Skipping:' + tail)
return cb()
} catch (ignored) {}
console.log('Cloning:\t' + name)
exec('git clone [email protected]:jstransformers/' + name + '.git' + ' ' + p(name), function (err) {
var tail = '\t' + name + '\t(' + (c++) + '/' + TOTAL + ')'
if (err) {
console.log('Errored:' + tail)
errored.push({ name: name, err: err.message })
} else {
console.log('Done:\t' + tail)
}
cb()
})
}, function () {
if (errored.length) {
console.log('Cloning failed:')
errored.forEach(function (repo) {
console.log('\t' + repo.name + '\t' + repo.err)
})
} else console.log('All finished')
})
})