diff --git a/src/fs.js b/src/fs.js index 5a8e223..122ce21 100644 --- a/src/fs.js +++ b/src/fs.js @@ -53,6 +53,7 @@ define(function(require) { var providers = require('src/providers/providers'); var adapters = require('src/adapters/adapters'); + var Shell = require('src/shell'); /* * DirectoryEntry @@ -2473,6 +2474,10 @@ define(function(require) { callback(error); } }; + FileSystem.prototype.Shell = function(options) { + return new Shell(this, options); + }; + return FileSystem; }); diff --git a/src/index.js b/src/index.js index eeebb53..f343bd6 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,8 @@ define(function(require) { return { FileSystem: require('src/fs'), + FileSystemShell: require('src/shell'), Path: require('src/path') - } + }; -}); \ No newline at end of file +}); diff --git a/src/shell.js b/src/shell.js new file mode 100644 index 0000000..48eb925 --- /dev/null +++ b/src/shell.js @@ -0,0 +1,78 @@ +define(function(require) { + + function Shell(fs, options) { + options = options || {}; + + var cwd = options.cwd || '/'; + + Object.defineProperty(this, 'fs', { + get: function() { return fs; }, + enumerable: true + }); + + Object.defineProperty(this, 'cwd', { + get: function() { return cwd; }, + enumerable: true + }); + + // We include `cd` on the this vs. proto so that + // we can access cwd without exposing it externally. + this.cd = function(path) { + + }; + + } + + Shell.prototype.ls = function(path) { + + }; + + Shell.prototype.rm = function(path, options, callback) { + + }; + + Shell.prototype.mv = function(path) { + + }; + + Shell.prototype.cp = function(path) { + + }; + + Shell.prototype.mkdir = function(path) { + + }; + + Shell.prototype.touch = function(path, options, callback) { + var fs = this.fs; + path = Path.resolve(this.cwd, path); + + function createFile(path) { + fs.writeFile(path, '', function(error) { + callback(error); + }); + } + + function updateTimes(path) { + var now = Date.now(); + fs.utimes(path, now, now, function(error) { + callback(error); + }); + } + + fs.stat(path, function(error, stats) { + if(error) { + createFile(path); + } else { + updateTimes(path); + } + }); + }; + + Shell.prototype.ln = function(path) { + + }; + + return Shell; + +});