Skip to content

Commit

Permalink
Added filterByIgnore method to support .couchappignore
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisekelley committed Mar 27, 2015
1 parent f5141a1 commit 8479889
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions index.js
Expand Up @@ -7,6 +7,36 @@ var glob = require('glob');
var mime = require('mime');
var async = require('async');

// kudos: http://stackoverflow.com/a/646643
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
// kudos: https://github.com/mikeal/node.couchapp.js/blob/fa4e0858630706ca720ec860eb07faf1a8aece97/main.js
// utility function to detect filtered files
var filterByIgnore = function(f, ignoreFilesArr){
var match=false;
ignoreFilesArr.forEach(
function(exp,i,arr){
var trimmedEx = exp.trim()
if (trimmedEx.startsWith('[') || trimmedEx.startsWith(']')) {
} else if (trimmedEx.startsWith('//')) {
} else if (trimmedEx == '') {
} else {
var regexed = trimmedEx.replace(/^"(.+(?="$))"$/, '$1');
if(new RegExp(regexed).test(f))
{
match=true;
console.log("Ignoring file: " + JSON.stringify(f) + " matching ignore rule: '" + trimmedEx + "'");
} else {
//console.log("File passes: " + JSON.stringify(f) + " ignore rule: '" + trimmedEx + "'");
}
}
});
return match;
}

// Recursively transform an object into a JSON compatible representation
// and preserve methods by calling toString() on the function objects.
function objToJson(obj) {
Expand Down Expand Up @@ -68,6 +98,14 @@ function compileDirectory(dir, options, callback) {
return done(null);
}

ignoreFiles = options.ignoreFiles;
var isIgnored = filterByIgnore(filename, ignoreFiles);

if (isIgnored) {
console.log("isIgnored: " + JSON.stringify(filename));
return done(null);
}

var relpath = filename.substr(dir.length).replace(/^\//, '');
var parts = relpath.split('/');
var isAttachment = parts[0] === '_attachments';
Expand Down

0 comments on commit 8479889

Please sign in to comment.