Comparing version 0.0.5-pre1 to 0.0.5-pre2
{ "name": "shelljs" | ||
, "version": "0.0.5pre1" | ||
, "version": "0.0.5pre2" | ||
, "author": "Artur Adib <aadib@mozilla.com>" | ||
@@ -4,0 +4,0 @@ , "description": "Portable Unix shell commands for Node.js" |
62
shell.js
@@ -93,3 +93,3 @@ // | ||
// Conditionally pushes file to list | ||
// Conditionally pushes file to list - returns true if pushed, false otherwise | ||
// (e.g. prevents hidden files to be included unless explicitly told so) | ||
@@ -101,6 +101,10 @@ function pushFile(file, query) { | ||
if (!options.all && !(path.basename(query)[0] === '.' && path.basename(query).length > 1)) | ||
return; | ||
return false; | ||
} | ||
if (platform === 'win') | ||
file = file.replace(/\\/g, '/'); | ||
list.push(file); | ||
return true; | ||
} | ||
@@ -120,10 +124,13 @@ | ||
fs.readdirSync(p).forEach(function(file) { | ||
pushFile(file, p); | ||
if (!pushFile(file, p)) | ||
return; | ||
// Recursive | ||
var oldDir = _pwd(); | ||
_cd('', p); | ||
if (fs.statSync(file).isDirectory() && options.recursive) | ||
list = list.concat(_ls('-R', file+'/*')); | ||
_cd('', oldDir); | ||
// Recursive? | ||
if (options.recursive) { | ||
var oldDir = _pwd(); | ||
_cd('', p); | ||
if (fs.statSync(file).isDirectory()) | ||
list = list.concat(_ls('-R'+(options.all?'a':''), file+'/*')); | ||
_cd('', oldDir); | ||
} | ||
}); | ||
@@ -147,9 +154,12 @@ return; // continue | ||
if (file.match(new RegExp(regexp))) { | ||
pushFile(path.normalize(dirname+'/'+file), basename); | ||
if (!pushFile(path.normalize(dirname+'/'+file), basename)) | ||
return; | ||
// Recursive | ||
var pp = dirname + '/' + file; | ||
if (fs.statSync(pp).isDirectory() && options.recursive) | ||
list = list.concat(_ls('-R', pp+'/*')); | ||
} | ||
// Recursive? | ||
if (options.recursive) { | ||
var pp = dirname + '/' + file; | ||
if (fs.statSync(pp).isDirectory()) | ||
list = list.concat(_ls('-R'+(options.all?'a':''), pp+'/*')); | ||
} // recursive | ||
} // if file matches | ||
}); // forEach | ||
@@ -192,11 +202,17 @@ return; | ||
function pushFile(file) { | ||
if (platform === 'win') | ||
file = file.replace(/\\/g, '/'); | ||
list.push(file); | ||
} | ||
// why not simply do ls('-R', paths)? because the output wouldn't give the base dirs | ||
// to get the base dir in the output, we need instead ls('-R', 'dir/*') for every directory | ||
paths.forEach(function(file){ | ||
list.push(file); | ||
paths.forEach(function(file) { | ||
pushFile(file); | ||
if (fs.statSync(file).isDirectory()) { | ||
_ls('-Ra', file+'/*').forEach(function(subfile) { | ||
list.push(subfile); | ||
pushFile(subfile); | ||
}); | ||
@@ -596,3 +612,7 @@ } | ||
fs.writeFileSync(file, this.toString(), 'utf8'); | ||
try { | ||
fs.writeFileSync(file, this.toString(), 'utf8'); | ||
} catch(e) { | ||
error('could not write to file (code '+e.code+'): '+file, true); | ||
} | ||
}; | ||
@@ -1120,3 +1140,3 @@ // In the future, when Proxies are default, we can add methods like `.to()` to primitive strings. | ||
if(currFile.isDirectory()) { // Recursive function back to the beginning | ||
rmdirSyncRecursive(file); | ||
rmdirSyncRecursive(file, force); | ||
} | ||
@@ -1136,4 +1156,4 @@ | ||
// Huzzah for the shopkeep. | ||
var result; | ||
try { | ||
@@ -1140,0 +1160,0 @@ result = fs.rmdirSync(dir); |
@@ -40,3 +40,3 @@ var shell = require('..'); | ||
assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true); | ||
assert.equal(Object.keys(result).length, 10); | ||
assert.equal(result.length, 10); | ||
@@ -48,3 +48,3 @@ // multiple paths - comma | ||
assert.equal(result.indexOf('resources/find/dir2/a_dir1') > -1, true); | ||
assert.equal(Object.keys(result).length, 6); | ||
assert.equal(result.length, 6); | ||
@@ -56,4 +56,4 @@ // multiple paths - array | ||
assert.equal(result.indexOf('resources/find/dir2/a_dir1') > -1, true); | ||
assert.equal(Object.keys(result).length, 6); | ||
assert.equal(result.length, 6); | ||
shell.exit(123); |
@@ -26,3 +26,3 @@ var shell = require('..'); | ||
assert.ok(shell.error()); | ||
assert.equal(Object.keys(result).length, 0); | ||
assert.equal(result.length, 0); | ||
@@ -49,3 +49,3 @@ // | ||
assert.equal(result.indexOf('a_dir') > -1, true); | ||
assert.equal(Object.keys(result).length, 6); | ||
assert.equal(result.length, 6); | ||
shell.cd('../..'); | ||
@@ -62,3 +62,3 @@ | ||
assert.equal(result.indexOf('a_dir') > -1, true); | ||
assert.equal(Object.keys(result).length, 6); | ||
assert.equal(result.length, 6); | ||
@@ -77,3 +77,3 @@ // no args, 'all' option | ||
assert.equal(result.indexOf('.hidden_dir') > -1, true); | ||
assert.equal(Object.keys(result).length, 8); | ||
assert.equal(result.length, 8); | ||
shell.cd('../..'); | ||
@@ -90,3 +90,3 @@ | ||
assert.equal(result.indexOf('resources/ls/a_dir') > -1, true); | ||
assert.equal(Object.keys(result).length, 6); | ||
assert.equal(result.length, 6); | ||
@@ -98,3 +98,3 @@ // wildcard, hidden only | ||
assert.equal(result.indexOf('resources/ls/.hidden_dir') > -1, true); | ||
assert.equal(Object.keys(result).length, 2); | ||
assert.equal(result.length, 2); | ||
@@ -104,3 +104,3 @@ // wildcard, mid-file | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 5); | ||
assert.equal(result.length, 5); | ||
assert.equal(result.indexOf('resources/ls/file1') > -1, true); | ||
@@ -115,3 +115,3 @@ assert.equal(result.indexOf('resources/ls/file2') > -1, true); | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 2); | ||
assert.equal(result.length, 2); | ||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); | ||
@@ -123,3 +123,3 @@ assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 0); | ||
assert.equal(result.length, 0); | ||
@@ -129,3 +129,3 @@ // wildcard, all files with extension | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 3); | ||
assert.equal(result.length, 3); | ||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); | ||
@@ -138,3 +138,3 @@ assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 4); | ||
assert.equal(result.length, 4); | ||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); | ||
@@ -148,3 +148,3 @@ assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 4); | ||
assert.equal(result.length, 4); | ||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); | ||
@@ -158,3 +158,3 @@ assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); | ||
assert.equal(shell.error(), null); | ||
assert.equal(Object.keys(result).length, 4); | ||
assert.equal(result.length, 4); | ||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); | ||
@@ -172,3 +172,3 @@ assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); | ||
assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true); | ||
assert.equal(Object.keys(result).length, 10); | ||
assert.equal(result.length, 9); | ||
shell.cd('../..'); | ||
@@ -182,4 +182,13 @@ | ||
assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true); | ||
assert.equal(Object.keys(result).length, 10); | ||
assert.equal(result.length, 9); | ||
// recusive, path given - 'all' flag | ||
var result = shell.ls('-Ra', 'resources/ls'); | ||
assert.equal(shell.error(), null); | ||
assert.equal(result.indexOf('a_dir') > -1, true); | ||
assert.equal(result.indexOf('a_dir/b_dir') > -1, true); | ||
assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true); | ||
assert.equal(result.indexOf('a_dir/.hidden_dir/nada') > -1, true); | ||
assert.equal(result.length, 14); | ||
// recursive, wildcard | ||
@@ -191,4 +200,4 @@ var result = shell.ls('-R', 'resources/ls/*'); | ||
assert.equal(result.indexOf('resources/ls/a_dir/b_dir/z') > -1, true); | ||
assert.equal(Object.keys(result).length, 10); | ||
assert.equal(result.length, 9); | ||
shell.exit(123); |
@@ -139,2 +139,28 @@ var shell = require('..'); | ||
// removal of a sub-tree containing read-only and hidden files - rm('dir/*') | ||
shell.mkdir('-p', 'tmp/tree3'); | ||
shell.mkdir('-p', 'tmp/tree3/subtree'); | ||
shell.mkdir('-p', 'tmp/tree3/.hidden'); | ||
'asdf'.to('tmp/tree3/subtree/file'); | ||
'asdf'.to('tmp/tree3/.hidden/file'); | ||
'asdf'.to('tmp/tree3/file'); | ||
fs.chmodSync('tmp/tree3/file', '0444'); // -r--r--r-- | ||
fs.chmodSync('tmp/tree3/subtree/file', '0444'); // -r--r--r-- | ||
fs.chmodSync('tmp/tree3/.hidden/file', '0444'); // -r--r--r-- | ||
shell.rm('-rf', 'tmp/tree3/*', 'tmp/tree3/.*'); // erase dir contents | ||
assert.equal(shell.ls('tmp/tree3').length, 0); | ||
// removal of a sub-tree containing read-only and hidden files - rm('dir') | ||
shell.mkdir('-p', 'tmp/tree4'); | ||
shell.mkdir('-p', 'tmp/tree4/subtree'); | ||
shell.mkdir('-p', 'tmp/tree4/.hidden'); | ||
'asdf'.to('tmp/tree4/subtree/file'); | ||
'asdf'.to('tmp/tree4/.hidden/file'); | ||
'asdf'.to('tmp/tree4/file'); | ||
fs.chmodSync('tmp/tree4/file', '0444'); // -r--r--r-- | ||
fs.chmodSync('tmp/tree4/subtree/file', '0444'); // -r--r--r-- | ||
fs.chmodSync('tmp/tree4/.hidden/file', '0444'); // -r--r--r-- | ||
shell.rm('-rf', 'tmp/tree4'); // erase dir contents | ||
assert.equal(fs.existsSync('tmp/tree4'), false); | ||
shell.exit(123); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
87173
58
2265