forked from rockybars/atom-shell-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignore.js
92 lines (74 loc) · 2.24 KB
/
ignore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict'
const debug = require('debug')('electron-packager')
const path = require('path')
const DEFAULT_IGNORES = [
'/node_modules/electron($|/)',
'/node_modules/electron-prebuilt($|/)',
'/node_modules/electron-packager($|/)',
'/\\.git($|/)',
'/node_modules/\\.bin($|/)',
'\\.o(bj)?$'
]
function generateIgnores (opts) {
if (typeof (opts.ignore) !== 'function') {
if (opts.ignore && !Array.isArray(opts.ignore)) opts.ignore = [opts.ignore]
opts.ignore = (opts.ignore) ? opts.ignore.concat(DEFAULT_IGNORES) : DEFAULT_IGNORES
debug('Ignored path regular expressions:', opts.ignore)
}
}
function generateOutIgnores (opts) {
// Avoid a circular require that breaks things
const common = require('./common')
let normalizedOut = opts.out ? path.resolve(opts.out) : null
let outIgnores = []
if (normalizedOut === null || normalizedOut === process.cwd()) {
for (let platform of common.platforms) {
for (let arch of common.archs) {
let basenameOpts = {
arch: arch,
name: opts.name,
platform: platform
}
outIgnores.push(path.join(process.cwd(), common.generateFinalBasename(basenameOpts)))
}
}
} else {
outIgnores.push(normalizedOut)
}
debug('Ignored paths based on the out param:', outIgnores)
return outIgnores
}
function userIgnoreFilter (opts) {
var ignore = opts.ignore || []
var ignoreFunc = null
if (typeof (ignore) === 'function') {
ignoreFunc = file => { return !ignore(file) }
} else {
if (!Array.isArray(ignore)) ignore = [ignore]
ignoreFunc = function filterByRegexes (file) {
for (var i = 0; i < ignore.length; i++) {
if (file.match(ignore[i])) {
return false
}
}
return true
}
}
let outIgnores = generateOutIgnores(opts)
return function filter (file) {
if (outIgnores.indexOf(file) !== -1) {
return false
}
var name = file.split(path.resolve(opts.dir))[1]
if (path.sep === '\\') {
// convert slashes so unix-format ignores work
name = name.replace(/\\/g, '/')
}
return ignoreFunc(name)
}
}
module.exports = {
generateIgnores: generateIgnores,
generateOutIgnores: generateOutIgnores,
userIgnoreFilter: userIgnoreFilter
}