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

module.exports   C

Complexity

Conditions 8
Paths 17

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
c 1
b 0
f 0
nc 17
nop 1
dl 0
loc 31
rs 5.3846
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