forked from hughsk/scoped-bulk
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
36 lines (31 loc) · 1006 Bytes
/
index.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
'use strict'
var cp = require('child_process')
var spawn = cp.spawn
var exec = cp.exec
module.exports = function () {
if (arguments.length >= 3) return bulkExec.apply(this, arguments)
return bulkSpawn.apply(this, arguments)
}
module.exports.exec = bulkExec
module.exports.spawn = bulkSpawn
module.exports.cmd = require.resolve('./cli')
function bulkExec (dirs, cmd, opts, fn) {
// opts is optional
if (arguments.length === 3) {
fn = opts
opts = {}
return bulkExec(dirs, cmd, opts, fn)
}
if (!cmd) throw new Error('command required: ' + cmd)
opts = opts || {}
var execCmd = 'echo ' + dirs.join(' ') + ' | ' + require.resolve('./bulk')
if ('onlyDirs' in opts && !opts.onlyDirs) execCmd += ' --no-only-dirs'
return exec(execCmd + ' -c ' + cmd, opts, fn)
}
function bulkSpawn (cmd, opts) {
if (!cmd) throw new Error('command required: ' + cmd)
// opts is optional
opts = opts || {}
opts.stdio = 'pipe'
return spawn(require.resolve('./bulk'), ['-c', cmd], opts)
}