Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复#1271 #1272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,31 @@ exports.getSourceByPatterns = function(patterns, opts) {

var ret = [];
var source = {};

var unret = [];
var hasIncloud = false;
patterns.forEach(function(pattern, index) {
var exclude = pattern.substring(0, 1) === '!';

if (exclude) {
pattern = pattern.substring(1);

// 如果第一个规则就是排除用法,都没有获取结果就排除,这是不合理的用法。
// 不过为了保证程序的正确性,在排除之前,通过 `**` 先把所有文件获取到。
// 至于性能问题,请用户使用时规避。
(index === 0) && (ret = glob.sync('**', opts));
}
exclude && (pattern = pattern.substring(1));

// glob 列文件规则带 / 表现不对。
pattern[0] === '/' && (pattern = pattern.substring(1));

var mathes = glob.sync(pattern, opts);

ret = _[exclude ? 'difference' : 'union'](ret, mathes);
if (exclude) {
unret = _.union(unret, mathes);
return;
}
hasIncloud = true;
ret = _.union(ret, mathes);
});
// 如果project.files只有过滤文件,没有包含文件则认为包含所有文件
if (!hasIncloud) {
ret = ret.length ? ret : glob.sync('**', opts);
}
// 在包含文件中过滤掉 过滤规则的文件
ret = _.difference(ret, unret);

console.log(ret);
ret.forEach(function(file) {
file = fis.file(opts.cwd, file);
if (file.release && !file.isDir()) {
Expand Down