Total Complexity | 10 |
Complexity/F | 3.33 |
Lines of Code | 47 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 | module.exports = function (containerToken, path, event) { |
||
21 | Module.getManifest(function (manifest) { |
||
22 | var options = manifest.getDevOption('autoreload') |
||
23 | if (!options || !('paths' in options)) { |
||
24 | return |
||
25 | } |
||
26 | if (typeof options.paths === 'string') { |
||
27 | options.paths = [options.paths] |
||
28 | } |
||
29 | |||
30 | var matched = false |
||
31 | for (var i in options.paths) { |
||
32 | if (!options.paths.hasOwnProperty(i)) { |
||
33 | continue |
||
34 | } |
||
35 | if (minimatch(path, options.paths[i])) { |
||
36 | matched = true |
||
37 | break |
||
38 | } |
||
39 | } |
||
40 | |||
41 | if (!matched) { |
||
42 | return |
||
43 | } |
||
44 | |||
45 | reload(containerToken, path, event) |
||
46 | }) |
||
47 | } |
||
48 |