diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-31 19:18:15 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-03-31 19:19:52 -0700 |
commit | 6bcd483351dc0fa45a0a8ad88405b27ff8b118f0 (patch) | |
tree | e41ff924798a4b6a3b0ec2efa3137a1aa1ad7826 | |
parent | 347ae52e677887413b2e68d6e3d4217b92fc88ee (diff) | |
download | gitbook-6bcd483351dc0fa45a0a8ad88405b27ff8b118f0.zip gitbook-6bcd483351dc0fa45a0a8ad88405b27ff8b118f0.tar.gz gitbook-6bcd483351dc0fa45a0a8ad88405b27ff8b118f0.tar.bz2 |
Replace glob with better fstream-ignore
It ignores according to .gitignore and other folders
-rw-r--r-- | lib/generate/index.js | 44 | ||||
-rw-r--r-- | package.json | 2 |
2 files changed, 40 insertions, 6 deletions
diff --git a/lib/generate/index.js b/lib/generate/index.js index a06aa8b..4b81d8f 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -1,11 +1,48 @@ var Q = require("q"); var _ = require("lodash"); + var path = require("path"); -var glob = require("glob"); +var Ignore = require("fstream-ignore"); + var fs = require("./fs"); var parse = require("../parse"); var template = require("./template"); + + +function getFiles(path) { + var d = Q.defer(); + + // Our list of files + var files = []; + + var ig = Ignore({ + path: path, + ignoreFiles: ['.ignore', '.gitignore'] + }); + + // Add extra rules to ignore common folders + ig.addIgnoreRules([ + '.git/' + ], '__custom_stuff'); + + // Push each file to our list + ig.on('child', function (c) { + files.push( + c.path.substr(c.root.path.length + 1) + (c.props.Directory === true ? '/' : '') + ); + }); + + ig.on('end', function() { + d.resolve(files); + }); + + ig.on('error', d.reject); + + return d.promise; +} + + var generate = function(root, output, options) { var files, summary, navigation, tpl; @@ -29,10 +66,7 @@ var generate = function(root, output, options) { // List all files in the repository .then(function() { - return Q.nfcall(glob, "**/*", { - cwd: root, - mark: true - }); + return getFiles(root); }) // Check repository is valid diff --git a/package.json b/package.json index 5ded0aa..1c9d5f7 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "lodash": "2.4.1", "marked": "0.3.2", "swig": "1.3.2", - "glob": "3.2.9", + "fstream-ignore": "0.0.7", "q": "1.0.1", "commander": "2.2.0", "fs-extra": "0.8.1" |