-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
clone.js
75 lines (66 loc) · 2.03 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
/**
* Clones several projects that are known to follow "JavaScript Standard Style" and runs
* the `standard` style checker to verify that it passes without warnings. This helps
* ensure we don't accidentally introduce new style rules that cause previously "good"
* code to start failing with new warnings! (And if we do, then that needs to be a MAJOR
* VERSION BUMP.)
*/
var cp = require('child_process')
var extend = require('xtend')
var mkdirp = require('mkdirp')
var path = require('path')
var rimraf = require('rimraf')
var series = require('run-series')
var test = require('tape')
var TMP = path.join(__dirname, '..', 'tmp')
var SEMISTANDARD = path.join(__dirname, '..', 'bin', 'cmd.js')
// var URLs = require('./semistandard-repos.json')
var URLS = [
'https://github.com/Flet/cursorfun'
]
var MODULES = {}
URLS.forEach(function (url) {
var spliturl = url.split('/')
var name = spliturl[spliturl.length - 1]
MODULES[name] = url + '.git'
})
test('clone repos from github', function (t) {
rimraf.sync(TMP)
mkdirp.sync(TMP)
series(Object.keys(MODULES).map(function (name) {
var url = MODULES[name]
return function (cb) {
var args = ['clone', '--depth', 1, url, path.join(TMP, name)]
// TODO: Start `git` in a way that works on Windows – PR welcome!
spawn('git', args, {}, cb)
}
}), function (err) {
if (err) throw err
t.pass('cloned repos')
t.end()
})
})
test('lint repos', function (t) {
series(Object.keys(MODULES).map(function (name) {
return function (cb) {
var cwd = path.join(TMP, name)
spawn('node', [SEMISTANDARD], { cwd }, function (err) {
t.error(err, name)
cb(null)
})
}
}), function (err) {
if (err) throw err
t.end()
})
})
function spawn (command, args, opts, cb) {
var child = cp.spawn(command, args, extend({ stdio: 'inherit' }, opts))
child.on('error', cb)
child.on('close', function (code) {
if (code !== 0) cb(new Error('non-zero exit code: ' + code))
else cb(null)
})
return child
}