mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Move getFiles to fs module
This commit is contained in:
@@ -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),
|
||||
|
||||
+1
-36
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user