1 |
|
2 | (function() {
|
3 | var chalk, clone, defaults, exec, exit, isEmpty, json, merge, ref, ref1, run, type;
|
4 |
|
5 | ref = require('shelljs'), exec = ref.exec, exit = ref.exit;
|
6 |
|
7 | ref1 = require('lodash'), clone = ref1.clone, defaults = ref1.defaults, merge = ref1.merge, isEmpty = ref1.isEmpty;
|
8 |
|
9 | chalk = require('chalk');
|
10 |
|
11 | type = require('./type').type;
|
12 |
|
13 | json = require('./log').json;
|
14 |
|
15 | run = function(command, options) {
|
16 | var exitCode, originalOptions, prettyCommand, ref2, ref3, result;
|
17 | if (options == null) {
|
18 | options = {};
|
19 | }
|
20 | originalOptions = clone(options);
|
21 | defaults(options, {
|
22 | color: true,
|
23 | relaxed: false,
|
24 | quiet: false,
|
25 | quietCommand: (ref2 = options.quiet) != null ? ref2 : false,
|
26 | quietResponse: (ref3 = options.quiet) != null ? ref3 : false
|
27 | });
|
28 | if (!options.quietCommand) {
|
29 | prettyCommand = "\n==> " + command + " " + (isEmpty(originalOptions) ? '' : '# ' + json(originalOptions));
|
30 | if (options.color) {
|
31 | prettyCommand = chalk.green(prettyCommand);
|
32 | }
|
33 | console.log(prettyCommand);
|
34 | }
|
35 | result = exec(command, merge(options, {
|
36 | quiet: options.quietResponse
|
37 | }));
|
38 | exitCode = result.code;
|
39 | if (type(exitCode) !== 'undefined' && exitCode !== 0 && !options.relaxed) {
|
40 | console.error("COMMAND FAILED: " + (json({
|
41 | exitCode: exitCode
|
42 | })));
|
43 | exit(exitCode);
|
44 | }
|
45 | return result;
|
46 | };
|
47 |
|
48 | module.exports = {
|
49 | run: run
|
50 | };
|
51 |
|
52 | }).call(this);
|