Skip to content

Commit

Permalink
fix #24, unignore special dir or file
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswong committed Nov 20, 2014
1 parent 4b3f967 commit 99580c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
18 changes: 11 additions & 7 deletions cli/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* @author chris<wfsr@foxmail.com>
*/

var fs = require('vinyl-fs');
var fs = require('vinyl-fs');

var util = require('../lib/util');
var ignored = require('../lib/ignored');
var jschecker = require('../lib/js/checker');
var csschecker = require('../lib/css/checker');
var util = require('../lib/util');
var ignored = require('../lib/ignored');
var jschecker = require('../lib/js/checker');
var csschecker = require('../lib/css/checker');
var htmlchecker = require('../lib/html/checker');

/**
* 不同的输入流处理
Expand All @@ -25,11 +26,14 @@ var streams = {
*/
files: function (options) {
var patterns = util.buildPattern(options._, options.type);
var specials = patterns.specials;
delete patterns.specials;

return fs.src(patterns, {cwdbase: true})
.pipe(ignored(options))
.pipe(ignored(options, specials))
.pipe(jschecker(options))
.pipe(csschecker(options));
.pipe(csschecker(options))
.pipe(htmlchecker(options));
},

/**
Expand Down
4 changes: 3 additions & 1 deletion cli/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ var streams = {
*/
files: function (options) {
var patterns = util.buildPattern(options._, options.types);
var specials = patterns.specials;
delete patterns.specials;

return fs.src(patterns, {cwdbase: true})
.pipe(ignored(options))
.pipe(ignored(options, specials))
.pipe(jsformatter(options))
.pipe(cssformatter(options))
.pipe(fs.dest(options.output));
Expand Down
16 changes: 13 additions & 3 deletions lib/ignored.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ function load(filename, options) {
* 根据 .fecsignore 与 --ignore 的规则过滤文件
*
* @param {Object} options 配置项
* @param {Array.<string>} special 直接指定的目录或文件列表
* @return {Transform} 转换流
*/
module.exports = function (options) {
module.exports = function (options, specials) {

var patterns = load(IGNORE_FILENAME, options);

Expand All @@ -57,7 +58,11 @@ module.exports = function (options) {

var filepath = file.relative.replace('\\', '/');

var isIgnore = patterns.reduce(function(ignored, pattern) {
var isSpecial = specials.some(function (dirOrPath) {
return filepath.indexOf(dirOrPath) === 0;
});

var isIgnore = !isSpecial && patterns.reduce(function(ignored, pattern) {
var negated = pattern[0] === '!';
var matches;

Expand All @@ -66,8 +71,13 @@ module.exports = function (options) {
}

matches = minimatch(filepath, pattern) || minimatch(filepath, pattern + '/**');
var result = matches ? !negated : ignored;

if (options.debug && result) {
console.log('%s is ignored by %s.', filepath, pattern);
}

return matches ? !negated : ignored;
return result;
}, false);

cb(null, !isIgnore && file);
Expand Down
6 changes: 6 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ exports.buildPattern = function (dirs, extensions) {
dirs = ['./'];
}

var specials = [];
var transform = function (dir) {
if (fs.existsSync(dir)) {
var stat = fs.statSync(dir);
specials.push(dir);

return stat.isDirectory()
? path.join(dir, '/') + '**/*.' + extensions
: dir;
Expand All @@ -39,6 +42,9 @@ exports.buildPattern = function (dirs, extensions) {
var patterns = dirs.map(transform).filter(Boolean);
patterns.push('!**/{node_modules,bower_components}/**');

// HACK: CLI 中直接指定的文件或目录,可以不被 .fecsignore 忽略
patterns.specials = specials;

return patterns;
};

Expand Down

0 comments on commit 99580c1

Please sign in to comment.