| Total Complexity | 10 |
| Complexity/F | 3.33 |
| Lines of Code | 55 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import process from 'child_process' |
||
| 2 | import fse from 'fs-extra' |
||
| 3 | import path from 'path' |
||
| 4 | import fs from 'fs' |
||
| 5 | |||
| 6 | import { |
||
| 7 | config |
||
| 8 | ,abeExtend |
||
| 9 | } from '../' |
||
| 10 | |||
| 11 | function prepend(value, array) { |
||
| 12 | var newArray = array.slice(0) |
||
| 13 | newArray.unshift(value) |
||
| 14 | return newArray |
||
| 15 | } |
||
| 16 | |||
| 17 | var abeProcess = function(name, args = []) { |
||
| 18 | args = prepend(`ABE_WEBSITE=${config.root}`, args) |
||
| 19 | args = prepend(`ABEJS_PATH=${__dirname}/../../../dist`, args) |
||
| 20 | |||
| 21 | if (!abeExtend.lock.create(name)) { |
||
| 22 | return false |
||
| 23 | } |
||
| 24 | |||
| 25 | var proc |
||
| 26 | var file = `${__dirname}/../../cli/process/${name}.js` |
||
| 27 | try { |
||
| 28 | var stats = fse.statSync(file) |
||
| 29 | if (stats.isFile()) { |
||
| 30 | proc = process.fork(file, args) |
||
| 31 | } |
||
| 32 | }catch(err) { |
||
| 33 | try { |
||
| 34 | file = abeExtend.plugins.instance.getProcess(name) |
||
| 35 | stats = fse.statSync(file) |
||
| 36 | if (stats.isFile()) { |
||
| 37 | proc = process.fork(file, args) |
||
| 38 | } |
||
| 39 | }catch(err) { |
||
| 40 | console.log('process fork failed') |
||
|
|
|||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if(typeof proc !== 'undefined' && proc !== null) { |
||
| 45 | proc.on('message', function( msg ) { |
||
| 46 | abeExtend.lock.remove(name) |
||
| 47 | proc.kill() |
||
| 48 | }); |
||
| 49 | return true |
||
| 50 | } |
||
| 51 | |||
| 52 | return false |
||
| 53 | } |
||
| 54 | |||
| 55 | export default abeProcess |