forked from standard/standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone.js
More file actions
132 lines (116 loc) · 3.64 KB
/
Copy pathclone.js
File metadata and controls
132 lines (116 loc) · 3.64 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/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 crossSpawnAsync = require('cross-spawn-async')
var fs = require('fs')
var minimist = require('minimist')
var mkdirp = require('mkdirp')
var os = require('os')
var parallelLimit = require('run-parallel-limit')
var path = require('path')
var standardPackages = require('standard-packages')
var test = require('tape')
var GIT = 'git'
var STANDARD = path.join(__dirname, '..', 'bin', 'cmd.js')
var TMP = path.join(__dirname, '..', 'tmp')
var PARALLEL_LIMIT = os.cpus().length
var argv = minimist(process.argv.slice(2), {
boolean: [
'disabled',
'offline',
'quick',
'quiet'
]
})
var testPackages = argv.quick
? standardPackages.test.slice(0, 20)
: standardPackages.test
var disabledPackages = []
testPackages = testPackages.filter(function (pkg) {
if (pkg.disable) disabledPackages.push(pkg)
return !pkg.disable
})
if (argv.disabled) {
testPackages = disabledPackages
} else {
test('Disabled Packages', function (t) {
if (disabledPackages.length === 0) {
t.pass('no disabled packages')
t.end()
} else {
t.plan(disabledPackages.length)
disabledPackages.forEach(function (pkg) {
t.pass('DISABLED: ' + pkg.name + ': ' + pkg.disable + ' (' + pkg.repo + ')')
})
}
})
}
test('test github repos that use `standard`', function (t) {
t.plan(testPackages.length)
mkdirp.sync(TMP)
parallelLimit(testPackages.map(function (pkg) {
var name = pkg.name
var url = pkg.repo + '.git'
var folder = path.join(TMP, name)
return function (cb) {
fs.access(path.join(TMP, name), fs.R_OK | fs.W_OK, function (err) {
if (argv.offline) {
if (err) {
t.pass('SKIPPING (offline): ' + name + ' (' + pkg.repo + ')')
return cb(null)
}
runStandard(cb)
} else {
downloadPackage(function (err) {
if (err) return cb(err)
runStandard(cb)
})
}
function downloadPackage (cb) {
if (err) gitClone(cb)
else gitPull(cb)
}
function gitClone (cb) {
var args = [ 'clone', '--depth', 1, url, path.join(TMP, name) ]
spawn(GIT, args, { stdio: 'ignore' }, function (err) {
if (err) err.message += ' (' + name + ')'
cb(err)
})
}
function gitPull (cb) {
var args = [ 'pull' ]
spawn(GIT, args, { cwd: folder, stdio: 'ignore' }, function (err) {
if (err) err.message += ' (' + name + ')'
cb(err)
})
}
function runStandard (cb) {
var args = [ '--verbose' ]
if (pkg.args) args.push.apply(args, pkg.args)
spawn(STANDARD, args, { cwd: folder }, function (err) {
var str = name + ' (' + pkg.repo + ')'
if (err) { t.fail(str) } else { t.pass(str) }
cb(null)
})
}
})
}
}), PARALLEL_LIMIT, function (err) {
if (err) throw err
})
})
function spawn (command, args, opts, cb) {
if (!opts.stdio) opts.stdio = argv.quiet ? 'ignore' : 'inherit'
var child = crossSpawnAsync(command, args, opts)
child.on('error', cb)
child.on('close', function (code) {
if (code !== 0) return cb(new Error('non-zero exit code: ' + code))
cb(null)
})
return child
}