Skip to content

Commit 2f0befc

Browse files
committed
Merge pull request react-bootstrap#851 from AlexKVal/tools
Simplify tools/exec
2 parents e7825eb + 6e61d7c commit 2f0befc

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

tools/build-cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ let buildProcess = argv.docsOnly ? docs(argv) : build();
3030

3131
buildProcess
3232
.catch(err => {
33-
console.error(err.toString().red);
3433
if (err.stack) {
3534
console.error(err.stack.red);
35+
} else {
36+
console.error(err.toString().red);
3637
}
3738
process.exit(1);
3839
});

tools/exec.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,31 @@ let executionOptions = {
88
};
99

1010
function logWithPrefix(prefix, message) {
11-
let formattedMessage = message.trim().split('\n')
12-
.reduce((acc, line) => `${acc}${ acc !== '' ? '\n' : '' }${prefix} ${line}`, '');
13-
14-
console.log(formattedMessage);
11+
console.log(
12+
message.toString().trim()
13+
.split('\n')
14+
.map((line) => `${prefix.grey} ${line}`)
15+
.join('\n')
16+
);
1517
}
1618

1719
function execWrapper(command, options = {}) {
1820
let proc = exec(command, options);
19-
let title = options.title || command;
20-
let log = message => logWithPrefix(`[${title}]`.grey, message);
21-
22-
if (executionOptions.verbose) {
23-
let output = (data, type) => {
24-
logWithPrefix(`[${title}] ${type}:`.grey, data.toString());
25-
};
26-
proc = proc.progress(({stdout, stderr}) => {
27-
stdout.on('data', data => output(data, 'stdout'));
28-
stderr.on('data', data => output(data, 'stderr'));
29-
})
30-
.then(result => {
31-
log('Complete'.cyan);
32-
return result;
33-
})
34-
.catch(err => {
35-
log(`ERROR: ${err.toString()}`.red);
36-
throw err;
37-
});
21+
if (!executionOptions.verbose) {
22+
return proc;
3823
}
3924

40-
return proc;
25+
let title = options.title || command;
26+
let output = (data, type) => logWithPrefix(`[${title}] ${type}:`, data);
27+
28+
return proc.progress(({stdout, stderr}) => {
29+
stdout.on('data', data => output(data, 'stdout'));
30+
stderr.on('data', data => output(data, 'stderr'));
31+
})
32+
.then(result => {
33+
logWithPrefix(`[${title}]`, 'Complete'.cyan);
34+
return result;
35+
});
4136
}
4237

4338
function safeExec(command, options = {}) {

0 commit comments

Comments
 (0)