Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "shelljs", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Artur Adib <aadib@mozilla.com>", | ||
@@ -5,0 +5,0 @@ "description": "Portable Unix shell commands for Node.js", |
100
README.md
@@ -184,3 +184,3 @@ # ShellJS - Unix shell commands for Node.js [![Build Status](https://secure.travis-ci.org/arturadib/shelljs.png)](http://travis-ci.org/arturadib/shelljs) | ||
The main difference from `ls('-R', path)` is that the resulting file names | ||
The main difference from `ls('-R', path)` is that the resulting file names | ||
include the base directories, e.g. `lib/resources/file1` instead of just `file1`. | ||
@@ -220,3 +220,3 @@ | ||
Removes files. The wildcard `*` is accepted. | ||
Removes files. The wildcard `*` is accepted. | ||
@@ -329,3 +329,3 @@ ### mv(source [, source ...], dest') | ||
Reads input string from given files and returns a string containing all lines of the | ||
Reads input string from given files and returns a string containing all lines of the | ||
file that match the given `regex_filter`. Wildcard `*` accepted. | ||
@@ -356,2 +356,62 @@ | ||
### dirs([options | '+N' | '-N']) | ||
Available options: | ||
+ `-c`: Clears the directory stack by deleting all of the elements. | ||
Arguments: | ||
+ `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero. | ||
+ `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero. | ||
Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified. | ||
See also: pushd, popd | ||
### pushd([options,] [dir | '-N' | '+N']) | ||
Available options: | ||
+ `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated. | ||
Arguments: | ||
+ `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`. | ||
+ `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. | ||
+ `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. | ||
Examples: | ||
```javascript | ||
// process.cwd() === '/usr' | ||
pushd('/etc'); // Returns /etc /usr | ||
pushd('+1'); // Returns /usr /etc | ||
``` | ||
Save the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. | ||
### popd([options,] ['-N' | '+N']) | ||
Available options: | ||
+ `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated. | ||
Arguments: | ||
+ `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero. | ||
+ `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero. | ||
Examples: | ||
```javascript | ||
echo(process.cwd()); // '/usr' | ||
pushd('/etc'); // '/etc /usr' | ||
echo(process.cwd()); // '/etc' | ||
popd(); // '/usr' | ||
echo(process.cwd()); // '/usr' | ||
``` | ||
When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. | ||
### exit(code) | ||
@@ -375,4 +435,4 @@ Exits the current process with the given exit code. | ||
var child = exec('some_long_running_process', {async:true}); | ||
child.stdout.on('data', function(data) { | ||
/* ... do something with data ... */ | ||
child.stdout.on('data', function(data) { | ||
/* ... do something with data ... */ | ||
}); | ||
@@ -386,4 +446,4 @@ | ||
Executes the given `command` _synchronously_, unless otherwise specified. | ||
When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's | ||
Executes the given `command` _synchronously_, unless otherwise specified. | ||
When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's | ||
`output` (stdout + stderr) and its exit `code`. Otherwise returns the child process object, and | ||
@@ -396,2 +456,28 @@ the `callback` gets the arguments `(code, output)`. | ||
### chmod(octal_mode || octal_string, file) | ||
### chmod(symbolic_mode, file) | ||
Available options: | ||
+ `-v`: output a diagnostic for every file processed | ||
+ `-c`: like verbose but report only when a change is made | ||
+ `-R`: change files and directories recursively | ||
Examples: | ||
```javascript | ||
chmod(755, '/Users/brandon'); | ||
chmod('755', '/Users/brandon'); // same as above | ||
chmod('u+x', '/Users/brandon'); | ||
``` | ||
Alters the permissions of a file or directory by either specifying the | ||
absolute permissions in octal form or expressing the changes in symbols. | ||
This command tries to mimic the POSIX behavior as much as possible. | ||
Notable exceptions: | ||
+ In symbolic modes, 'a-r' and '-r' are identical. No consideration is | ||
given to the umask. | ||
+ There is no "quiet" option since default behavior is to run silent. | ||
## Configuration | ||
@@ -398,0 +484,0 @@ |
214
shell.js
@@ -892,5 +892,7 @@ // | ||
//@ Available options: | ||
//@ | ||
//@ + `-c`: Clears the directory stack by deleting all of the elements. | ||
//@ | ||
//@ Arguments: | ||
//@ | ||
//@ + `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero. | ||
@@ -939,5 +941,7 @@ //@ + `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero. | ||
//@ Available options: | ||
//@ | ||
//@ + `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated. | ||
//@ | ||
//@ Arguments | ||
//@ Arguments: | ||
//@ | ||
//@ + `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`. | ||
@@ -948,2 +952,3 @@ //@ + `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. | ||
//@ Examples: | ||
//@ | ||
//@ ```javascript | ||
@@ -1003,5 +1008,7 @@ //@ // process.cwd() === '/usr' | ||
//@ Available options: | ||
//@ | ||
//@ + `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated. | ||
//@ | ||
//@ Arguments: | ||
//@ | ||
//@ + `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero. | ||
@@ -1011,2 +1018,3 @@ //@ + `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero. | ||
//@ Examples: | ||
//@ | ||
//@ ```javascript | ||
@@ -1111,6 +1119,210 @@ //@ echo(process.cwd()); // '/usr' | ||
var PERMS = (function (base) { | ||
return { | ||
OTHER_EXEC : base.EXEC, | ||
OTHER_WRITE : base.WRITE, | ||
OTHER_READ : base.READ, | ||
GROUP_EXEC : base.EXEC << 3, | ||
GROUP_WRITE : base.WRITE << 3, | ||
GROUP_READ : base.READ << 3, | ||
OWNER_EXEC : base.EXEC << 6, | ||
OWNER_WRITE : base.WRITE << 6, | ||
OWNER_READ : base.READ << 6, | ||
// Literal octal numbers are apparently not allowed in "strict" javascript. Using parseInt is | ||
// the preferred way, else a jshint warning is thrown. | ||
STICKY : parseInt('01000', 8), | ||
SETGID : parseInt('02000', 8), | ||
SETUID : parseInt('04000', 8), | ||
TYPE_MASK : parseInt('0770000', 8) | ||
}; | ||
})({ | ||
EXEC : 1, | ||
WRITE : 2, | ||
READ : 4 | ||
}); | ||
//@ | ||
//@ ### chmod(octal_mode || octal_string, file) | ||
//@ ### chmod(symbolic_mode, file) | ||
//@ | ||
//@ Available options: | ||
//@ | ||
//@ + `-v`: output a diagnostic for every file processed//@ | ||
//@ + `-c`: like verbose but report only when a change is made//@ | ||
//@ + `-R`: change files and directories recursively//@ | ||
//@ | ||
//@ Examples: | ||
//@ | ||
//@ ```javascript | ||
//@ chmod(755, '/Users/brandon'); | ||
//@ chmod('755', '/Users/brandon'); // same as above | ||
//@ chmod('u+x', '/Users/brandon'); | ||
//@ ``` | ||
//@ | ||
//@ Alters the permissions of a file or directory by either specifying the | ||
//@ absolute permissions in octal form or expressing the changes in symbols. | ||
//@ This command tries to mimic the POSIX behavior as much as possible. | ||
//@ Notable exceptions: | ||
//@ | ||
//@ + In symbolic modes, 'a-r' and '-r' are identical. No consideration is | ||
//@ given to the umask. | ||
//@ + There is no "quiet" option since default behavior is to run silent. | ||
function _chmod(options, mode, filePattern) { | ||
if (!filePattern) { | ||
if (options.length > 0 && options.charAt(0) === '-') { | ||
// Special case where the specified file permissions started with - to subtract perms, which | ||
// get picked up by the option parser as command flags. | ||
// If we are down by one argument and options starts with -, shift everything over. | ||
filePattern = mode; | ||
mode = options; | ||
options = ''; | ||
} | ||
else { | ||
error('You must specify a file.'); | ||
} | ||
} | ||
options = parseOptions(options, { | ||
'R': 'recursive', | ||
'c': 'changes', | ||
'v': 'verbose' | ||
}); | ||
if (typeof filePattern === 'string') { | ||
filePattern = [ filePattern ]; | ||
} | ||
var files; | ||
if (options.recursive) { | ||
files = []; | ||
expand(filePattern).forEach(function addFile(expandedFile) { | ||
var stat = fs.lstatSync(expandedFile); | ||
if (!stat.isSymbolicLink()) { | ||
files.push(expandedFile); | ||
if (stat.isDirectory()) { // intentionally does not follow symlinks. | ||
fs.readdirSync(expandedFile).forEach(function (child) { | ||
addFile(expandedFile + '/' + child); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
else { | ||
files = expand(filePattern); | ||
} | ||
files.forEach(function innerChmod(file) { | ||
file = path.resolve(file); | ||
if (!fs.existsSync(file)) { | ||
error('File not found: ' + file); | ||
} | ||
// When recursing, don't follow symlinks. | ||
if (options.recursive && fs.lstatSync(file).isSymbolicLink()) { | ||
return; | ||
} | ||
var perms = fs.statSync(file).mode; | ||
var type = perms & PERMS.TYPE_MASK; | ||
var newPerms = perms; | ||
if (isNaN(parseInt(mode, 8))) { | ||
// parse options | ||
mode.split(',').forEach(function (symbolicMode) { | ||
/*jshint regexdash:true */ | ||
var pattern = /([ugoa]*)([=\+-])([rwxXst]*)/i; | ||
var matches = pattern.exec(symbolicMode); | ||
if (matches) { | ||
var applyTo = matches[1]; | ||
var operator = matches[2]; | ||
var change = matches[3]; | ||
var changeOwner = applyTo.indexOf('u') != -1 || applyTo === 'a' || applyTo === ''; | ||
var changeGroup = applyTo.indexOf('g') != -1 || applyTo === 'a' || applyTo === ''; | ||
var changeOther = applyTo.indexOf('o') != -1 || applyTo === 'a' || applyTo === ''; | ||
var changeRead = change.indexOf('r') != -1; | ||
var changeWrite = change.indexOf('w') != -1; | ||
var changeExec = change.indexOf('x') != -1; | ||
var changeSticky = change.indexOf('t') != -1; | ||
var changeSetuid = change.indexOf('s') != -1; | ||
var mask = 0; | ||
if (changeOwner) { | ||
mask |= (changeRead ? PERMS.OWNER_READ : 0) + (changeWrite ? PERMS.OWNER_WRITE : 0) + (changeExec ? PERMS.OWNER_EXEC : 0) + (changeSetuid ? PERMS.SETUID : 0); | ||
} | ||
if (changeGroup) { | ||
mask |= (changeRead ? PERMS.GROUP_READ : 0) + (changeWrite ? PERMS.GROUP_WRITE : 0) + (changeExec ? PERMS.GROUP_EXEC : 0) + (changeSetuid ? PERMS.SETGID : 0); | ||
} | ||
if (changeOther) { | ||
mask |= (changeRead ? PERMS.OTHER_READ : 0) + (changeWrite ? PERMS.OTHER_WRITE : 0) + (changeExec ? PERMS.OTHER_EXEC : 0); | ||
} | ||
// Sticky bit is special - it's not tied to user, group or other. | ||
if (changeSticky) { | ||
mask |= PERMS.STICKY; | ||
} | ||
switch (operator) { | ||
case '+': | ||
newPerms |= mask; | ||
break; | ||
case '-': | ||
newPerms &= ~mask; | ||
break; | ||
case '=': | ||
newPerms = type + mask; | ||
// According to POSIX, when using = to explicitly set the permissions, setuid and setgid can never be cleared. | ||
if (fs.statSync(file).isDirectory()) { | ||
newPerms |= (PERMS.SETUID + PERMS.SETGID) & perms; | ||
} | ||
break; | ||
} | ||
if (options.verbose) { | ||
log(file + ' -> ' + newPerms.toString(8)); | ||
} | ||
if (perms != newPerms) { | ||
if (!options.verbose && options.changes) { | ||
log(file + ' -> ' + newPerms.toString(8)); | ||
} | ||
fs.chmodSync(file, newPerms); | ||
} | ||
} | ||
else { | ||
error('Invalid symbolic mode change: ' + symbolicMode); | ||
} | ||
}); | ||
} | ||
else { | ||
// they gave us a full number | ||
newPerms = type + parseInt(mode, 8); | ||
// POSIX rules are that setuid and setgid can only be added using numeric form, but not cleared. | ||
if (fs.statSync(file).isDirectory()) { | ||
newPerms |= (PERMS.SETUID + PERMS.SETGID) & perms; | ||
} | ||
fs.chmodSync(file, newPerms); | ||
} | ||
}); | ||
} | ||
exports.chmod = wrap('chmod', _chmod); | ||
//@ | ||
//@ ## Configuration | ||
@@ -1117,0 +1329,0 @@ //@ |
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
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
128185
73
3253
513
34