Code Duplication    Length = 35-50 lines in 2 locations

lib/plugins/Autoreload.js 1 location

@@ 1-50 (lines=50) @@
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

lib/plugins/Ignore.js 1 location

@@ 6-40 (lines=35) @@
3
 * Created by Thomas Schoffelen.
4
 */
5
6
'use strict'
7
8
const minimatch = require('minimatch')
9
const Module = require('../containers/Module')
10
11
const matchFile = function (options, path) {
12
  if (typeof options.paths === 'string') {
13
    options.paths = [options.paths]
14
  }
15
16
  for (var i in options.paths) {
17
    if (!options.paths.hasOwnProperty(i)) {
18
      continue
19
    }
20
    if (minimatch(path, options.paths[i])) {
21
      return true
22
    }
23
  }
24
25
  return false
26
}
27
28
let manifest
29
Module.getManifest(function (manifestObj) {
30
  manifest = manifestObj
31
})
32
33
module.exports = function (path) {
34
  var options = manifest.getDevOption('ignore')
35
  if (!options || !('paths' in options)) {
36
    return false
37
  }
38
39
  return matchFile(options, path)
40
}
41