lib/util/ChildProcess.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 35
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 35
rs 10
wmc 7
mnd 1
bc 6
fnc 4
bpm 1.5
cpm 1.75
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B ChildProcess.js ➔ runProcess 0 25 2
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