Completed
Push — master ( a35fd3...1710d3 )
by Thomas
31s
created

module.exports   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 2
nop 3
dl 0
loc 14
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 12 4
1
'use strict'
2
3
const minimatch = require('minimatch')
4
const _ = require('lodash')
5
const request = require('../util').request
6
const Module = require('../containers/Module')
7
8
const reload = _.debounce(function (containerToken, path, event) {
9
  request(containerToken + '/ws', {
10
    type: 'autoreload',
11
    payload: {
12
      path: path,
13
      event: event
14
    }
15
  }, {
16
    'Content-Type': 'multipart/form-data'
17
  }).end()
18
}, 120)
19
20
const matchFile = function (options, path) {
21
  if (typeof options.paths === 'string') {
22
    options.paths = [options.paths]
23
  }
24
25
  for (var i in options.paths) {
26
    if (!options.paths.hasOwnProperty(i)) {
27
      continue
28
    }
29
    if (minimatch(path, options.paths[i])) {
30
      return true
31
    }
32
  }
33
34
  return false
35
}
36
37
module.exports = function (containerToken, path, event) {
38
  Module.getManifest(function (manifest) {
39
    var options = manifest.getDevOption('autoreload')
40
    if (!options || !('paths' in options)) {
41
      return
42
    }
43
44
    if (!matchFile(options, path)) {
45
      return
46
    }
47
48
    reload(containerToken, path, event)
49
  })
50
}
51