Deal with all other uses of this.cwd etc and convert to pwd() on current shell instance.
This commit is contained in:
parent
5b785037f0
commit
2114f65f09
|
@ -78,14 +78,15 @@ function Shell(fs, options) {
|
||||||
*/
|
*/
|
||||||
Shell.prototype.exec = function(path, args, callback) {
|
Shell.prototype.exec = function(path, args, callback) {
|
||||||
/* jshint evil:true */
|
/* jshint evil:true */
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof args === 'function') {
|
if(typeof args === 'function') {
|
||||||
callback = args;
|
callback = args;
|
||||||
args = [];
|
args = [];
|
||||||
}
|
}
|
||||||
args = args || [];
|
args = args || [];
|
||||||
callback = callback || function(){};
|
callback = callback || function(){};
|
||||||
path = Path.resolve(this.cwd, path);
|
path = Path.resolve(sh.pwd(), path);
|
||||||
|
|
||||||
fs.readFile(path, "utf8", function(error, data) {
|
fs.readFile(path, "utf8", function(error, data) {
|
||||||
if(error) {
|
if(error) {
|
||||||
|
@ -109,14 +110,15 @@ Shell.prototype.exec = function(path, args, callback) {
|
||||||
* * date - use the provided Date value instead of current date/time
|
* * date - use the provided Date value instead of current date/time
|
||||||
*/
|
*/
|
||||||
Shell.prototype.touch = function(path, options, callback) {
|
Shell.prototype.touch = function(path, options, callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
options = options || {};
|
options = options || {};
|
||||||
callback = callback || function(){};
|
callback = callback || function(){};
|
||||||
path = Path.resolve(this.cwd, path);
|
path = Path.resolve(sh.pwd(), path);
|
||||||
|
|
||||||
function createFile(path) {
|
function createFile(path) {
|
||||||
fs.writeFile(path, '', callback);
|
fs.writeFile(path, '', callback);
|
||||||
|
@ -150,7 +152,8 @@ Shell.prototype.touch = function(path, options, callback) {
|
||||||
* (multiple file paths).
|
* (multiple file paths).
|
||||||
*/
|
*/
|
||||||
Shell.prototype.cat = function(files, callback) {
|
Shell.prototype.cat = function(files, callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
var all = '';
|
var all = '';
|
||||||
callback = callback || function(){};
|
callback = callback || function(){};
|
||||||
|
|
||||||
|
@ -162,7 +165,7 @@ Shell.prototype.cat = function(files, callback) {
|
||||||
files = typeof files === 'string' ? [ files ] : files;
|
files = typeof files === 'string' ? [ files ] : files;
|
||||||
|
|
||||||
function append(item, callback) {
|
function append(item, callback) {
|
||||||
var filename = Path.resolve(this.cwd, item);
|
var filename = Path.resolve(sh.pwd(), item);
|
||||||
fs.readFile(filename, 'utf8', function(error, data) {
|
fs.readFile(filename, 'utf8', function(error, data) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
|
@ -200,7 +203,8 @@ Shell.prototype.cat = function(files, callback) {
|
||||||
* the `recursive=true` option.
|
* the `recursive=true` option.
|
||||||
*/
|
*/
|
||||||
Shell.prototype.ls = function(dir, options, callback) {
|
Shell.prototype.ls = function(dir, options, callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -214,7 +218,7 @@ Shell.prototype.ls = function(dir, options, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function list(path, callback) {
|
function list(path, callback) {
|
||||||
var pathname = Path.resolve(this.cwd, path);
|
var pathname = Path.resolve(sh.pwd(), path);
|
||||||
var result = [];
|
var result = [];
|
||||||
|
|
||||||
fs.readdir(pathname, function(error, entries) {
|
fs.readdir(pathname, function(error, entries) {
|
||||||
|
@ -272,7 +276,8 @@ Shell.prototype.ls = function(dir, options, callback) {
|
||||||
* `recursive=true` option.
|
* `recursive=true` option.
|
||||||
*/
|
*/
|
||||||
Shell.prototype.rm = function(path, options, callback) {
|
Shell.prototype.rm = function(path, options, callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -286,7 +291,7 @@ Shell.prototype.rm = function(path, options, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(pathname, callback) {
|
function remove(pathname, callback) {
|
||||||
pathname = Path.resolve(this.cwd, pathname);
|
pathname = Path.resolve(sh.pwd(), pathname);
|
||||||
fs.stat(pathname, function(error, stats) {
|
fs.stat(pathname, function(error, stats) {
|
||||||
if(error) {
|
if(error) {
|
||||||
callback(error);
|
callback(error);
|
||||||
|
@ -343,8 +348,9 @@ Shell.prototype.rm = function(path, options, callback) {
|
||||||
* env.TMP. The callback receives (error, tempDirName).
|
* env.TMP. The callback receives (error, tempDirName).
|
||||||
*/
|
*/
|
||||||
Shell.prototype.tempDir = function(callback) {
|
Shell.prototype.tempDir = function(callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
var tmp = this.env.get('TMP');
|
var fs = sh.fs;
|
||||||
|
var tmp = sh.env.get('TMP');
|
||||||
callback = callback || function(){};
|
callback = callback || function(){};
|
||||||
|
|
||||||
// Try and create it, and it will either work or fail
|
// Try and create it, and it will either work or fail
|
||||||
|
@ -362,7 +368,8 @@ Shell.prototype.tempDir = function(callback) {
|
||||||
* MIT License
|
* MIT License
|
||||||
*/
|
*/
|
||||||
Shell.prototype.mkdirp = function(path, callback) {
|
Shell.prototype.mkdirp = function(path, callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
callback = callback || function(){};
|
callback = callback || function(){};
|
||||||
|
|
||||||
if(!path) {
|
if(!path) {
|
||||||
|
@ -428,7 +435,8 @@ Shell.prototype.mkdirp = function(path, callback) {
|
||||||
* filename is used instead. The callback receives (error, path).
|
* filename is used instead. The callback receives (error, path).
|
||||||
*/
|
*/
|
||||||
Shell.prototype.wget = function(url, options, callback) {
|
Shell.prototype.wget = function(url, options, callback) {
|
||||||
var fs = this.fs;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -447,7 +455,7 @@ Shell.prototype.wget = function(url, options, callback) {
|
||||||
// i.e. instead of "/foo?bar/" we would expect "/foo?bar%2F"
|
// i.e. instead of "/foo?bar/" we would expect "/foo?bar%2F"
|
||||||
var path = options.filename || url.split('/').pop();
|
var path = options.filename || url.split('/').pop();
|
||||||
|
|
||||||
path = Path.resolve(fs.cwd, path);
|
path = Path.resolve(sh.pwd(), path);
|
||||||
|
|
||||||
function onerror() {
|
function onerror() {
|
||||||
callback(new Error('unable to get resource'));
|
callback(new Error('unable to get resource'));
|
||||||
|
@ -469,8 +477,8 @@ Shell.prototype.wget = function(url, options, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Shell.prototype.unzip = function(zipfile, options, callback) {
|
Shell.prototype.unzip = function(zipfile, options, callback) {
|
||||||
var fs = this.fs;
|
|
||||||
var sh = this;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -483,8 +491,8 @@ Shell.prototype.unzip = function(zipfile, options, callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = Path.resolve(this.cwd, zipfile);
|
var path = Path.resolve(sh.pwd(), zipfile);
|
||||||
var destination = Path.resolve(options.destination || this.cwd);
|
var destination = Path.resolve(options.destination || sh.pwd());
|
||||||
|
|
||||||
fs.readFile(path, function(err, data) {
|
fs.readFile(path, function(err, data) {
|
||||||
if(err) return callback(err);
|
if(err) return callback(err);
|
||||||
|
@ -515,8 +523,8 @@ Shell.prototype.unzip = function(zipfile, options, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Shell.prototype.zip = function(zipfile, paths, options, callback) {
|
Shell.prototype.zip = function(zipfile, paths, options, callback) {
|
||||||
var fs = this.fs;
|
|
||||||
var sh = this;
|
var sh = this;
|
||||||
|
var fs = sh.fs;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -535,7 +543,7 @@ Shell.prototype.zip = function(zipfile, paths, options, callback) {
|
||||||
if(typeof paths === 'string') {
|
if(typeof paths === 'string') {
|
||||||
paths = [ paths ];
|
paths = [ paths ];
|
||||||
}
|
}
|
||||||
zipfile = Path.resolve(this.cwd, zipfile);
|
zipfile = Path.resolve(sh.pwd(), zipfile);
|
||||||
|
|
||||||
function toRelPath(path) {
|
function toRelPath(path) {
|
||||||
// Make path relative within the zip
|
// Make path relative within the zip
|
||||||
|
@ -568,7 +576,7 @@ Shell.prototype.zip = function(zipfile, paths, options, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(path, callback) {
|
function add(path, callback) {
|
||||||
path = Path.resolve(sh.cwd, path);
|
path = Path.resolve(sh.pwd(), path);
|
||||||
fs.stat(path, function(err, stats) {
|
fs.stat(path, function(err, stats) {
|
||||||
if(err) return callback(err);
|
if(err) return callback(err);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue