processPattern.js
4.47 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = processPattern;
var _globby = require('globby');
var _globby2 = _interopRequireDefault(_globby);
var _pLimit = require('p-limit');
var _pLimit2 = _interopRequireDefault(_pLimit);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _minimatch = require('minimatch');
var _minimatch2 = _interopRequireDefault(_minimatch);
var _writeFile = require('./writeFile');
var _writeFile2 = _interopRequireDefault(_writeFile);
var _isObject = require('./utils/isObject');
var _isObject2 = _interopRequireDefault(_isObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function processPattern(globalRef, pattern) {
var info = globalRef.info,
debug = globalRef.debug,
output = globalRef.output,
concurrency = globalRef.concurrency;
var globArgs = Object.assign({
cwd: pattern.context
}, pattern.fromArgs || {});
if (pattern.fromType === 'nonexistent') {
return Promise.resolve();
}
var limit = (0, _pLimit2.default)(concurrency || 100);
info('begin globbing \'' + pattern.glob + '\' with a context of \'' + pattern.context + '\'');
return (0, _globby2.default)(pattern.glob, globArgs).then(function (paths) {
return Promise.all(paths.map(function (from) {
return limit(function () {
var file = {
force: pattern.force,
absoluteFrom: _path2.default.resolve(pattern.context, from)
};
file.relativeFrom = _path2.default.relative(pattern.context, file.absoluteFrom);
if (pattern.flatten) {
file.relativeFrom = _path2.default.basename(file.relativeFrom);
}
debug('found ' + from);
// Check the ignore list
var il = pattern.ignore.length;
while (il--) {
var ignoreGlob = pattern.ignore[il];
var globParams = {
dot: true,
matchBase: true
};
var glob = void 0;
if (typeof ignoreGlob === 'string') {
glob = ignoreGlob;
} else if ((0, _isObject2.default)(ignoreGlob)) {
glob = ignoreGlob.glob || '';
var ignoreGlobParams = Object.assign({}, ignoreGlob);
delete ignoreGlobParams.glob;
// Overwrite minimatch defaults
globParams = Object.assign(globParams, ignoreGlobParams);
} else {
glob = '';
}
debug('testing ' + glob + ' against ' + file.relativeFrom);
if ((0, _minimatch2.default)(file.relativeFrom, glob, globParams)) {
info('ignoring \'' + file.relativeFrom + '\', because it matches the ignore glob \'' + glob + '\'');
return Promise.resolve();
} else {
debug(glob + ' doesn\'t match ' + file.relativeFrom);
}
}
// Change the to path to be relative for webpack
if (pattern.toType === 'dir') {
file.webpackTo = _path2.default.join(pattern.to, file.relativeFrom);
} else if (pattern.toType === 'file') {
file.webpackTo = pattern.to || file.relativeFrom;
} else if (pattern.toType === 'template') {
file.webpackTo = pattern.to;
file.webpackToRegExp = pattern.test;
}
if (_path2.default.isAbsolute(file.webpackTo)) {
if (output === '/') {
throw '[copy-webpack-plugin] Using older versions of webpack-dev-server, devServer.outputPath must be defined to write to absolute paths';
}
file.webpackTo = _path2.default.relative(output, file.webpackTo);
}
// ensure forward slashes
file.webpackTo = file.webpackTo.replace(/\\/g, '/');
info('determined that \'' + from + '\' should write to \'' + file.webpackTo + '\'');
return (0, _writeFile2.default)(globalRef, pattern, file);
});
}));
});
}