Completed
Push — master ( f600c2...eab8e1 )
by Thomas
45s
created

Ignore.js ➔ matchFile   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 8
dl 0
loc 16
rs 8.8571
nop 2
1
/*
2
 * Copyright (c) 2018 Includable.
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