Total Complexity | 7 |
Complexity/F | 1.75 |
Lines of Code | 35 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | 'use strict' |
||
2 | |||
3 | const output = require('../output') |
||
4 | const path = require('path') |
||
5 | const childProcess = require('shelljs') |
||
6 | |||
7 | function runProcess (script, callback, basePath) { |
||
8 | var opts = { |
||
9 | silent: true, |
||
10 | async: true |
||
11 | } |
||
12 | if (basePath) { |
||
13 | opts.cwd = path.resolve(basePath) |
||
14 | } |
||
15 | |||
16 | var process = childProcess.exec(script, opts) |
||
17 | output.logComponent('Script', 'blue', 'Executing "' + script + '"') |
||
18 | process.on('exit', function (code) { |
||
19 | code = parseInt(code, 10) || code |
||
20 | output.logComponent('Script', code === 0 ? 'blue' : 'red', 'Exited with code ' + code) |
||
21 | if (callback) { |
||
22 | callback(code) |
||
23 | } |
||
24 | }) |
||
25 | process.stderr.on('data', function (message) { |
||
26 | output.logComponent('Script', 'red', message) |
||
27 | }) |
||
28 | process.stdout.on('data', function (message) { |
||
29 | output.logComponent('Script', 'blue', message) |
||
30 | }) |
||
31 | } |
||
32 | |||
33 | module.exports = { |
||
34 | run: runProcess |
||
35 | } |
||
36 |