Sha256: 84c153481ab46b183946adeafebaa549b9e89715c28e7d3215c6e1e21f4f07dd
Contents?: true
Size: 1.64 KB
Versions: 62
Compression:
Stored size: 1.64 KB
Contents
var path = require('path'); var rimraf = require('../util/rimraf'); var fstreamIgnore = require('fstream-ignore'); var mout = require('mout'); var Q = require('q'); function removeIgnores(dir, meta) { var reader; var applyIgnores; var deferred = Q.defer(); var ignored = []; var nonIgnored = ['bower.json']; // Don't ignore main files nonIgnored = nonIgnored.concat(meta.main || []); nonIgnored = nonIgnored.map(function (file) { return path.join(dir, file); }); reader = fstreamIgnore({ path: dir, type: 'Directory' }); reader.addIgnoreRules(meta.ignore || []); // Monkey patch applyIgnores such that we get hold of all ignored files applyIgnores = reader.applyIgnores; reader.applyIgnores = function (entry) { var ret = applyIgnores.apply(this, arguments); if (!ret) { ignored.push(path.join(dir, entry)); } return ret; }; reader .on('child', function (entry) { nonIgnored.push(entry.path); }) .on('error', deferred.reject) .on('end', function () { var promises; // Ensure that we are not ignoring files that should not be ignored! ignored = mout.array.unique(ignored); ignored = ignored.filter(function (file) { return nonIgnored.indexOf(file) === -1; }); // Delete all the ignored files promises = ignored.map(function (file) { return Q.nfcall(rimraf, file); }); return Q.all(promises) .then(deferred.resolve, deferred.reject); }); return deferred.promise; } module.exports = removeIgnores;
Version data entries
62 entries across 62 versions & 1 rubygems