Move getFiles to fs module

This commit is contained in:
Samy Pessé
2014-03-31 22:45:45 -07:00
parent 0f0128fa49
commit aefbfaf057
2 changed files with 35 additions and 36 deletions
+34
View File
@@ -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
View File
@@ -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