Completed
Push — master ( 1abe1d...4b8289 )
by Thomas
46s
created

lib/plugins/Autoreload.js   A

Complexity

Total Complexity 9
Complexity/F 4.5

Size

Lines of Code 39
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 2
dl 0
loc 39
rs 10
wmc 9
mnd 2
bc 8
fnc 2
bpm 4
cpm 4.5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B module.exports 0 33 1
1
'use strict'
2
3
const minimatch = require('minimatch')
4
const Module = require('../containers/Module')
5
const Socket = require('../containers/Socket')
6
7
module.exports = function (path) {
8
  Module.getManifest(function (manifest) {
9
    var options = manifest.getDevOption('autoreload')
10
    if (!options || !('paths' in options)) {
11
      return
12
    }
13
    if (typeof options.paths === 'string') {
14
      options.paths = [options.paths]
15
    }
16
17
    var matched = false
18
    for (var i in options.paths) {
19
      if (!options.paths.hasOwnProperty(i)) {
20
        continue
21
      }
22
      if (minimatch(path, options.paths[i])) {
23
        matched = true
24
        break
25
      }
26
    }
27
28
    if (!matched) {
29
      return
30
    }
31
32
    Socket.emit('passthrough', {
33
      plugin: 'autoreload',
34
      data: {
35
        path: path
36
      }
37
    })
38
  })
39
}
40