mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 19:32:07 +00:00
fs.list take option for files to ignores
This commit is contained in:
+25
-1
@@ -549,7 +549,31 @@ Book.prototype.statFile = function(filename) {
|
||||
Book.prototype.listAllFiles = function() {
|
||||
var that = this;
|
||||
|
||||
return fs.list(this.root)
|
||||
return fs.list(this.root, {
|
||||
ignoreFiles: ['.ignore', '.gitignore', '.bookignore'],
|
||||
ignoreRules: [
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
'.gitignore',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'_book',
|
||||
'*.pdf',
|
||||
'*.epub',
|
||||
'*.mobi',
|
||||
|
||||
// Skip config files
|
||||
'.ignore',
|
||||
'.bookignore',
|
||||
'book.json',
|
||||
]
|
||||
})
|
||||
.then(function(_files) {
|
||||
that.files = _files;
|
||||
});
|
||||
|
||||
+12
-25
@@ -1,10 +1,16 @@
|
||||
var _ = require("lodash");
|
||||
var Q = require("q");
|
||||
var tmp = require("tmp");
|
||||
var fs = require("graceful-fs");
|
||||
var fsExtra = require("fs-extra");
|
||||
var Ignore = require("fstream-ignore");
|
||||
|
||||
var getFiles = function(path) {
|
||||
var listFiles = function(path, options) {
|
||||
options = _.defaults(options || {}, {
|
||||
ignoreFiles: [],
|
||||
ignoreRules: []
|
||||
});
|
||||
|
||||
var d = Q.defer();
|
||||
|
||||
// Our list of files
|
||||
@@ -12,32 +18,11 @@ var getFiles = function(path) {
|
||||
|
||||
var ig = Ignore({
|
||||
path: path,
|
||||
ignoreFiles: ['.ignore', '.gitignore', '.bookignore']
|
||||
ignoreFiles: options.ignoreFiles
|
||||
});
|
||||
|
||||
// Add extra rules to ignore common folders
|
||||
ig.addIgnoreRules([
|
||||
// Skip Git stuff
|
||||
'.git/',
|
||||
'.gitignore',
|
||||
|
||||
// Skip OS X meta data
|
||||
'.DS_Store',
|
||||
|
||||
// Skip stuff installed by plugins
|
||||
'node_modules',
|
||||
|
||||
// Skip book outputs
|
||||
'_book',
|
||||
'*.pdf',
|
||||
'*.epub',
|
||||
'*.mobi',
|
||||
|
||||
// Skip config files
|
||||
'.ignore',
|
||||
'.bookignore',
|
||||
'book.json',
|
||||
], '__custom_stuff');
|
||||
ig.addIgnoreRules(options.ignoreRules, '__custom_stuff');
|
||||
|
||||
// Push each file to our list
|
||||
ig.on('child', function (c) {
|
||||
@@ -63,6 +48,8 @@ var getFiles = function(path) {
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
tmp: {
|
||||
file: function() {
|
||||
@@ -72,7 +59,7 @@ module.exports = {
|
||||
return Q.nfcall(tmp.dir.bind(tmp)).get(0)
|
||||
}
|
||||
},
|
||||
list: getFiles,
|
||||
list: listFiles,
|
||||
stat: Q.denodeify(fs.stat),
|
||||
readdir: Q.denodeify(fs.readdir),
|
||||
readFile: Q.denodeify(fs.readFile),
|
||||
|
||||
Reference in New Issue
Block a user