diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-03-31 22:45:45 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-03-31 22:45:45 -0700 |
commit | aefbfaf057da43f57afa1e8a34bdba1ddb2d0a73 (patch) | |
tree | dbc2a1d6e2901c7771e666ca1b1778c9ac48cb11 | |
parent | 0f0128fa493ca6227498b5db529753ab632b2e5a (diff) | |
download | gitbook-aefbfaf057da43f57afa1e8a34bdba1ddb2d0a73.zip gitbook-aefbfaf057da43f57afa1e8a34bdba1ddb2d0a73.tar.gz gitbook-aefbfaf057da43f57afa1e8a34bdba1ddb2d0a73.tar.bz2 |
Move getFiles to fs module
-rw-r--r-- | lib/generate/fs.js | 34 | ||||
-rw-r--r-- | lib/generate/index.js | 37 |
2 files changed, 35 insertions, 36 deletions
diff --git a/lib/generate/fs.js b/lib/generate/fs.js index f7ae772..c43225e 100644 --- a/lib/generate/fs.js +++ b/lib/generate/fs.js @@ -1,8 +1,42 @@ var Q = require("q"); var fs = require("fs"); var fsExtra = require("fs-extra"); +var Ignore = require("fstream-ignore"); + +var getFiles = function(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; +} module.exports = { + list: getFiles, readFile: Q.denodeify(fs.readFile), writeFile: Q.denodeify(fs.writeFile), mkdirp: Q.denodeify(fsExtra.mkdirp), diff --git a/lib/generate/index.js b/lib/generate/index.js index 35ee4f4..b9d3d9b 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -2,47 +2,12 @@ var Q = require("q"); var _ = require("lodash"); var path = require("path"); -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; @@ -66,7 +31,7 @@ var generate = function(root, output, options) { // List all files in the repository .then(function() { - return getFiles(root); + return fs.list(root); }) // Check repository is valid |