Issues (791)

src/cli/extend/process.js (3 issues)

1
import process from 'child_process'
2
import fse from 'fs-extra'
3
4
import {
5
  config
6
  ,abeExtend
7
} from '../'
8
9
function prepend(value, array) {
10
  var newArray = array.slice(0)
11
  newArray.unshift(value)
12
  return newArray
13
}
14
15
var abeProcess = function(name, args = []) {
16
  args = prepend(`ABE_WEBSITE=${config.root}`, args)
17
  args = prepend(`ABEJS_PATH=${__dirname}/../../../dist`, args)
18
19
  if (!abeExtend.lock.create(name)) {
20
    return false
21
  }
22
23
  var proc
24
  var file = `${__dirname}/../../cli/process/${name}.js`
25
  try {
26
    var stats = fse.statSync(file)
27
    if (stats.isFile()) {
28
      proc = process.fork(file, args)
29
    }
30
  }catch(err) {
31
    try {
32
      file = abeExtend.plugins.instance.getProcess(name)
33
      stats = fse.statSync(file)
34
      if (stats.isFile()) {
35
        proc = process.fork(file, args)
36
      }
37
    }catch(err) {
38
      console.log('process fork failed')
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
39
    }
40
  }
41
42
  if(typeof proc !== 'undefined' && proc !== null) {
0 ignored issues
show
The variable proc seems to not be initialized for all possible execution paths.
Loading history...
43
    proc.on('message', function() {
44
      abeExtend.lock.remove(name)
45
      proc.kill()
0 ignored issues
show
The variable proc seems to not be initialized for all possible execution paths.
Loading history...
46
    })
47
    return true
48
  }
49
50
  return false
51
}
52
53
export default abeProcess