Completed
Push — master ( 6eff60...46c46b )
by
unknown
01:53
created

abe-process.js ➔ abeProcess   B

Complexity

Conditions 5
Paths 20

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 20
nop 2
dl 0
loc 22
rs 8.6737
1
import process from 'child_process'
2
import fse from 'fs-extra'
3
4
import {
5
  config
6
  ,Plugins
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
  var file = `${__dirname}/../../cli/process/${name}.js`
20
  try {
21
		var stats = fse.statSync(file)
22
		if (stats.isFile()) {
23
			process.fork(file, args)
24
		}
25
	}catch(err) {
26
		try {
27
			file = Plugins.instance.getProcess(name)
28
			var stats = fse.statSync(file)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable stats already seems to be declared on line 21. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
29
			if (stats.isFile()) {
30
				process.fork(file, args)
31
			}
32
		}catch(err) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
33
			
34
		}
35
	}
36
}
37
38
export default abeProcess