-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
51 lines (43 loc) · 1.36 KB
/
run.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
const execa = require('execa');
const path = require('path');
function handleExit(code, stderr, errorCallback) {
if (code !== 0) {
if (errorCallback && typeof errorCallback === 'function') {
errorCallback(stderr);
}
process.exit(code);
}
}
async function run({ watch, dir, silent, command, errorCallback }) {
return new Promise(async (resolve, reject) => {
if (command !== '') {
if (dir) await execa.command('npx copyfiles -u 1 src/**/*.css ' + dir);
const child = execa.command(command, {
... {
buffer: false,
}, ...(dir ? { env: { BABEL_MODE: path.basename(dir) } } : {})
});
let stderr = '';
if (watch) {
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
} else {
child.stderr.on('data', (data) => {
stderr += data.toString();
});
child.stdout.on('data', (data) => {
stderr += data.toString();
});
}
child.on('exit', (code) => {
resolve();
handleExit(code, stderr, errorCallback);
});
} else {
resolve();
}
});
}
module.exports = {
run,
};