-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawn.js
41 lines (35 loc) · 924 Bytes
/
spawn.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
const { spawn } = require('child_process');
const readline = require('readline');
async function sh(path, preserveGit, exclude) {
return new Promise(function (resolve, reject) {
const find = spawn('find', [path, '-type', 'f']);
let result = find
if (preserveGit) {
const grepGit = spawn(
'grep',
['-v', '.git'],
{ stdio: [result.stdout, 'pipe', process.error] },
);
result = grepGit
}
if (exclude !== null) {
const grepExclude = spawn(
'grep',
['-v', exclude],
{ stdio: [result.stdout, 'pipe', process.error] },
);
result = grepExclude
}
let lines = [];
const rl = readline.createInterface({ input: result.stdout });
rl.on('line', function(line) {
lines.push(line);
});
result.on('exit', function(data) {
resolve({ stdout: lines })
});
});
}
module.exports = {
sh,
};