Completed
Push — master ( 6b23d7...ea705b )
by
unknown
02:05
created

src/cli/process/initAbeForProcesses.js   A

Complexity

Total Complexity 10
Complexity/F 1.67

Size

Lines of Code 60
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 10
c 1
b 0
f 0
nc 1
mnd 1
bc 10
fnc 6
dl 0
loc 60
rs 10
bpm 1.6666
cpm 1.6666
noi 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A initAbeForProcesses.js ➔ getTime 0 3 1
B initAbeForProcesses.js ➔ init 0 41 1
1
import debug from 'debug'
2
import extend from 'extend'
3
import moment from 'moment'
4
5
var Manager = require('../../cli').Manager
6
var Handlebars = require('../../cli').Handlebars
7
var config = require('../../cli').config
8
var abeExtend = require('../../cli').abeExtend
9
10
export var log
11
export var trace
12
export var error
13
export var processConfig
14
export var dateStart
15
16
export function getTime() {
17
	return (moment(moment() - dateStart).format('mm:ss')) + 'sec'
18
}
19
20
export function init(processName, conf) {
21
	var p = new Promise((resolve, reject) => {
0 ignored issues
show
Unused Code introduced by
The parameter reject is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
22
23
		log = debug(processName + ':log')
24
		log.color = 2
25
		trace = debug(processName + ':trace')
26
		error = debug(processName + ':error')
27
		error.color = 1
28
29
		processConfig = {}
30
		Array.prototype.forEach.call(process.argv, (item) => {
31
		  if (item.indexOf('=') > -1) {
32
		    var ar = item.split('=')
33
		    processConfig[ar[0]] = ar[1]
34
		  }
35
		})
36
		if(processConfig.ABE_WEBSITE) {
37
			config.set({root: processConfig.ABE_WEBSITE.replace(/\/$/, '') + '/'})
38
		}
39
40
		processConfig = extend(true, conf, processConfig)
41
42
		if(typeof processConfig.ABE_WEBSITE !== 'undefined' && processConfig.ABE_WEBSITE !== null) {
43
			abeExtend.hooks.instance.trigger('afterHandlebarsHelpers', Handlebars)
44
45
			Manager.instance.init()
46
	      .then(()=> {
47
	      	dateStart = moment()
48
	      	resolve()
49
	      })
50
	      .catch((e) => {
51
	        error('publish-all' + e)
52
	      })
53
		}else {
54
		  error('ABE_WEBSITE is not defined use node process.js ABE_WEBSITE=/pat/to/website')
55
		  process.exit(0)
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
56
		}
57
	})
58
59
	return p
60
}