Skip to content

Commit

Permalink
Merge pull request react-bootstrap#851 from AlexKVal/tools
Browse files Browse the repository at this point in the history
Simplify tools/exec
  • Loading branch information
AlexKVal committed Jun 18, 2015
2 parents e7825eb + 6e61d7c commit 2f0befc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
3 changes: 2 additions & 1 deletion tools/build-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ let buildProcess = argv.docsOnly ? docs(argv) : build();

buildProcess
.catch(err => {
console.error(err.toString().red);
if (err.stack) {
console.error(err.stack.red);
} else {
console.error(err.toString().red);
}
process.exit(1);
});
43 changes: 19 additions & 24 deletions tools/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,31 @@ let executionOptions = {
};

function logWithPrefix(prefix, message) {
let formattedMessage = message.trim().split('\n')
.reduce((acc, line) => `${acc}${ acc !== '' ? '\n' : '' }${prefix} ${line}`, '');

console.log(formattedMessage);
console.log(
message.toString().trim()
.split('\n')
.map((line) => `${prefix.grey} ${line}`)
.join('\n')
);
}

function execWrapper(command, options = {}) {
let proc = exec(command, options);
let title = options.title || command;
let log = message => logWithPrefix(`[${title}]`.grey, message);

if (executionOptions.verbose) {
let output = (data, type) => {
logWithPrefix(`[${title}] ${type}:`.grey, data.toString());
};
proc = proc.progress(({stdout, stderr}) => {
stdout.on('data', data => output(data, 'stdout'));
stderr.on('data', data => output(data, 'stderr'));
})
.then(result => {
log('Complete'.cyan);
return result;
})
.catch(err => {
log(`ERROR: ${err.toString()}`.red);
throw err;
});
if (!executionOptions.verbose) {
return proc;
}

return proc;
let title = options.title || command;
let output = (data, type) => logWithPrefix(`[${title}] ${type}:`, data);

return proc.progress(({stdout, stderr}) => {
stdout.on('data', data => output(data, 'stdout'));
stderr.on('data', data => output(data, 'stderr'));
})
.then(result => {
logWithPrefix(`[${title}]`, 'Complete'.cyan);
return result;
});
}

function safeExec(command, options = {}) {
Expand Down

0 comments on commit 2f0befc

Please sign in to comment.