summaryrefslogtreecommitdiffstats
path: root/lib/fs/node.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-04-22 11:00:21 +0200
committerSamy Pessé <samypesse@gmail.com>2016-04-22 11:00:21 +0200
commit4336fdb2414d460ffee68a0cc87c0cb0c85cf56e (patch)
tree279f711ab98666c892c19a7b9e4073a094f03f98 /lib/fs/node.js
parent87db7cf1d412fa6fbd18e9a7e4f4755f2c0c5547 (diff)
downloadgitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.zip
gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.tar.gz
gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.tar.bz2
Base
Diffstat (limited to 'lib/fs/node.js')
-rw-r--r--lib/fs/node.js68
1 files changed, 21 insertions, 47 deletions
diff --git a/lib/fs/node.js b/lib/fs/node.js
index fc2517e..e05cb65 100644
--- a/lib/fs/node.js
+++ b/lib/fs/node.js
@@ -1,36 +1,15 @@
-var _ = require('lodash');
-var util = require('util');
var path = require('path');
+var Immutable = require('immutable');
var fs = require('../utils/fs');
-var Promise = require('../utils/promise');
-var BaseFS = require('./');
+var FS = require('../models/fs');
-function NodeFS() {
- BaseFS.call(this);
-}
-util.inherits(NodeFS, BaseFS);
-
-// Check if a file exists, run a Promise(true) if that's the case, Promise(false) otherwise
-NodeFS.prototype.exists = function(filename) {
- return fs.exists(filename);
-};
-
-// Read a file and returns a promise with the content as a buffer
-NodeFS.prototype.read = function(filename) {
- return fs.readFile(filename);
-};
-
-// Read stat infos about a file
-NodeFS.prototype.stat = function(filename) {
- return fs.stat(filename);
-};
-
-// List files in a directory
-NodeFS.prototype.readdir = function(folder) {
+function fsReadDir(folder) {
return fs.readdir(folder)
.then(function(files) {
- return _.chain(files)
+ files = Immutable.List(files);
+
+ return files
.map(function(file) {
if (file == '.' || file == '..') return;
@@ -38,29 +17,24 @@ NodeFS.prototype.readdir = function(folder) {
if (stat.isDirectory()) file = file + path.sep;
return file;
})
- .compact()
- .value();
+ .filter(function(file) {
+ return Boolean(file);
+ });
});
-};
-
-// Load a JSON/JS file
-NodeFS.prototype.loadAsObject = function(filename) {
- return Promise()
- .then(function() {
- var jsFile;
+}
- try {
- jsFile = require.resolve(filename);
+function fsLoadObject(filename) {
+ return require(filename);
+}
- // Invalidate node.js cache for livreloading
- delete require.cache[jsFile];
+module.exports = function createNodeFS(root) {
+ return FS.create({
+ root: root,
- return require(jsFile);
- }
- catch(err) {
- return Promise.reject(err);
- }
+ fsExists: fs.exists,
+ fsReadFile: fs.readFile,
+ fsStatFile: fs.stat,
+ fsReadDir: fsReadDir,
+ fsLoadObject: fsLoadObject
});
};
-
-module.exports = NodeFS;