initial
This commit is contained in:
12
node_modules/shelljs/.npmignore
generated
vendored
Normal file
12
node_modules/shelljs/.npmignore
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
test/
|
||||
tmp/
|
||||
.github/
|
||||
.documentup.json
|
||||
.gitignore
|
||||
.jshintrc
|
||||
.lgtm
|
||||
.travis.yml
|
||||
.gitattributes
|
||||
appveyor.yml
|
||||
RELEASE.md
|
||||
CONTRIBUTING.md
|
26
node_modules/shelljs/LICENSE
generated
vendored
Normal file
26
node_modules/shelljs/LICENSE
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
Copyright (c) 2012, Artur Adib <arturadib@gmail.com>
|
||||
All rights reserved.
|
||||
|
||||
You may use this project under the terms of the New BSD license as follows:
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Artur Adib nor the
|
||||
names of the contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
3
node_modules/shelljs/MAINTAINERS
generated
vendored
Normal file
3
node_modules/shelljs/MAINTAINERS
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
Ari Porad <ari@ariporad.com> (@ariporad)
|
||||
Nate Fischer <ntfschr@gmail.com> (@nfischer)
|
||||
Artur Adib <arturadib@gmail.com> (@arturadib)
|
744
node_modules/shelljs/README.md
generated
vendored
Normal file
744
node_modules/shelljs/README.md
generated
vendored
Normal file
@ -0,0 +1,744 @@
|
||||
# ShellJS - Unix shell commands for Node.js
|
||||
|
||||
[](https://gitter.im/shelljs/shelljs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](http://travis-ci.org/shelljs/shelljs)
|
||||
[](https://ci.appveyor.com/project/shelljs/shelljs)
|
||||
|
||||
ShellJS is a portable **(Windows/Linux/OS X)** implementation of Unix shell commands on top of the
|
||||
Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping
|
||||
its familiar and powerful commands. You can also install it globally so you can run it from outside
|
||||
Node projects - say goodbye to those gnarly Bash scripts!
|
||||
|
||||
ShellJS supports node `v0.11`, `v0.12`, `v4`, `v5`, and all releases of iojs.
|
||||
|
||||
The project is [unit-tested](http://travis-ci.org/shelljs/shelljs) and battled-tested in projects like:
|
||||
|
||||
+ [PDF.js](http://github.com/mozilla/pdf.js) - Firefox's next-gen PDF reader
|
||||
+ [Firebug](http://getfirebug.com/) - Firefox's infamous debugger
|
||||
+ [JSHint](http://jshint.com) - Most popular JavaScript linter
|
||||
+ [Zepto](http://zeptojs.com) - jQuery-compatible JavaScript library for modern browsers
|
||||
+ [Yeoman](http://yeoman.io/) - Web application stack and development tool
|
||||
+ [Deployd.com](http://deployd.com) - Open source PaaS for quick API backend generation
|
||||
+ And [many more](https://npmjs.org/browse/depended/shelljs).
|
||||
|
||||
If you have feedback, suggestions, or need help, feel free to post in our [issue tracker](https://github.com/shelljs/shelljs/issues).
|
||||
|
||||
Think ShellJS is cool? Check out some related projects (like
|
||||
[cash](https://github.com/dthree/cash)--a javascript-based POSIX shell)
|
||||
in our [Wiki page](https://github.com/shelljs/shelljs/wiki)!
|
||||
|
||||
Upgrading from an older version? Check out our [breaking
|
||||
changes](https://github.com/shelljs/shelljs/wiki/Breaking-Changes) page to see
|
||||
what changes to watch out for while upgrading.
|
||||
|
||||
## Command line use
|
||||
|
||||
If you just want cross platform UNIX commands, checkout our new project
|
||||
[shelljs/shx](https://github.com/shelljs/shx), a utility to expose `shelljs` to
|
||||
the command line.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
$ shx mkdir -p foo
|
||||
$ shx touch foo/bar.txt
|
||||
$ shx rm -rf foo
|
||||
```
|
||||
|
||||
## Installing
|
||||
|
||||
Via npm:
|
||||
|
||||
```bash
|
||||
$ npm install [-g] shelljs
|
||||
```
|
||||
|
||||
If the global option `-g` is specified, the binary `shjs` will be installed. This makes it possible to
|
||||
run ShellJS scripts much like any shell script from the command line, i.e. without requiring a `node_modules` folder:
|
||||
|
||||
```bash
|
||||
$ shjs my_script
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### JavaScript
|
||||
|
||||
```javascript
|
||||
require('shelljs/global');
|
||||
|
||||
if (!which('git')) {
|
||||
echo('Sorry, this script requires git');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Copy files to release dir
|
||||
rm('-rf', 'out/Release');
|
||||
cp('-R', 'stuff/', 'out/Release');
|
||||
|
||||
// Replace macros in each .js file
|
||||
cd('lib');
|
||||
ls('*.js').forEach(function(file) {
|
||||
sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
|
||||
sed('-i', /^.*REMOVE_THIS_LINE.*$/, '', file);
|
||||
sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file);
|
||||
});
|
||||
cd('..');
|
||||
|
||||
// Run external tool synchronously
|
||||
if (exec('git commit -am "Auto-commit"').code !== 0) {
|
||||
echo('Error: Git commit failed');
|
||||
exit(1);
|
||||
}
|
||||
```
|
||||
|
||||
### CoffeeScript
|
||||
|
||||
CoffeeScript is also supported automatically:
|
||||
|
||||
```coffeescript
|
||||
require 'shelljs/global'
|
||||
|
||||
if not which 'git'
|
||||
echo 'Sorry, this script requires git'
|
||||
exit 1
|
||||
|
||||
# Copy files to release dir
|
||||
rm '-rf', 'out/Release'
|
||||
cp '-R', 'stuff/', 'out/Release'
|
||||
|
||||
# Replace macros in each .js file
|
||||
cd 'lib'
|
||||
for file in ls '*.js'
|
||||
sed '-i', 'BUILD_VERSION', 'v0.1.2', file
|
||||
sed '-i', /^.*REMOVE_THIS_LINE.*$/, '', file
|
||||
sed '-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file
|
||||
cd '..'
|
||||
|
||||
# Run external tool synchronously
|
||||
if (exec 'git commit -am "Auto-commit"').code != 0
|
||||
echo 'Error: Git commit failed'
|
||||
exit 1
|
||||
```
|
||||
|
||||
## Global vs. Local
|
||||
|
||||
The example above uses the convenience script `shelljs/global` to reduce verbosity. If polluting your global namespace is not desirable, simply require `shelljs`.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var shell = require('shelljs');
|
||||
shell.echo('hello world');
|
||||
```
|
||||
|
||||
<!-- DO NOT MODIFY BEYOND THIS POINT - IT'S AUTOMATICALLY GENERATED -->
|
||||
|
||||
|
||||
## Command reference
|
||||
|
||||
|
||||
All commands run synchronously, unless otherwise stated.
|
||||
All commands accept standard bash globbing characters (`*`, `?`, etc.),
|
||||
compatible with the [node glob module](https://github.com/isaacs/node-glob).
|
||||
|
||||
For less-commonly used commands and features, please check out our [wiki
|
||||
page](https://github.com/shelljs/shelljs/wiki).
|
||||
|
||||
|
||||
### cd([dir])
|
||||
Changes to directory `dir` for the duration of the script. Changes to home
|
||||
directory if no argument is supplied.
|
||||
|
||||
|
||||
### pwd()
|
||||
Returns the current directory.
|
||||
|
||||
|
||||
### ls([options,] [path, ...])
|
||||
### ls([options,] path_array)
|
||||
Available options:
|
||||
|
||||
+ `-R`: recursive
|
||||
+ `-A`: all files (include files beginning with `.`, except for `.` and `..`)
|
||||
+ `-d`: list directories themselves, not their contents
|
||||
+ `-l`: list objects representing each file, each with fields containing `ls
|
||||
-l` output fields. See
|
||||
[fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
for more info
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
ls('projs/*.js');
|
||||
ls('-R', '/users/me', '/tmp');
|
||||
ls('-R', ['/users/me', '/tmp']); // same as above
|
||||
ls('-l', 'file.txt'); // { name: 'file.txt', mode: 33188, nlink: 1, ...}
|
||||
```
|
||||
|
||||
Returns array of files in the given path, or in current directory if no path provided.
|
||||
|
||||
|
||||
### find(path [, path ...])
|
||||
### find(path_array)
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
find('src', 'lib');
|
||||
find(['src', 'lib']); // same as above
|
||||
find('.').filter(function(file) { return file.match(/\.js$/); });
|
||||
```
|
||||
|
||||
Returns array of all files (however deep) in the given paths.
|
||||
|
||||
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`.
|
||||
|
||||
|
||||
### cp([options,] source [, source ...], dest)
|
||||
### cp([options,] source_array, dest)
|
||||
Available options:
|
||||
|
||||
+ `-f`: force (default behavior)
|
||||
+ `-n`: no-clobber
|
||||
+ `-r`, `-R`: recursive
|
||||
+ `-L`: follow symlinks
|
||||
+ `-P`: don't follow symlinks
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cp('file1', 'dir1');
|
||||
cp('-R', 'path/to/dir/', '~/newCopy/');
|
||||
cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp');
|
||||
cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above
|
||||
```
|
||||
|
||||
Copies files.
|
||||
|
||||
|
||||
### rm([options,] file [, file ...])
|
||||
### rm([options,] file_array)
|
||||
Available options:
|
||||
|
||||
+ `-f`: force
|
||||
+ `-r, -R`: recursive
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
rm('-rf', '/tmp/*');
|
||||
rm('some_file.txt', 'another_file.txt');
|
||||
rm(['some_file.txt', 'another_file.txt']); // same as above
|
||||
```
|
||||
|
||||
Removes files.
|
||||
|
||||
|
||||
### mv([options ,] source [, source ...], dest')
|
||||
### mv([options ,] source_array, dest')
|
||||
Available options:
|
||||
|
||||
+ `-f`: force (default behavior)
|
||||
+ `-n`: no-clobber
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
mv('-n', 'file', 'dir/');
|
||||
mv('file1', 'file2', 'dir/');
|
||||
mv(['file1', 'file2'], 'dir/'); // same as above
|
||||
```
|
||||
|
||||
Moves files.
|
||||
|
||||
|
||||
### mkdir([options,] dir [, dir ...])
|
||||
### mkdir([options,] dir_array)
|
||||
Available options:
|
||||
|
||||
+ `-p`: full path (will create intermediate dirs if necessary)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g');
|
||||
mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above
|
||||
```
|
||||
|
||||
Creates directories.
|
||||
|
||||
|
||||
### test(expression)
|
||||
Available expression primaries:
|
||||
|
||||
+ `'-b', 'path'`: true if path is a block device
|
||||
+ `'-c', 'path'`: true if path is a character device
|
||||
+ `'-d', 'path'`: true if path is a directory
|
||||
+ `'-e', 'path'`: true if path exists
|
||||
+ `'-f', 'path'`: true if path is a regular file
|
||||
+ `'-L', 'path'`: true if path is a symbolic link
|
||||
+ `'-p', 'path'`: true if path is a pipe (FIFO)
|
||||
+ `'-S', 'path'`: true if path is a socket
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
if (test('-d', path)) { /* do something with dir */ };
|
||||
if (!test('-f', path)) continue; // skip if it's a regular file
|
||||
```
|
||||
|
||||
Evaluates expression using the available primaries and returns corresponding value.
|
||||
|
||||
|
||||
### cat(file [, file ...])
|
||||
### cat(file_array)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var str = cat('file*.txt');
|
||||
var str = cat('file1', 'file2');
|
||||
var str = cat(['file1', 'file2']); // same as above
|
||||
```
|
||||
|
||||
Returns a string containing the given file, or a concatenated string
|
||||
containing the files if more than one file is given (a new line character is
|
||||
introduced between each file).
|
||||
|
||||
|
||||
### head([{'-n', \<num\>},] file [, file ...])
|
||||
### head([{'-n', \<num\>},] file_array)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var str = head({'-n', 1}, 'file*.txt');
|
||||
var str = head('file1', 'file2');
|
||||
var str = head(['file1', 'file2']); // same as above
|
||||
```
|
||||
|
||||
Output the first 10 lines of a file (or the first `<num>` if `-n` is
|
||||
specified)
|
||||
|
||||
|
||||
### tail([{'-n', \<num\>},] file [, file ...])
|
||||
### tail([{'-n', \<num\>},] file_array)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var str = tail({'-n', 1}, 'file*.txt');
|
||||
var str = tail('file1', 'file2');
|
||||
var str = tail(['file1', 'file2']); // same as above
|
||||
```
|
||||
|
||||
Output the last 10 lines of a file (or the last `<num>` if `-n` is
|
||||
specified)
|
||||
|
||||
|
||||
### ShellString.prototype.to(file)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cat('input.txt').to('output.txt');
|
||||
```
|
||||
|
||||
Analogous to the redirection operator `>` in Unix, but works with
|
||||
ShellStrings (such as those returned by `cat`, `grep`, etc). _Like Unix
|
||||
redirections, `to()` will overwrite any existing file!_
|
||||
|
||||
|
||||
### ShellString.prototype.toEnd(file)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cat('input.txt').toEnd('output.txt');
|
||||
```
|
||||
|
||||
Analogous to the redirect-and-append operator `>>` in Unix, but works with
|
||||
ShellStrings (such as those returned by `cat`, `grep`, etc).
|
||||
|
||||
|
||||
### sed([options,] search_regex, replacement, file [, file ...])
|
||||
### sed([options,] search_regex, replacement, file_array)
|
||||
Available options:
|
||||
|
||||
+ `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');
|
||||
sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
|
||||
```
|
||||
|
||||
Reads an input string from `files` and performs a JavaScript `replace()` on the input
|
||||
using the given search regex and replacement string or function. Returns the new string after replacement.
|
||||
|
||||
|
||||
### sort([options,] file [, file ...])
|
||||
### sort([options,] file_array)
|
||||
Available options:
|
||||
|
||||
+ `-r`: Reverse the result of comparisons
|
||||
+ `-n`: Compare according to numerical value
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
sort('foo.txt', 'bar.txt');
|
||||
sort('-r', 'foo.txt');
|
||||
```
|
||||
|
||||
Return the contents of the files, sorted line-by-line. Sorting multiple
|
||||
files mixes their content, just like unix sort does.
|
||||
|
||||
|
||||
### grep([options,] regex_filter, file [, file ...])
|
||||
### grep([options,] regex_filter, file_array)
|
||||
Available options:
|
||||
|
||||
+ `-v`: Inverse the sense of the regex and print the lines not matching the criteria.
|
||||
+ `-l`: Print only filenames of matching files
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
grep('-v', 'GLOBAL_VARIABLE', '*.js');
|
||||
grep('GLOBAL_VARIABLE', '*.js');
|
||||
```
|
||||
|
||||
Reads input string from given files and returns a string containing all lines of the
|
||||
file that match the given `regex_filter`.
|
||||
|
||||
|
||||
### which(command)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var nodeExec = which('node');
|
||||
```
|
||||
|
||||
Searches for `command` in the system's PATH. On Windows, this uses the
|
||||
`PATHEXT` variable to append the extension if it's not already executable.
|
||||
Returns string containing the absolute path to the command.
|
||||
|
||||
|
||||
### echo(string [, string ...])
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
echo('hello world');
|
||||
var str = echo('hello world');
|
||||
```
|
||||
|
||||
Prints string to stdout, and returns string with additional utility methods
|
||||
like `.to()`.
|
||||
|
||||
|
||||
### 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.
|
||||
|
||||
### 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
|
||||
|
||||
|
||||
### ln([options,] source, dest)
|
||||
Available options:
|
||||
|
||||
+ `-s`: symlink
|
||||
+ `-f`: force
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
ln('file', 'newlink');
|
||||
ln('-sf', 'file', 'existing');
|
||||
```
|
||||
|
||||
Links source to dest. Use -f to force the link, should dest already exist.
|
||||
|
||||
|
||||
### exit(code)
|
||||
Exits the current process with the given exit code.
|
||||
|
||||
### env['VAR_NAME']
|
||||
Object containing environment variables (both getter and setter). Shortcut to process.env.
|
||||
|
||||
### exec(command [, options] [, callback])
|
||||
Available options (all `false` by default):
|
||||
|
||||
+ `async`: Asynchronous execution. If a callback is provided, it will be set to
|
||||
`true`, regardless of the passed value.
|
||||
+ `silent`: Do not echo program output to console.
|
||||
+ and any option available to NodeJS's
|
||||
[child_process.exec()](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var version = exec('node --version', {silent:true}).stdout;
|
||||
|
||||
var child = exec('some_long_running_process', {async:true});
|
||||
child.stdout.on('data', function(data) {
|
||||
/* ... do something with data ... */
|
||||
});
|
||||
|
||||
exec('some_long_running_process', function(code, stdout, stderr) {
|
||||
console.log('Exit code:', code);
|
||||
console.log('Program output:', stdout);
|
||||
console.log('Program stderr:', stderr);
|
||||
});
|
||||
```
|
||||
|
||||
Executes the given `command` _synchronously_, unless otherwise specified. When in synchronous
|
||||
mode, this returns a ShellString (compatible with ShellJS v0.6.x, which returns an object
|
||||
of the form `{ code:..., stdout:... , stderr:... }`). Otherwise, this returns the child process
|
||||
object, and the `callback` gets the arguments `(code, stdout, stderr)`.
|
||||
|
||||
**Note:** For long-lived processes, it's best to run `exec()` asynchronously as
|
||||
the current synchronous implementation uses a lot of CPU. This should be getting
|
||||
fixed soon.
|
||||
|
||||
|
||||
### 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.
|
||||
|
||||
|
||||
### touch([options,] file [, file ...])
|
||||
### touch([options,] file_array)
|
||||
Available options:
|
||||
|
||||
+ `-a`: Change only the access time
|
||||
+ `-c`: Do not create any files
|
||||
+ `-m`: Change only the modification time
|
||||
+ `-d DATE`: Parse DATE and use it instead of current time
|
||||
+ `-r FILE`: Use FILE's times instead of current time
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
touch('source.js');
|
||||
touch('-c', '/path/to/some/dir/source.js');
|
||||
touch({ '-r': FILE }, '/path/to/some/dir/source.js');
|
||||
```
|
||||
|
||||
Update the access and modification times of each FILE to the current time.
|
||||
A FILE argument that does not exist is created empty, unless -c is supplied.
|
||||
This is a partial implementation of *[touch(1)](http://linux.die.net/man/1/touch)*.
|
||||
|
||||
|
||||
### set(options)
|
||||
Available options:
|
||||
|
||||
+ `+/-e`: exit upon error (`config.fatal`)
|
||||
+ `+/-v`: verbose: show all commands (`config.verbose`)
|
||||
+ `+/-f`: disable filename expansion (globbing)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
set('-e'); // exit upon first error
|
||||
set('+e'); // this undoes a "set('-e')"
|
||||
```
|
||||
|
||||
Sets global configuration variables
|
||||
|
||||
|
||||
## Non-Unix commands
|
||||
|
||||
|
||||
### tempdir()
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var tmp = tempdir(); // "/tmp" for most *nix platforms
|
||||
```
|
||||
|
||||
Searches and returns string containing a writeable, platform-dependent temporary directory.
|
||||
Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
||||
|
||||
|
||||
### error()
|
||||
Tests if error occurred in the last command. Returns a truthy value if an
|
||||
error returned and a falsy value otherwise.
|
||||
|
||||
**Note**: do not rely on the
|
||||
return value to be an error message. If you need the last error message, use
|
||||
the `.stderr` attribute from the last command's return value instead.
|
||||
|
||||
|
||||
### ShellString(str)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var foo = ShellString('hello world');
|
||||
```
|
||||
|
||||
Turns a regular string into a string-like object similar to what each
|
||||
command returns. This has special methods, like `.to()` and `.toEnd()`
|
||||
|
||||
|
||||
### Pipes
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
grep('foo', 'file1.txt', 'file2.txt').sed(/o/g, 'a').to('output.txt');
|
||||
echo('files with o\'s in the name:\n' + ls().grep('o'));
|
||||
cat('test.js').exec('node'); // pipe to exec() call
|
||||
```
|
||||
|
||||
Commands can send their output to another command in a pipe-like fashion.
|
||||
`sed`, `grep`, `cat`, `exec`, `to`, and `toEnd` can appear on the right-hand
|
||||
side of a pipe. Pipes can be chained.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
### config.silent
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var sh = require('shelljs');
|
||||
var silentState = sh.config.silent; // save old silent state
|
||||
sh.config.silent = true;
|
||||
/* ... */
|
||||
sh.config.silent = silentState; // restore old silent state
|
||||
```
|
||||
|
||||
Suppresses all command output if `true`, except for `echo()` calls.
|
||||
Default is `false`.
|
||||
|
||||
### config.fatal
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
require('shelljs/global');
|
||||
config.fatal = true; // or set('-e');
|
||||
cp('this_file_does_not_exist', '/dev/null'); // throws Error here
|
||||
/* more commands... */
|
||||
```
|
||||
|
||||
If `true` the script will throw a Javascript error when any shell.js
|
||||
command encounters an error. Default is `false`. This is analogous to
|
||||
Bash's `set -e`
|
||||
|
||||
### config.verbose
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
config.verbose = true; // or set('-v');
|
||||
cd('dir/');
|
||||
ls('subdir/');
|
||||
```
|
||||
|
||||
Will print each command as follows:
|
||||
|
||||
```
|
||||
cd dir/
|
||||
ls subdir/
|
||||
```
|
||||
|
||||
### config.globOptions
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
config.globOptions = {nodir: true};
|
||||
```
|
||||
|
||||
Use this value for calls to `glob.sync()` instead of the default options.
|
||||
|
||||
## Team
|
||||
|
||||
| [](https://github.com/nfischer) | [](http://github.com/ariporad) |
|
||||
|:---:|:---:|
|
||||
| [Nate Fischer](https://github.com/nfischer) | [Ari Porad](http://github.com/ariporad) |
|
39
node_modules/shelljs/bin/shjs
generated
vendored
Executable file
39
node_modules/shelljs/bin/shjs
generated
vendored
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
require('../global');
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log('ShellJS: missing argument (script name)');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var args,
|
||||
scriptName = process.argv[2];
|
||||
env['NODE_PATH'] = __dirname + '/../..';
|
||||
|
||||
if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
|
||||
if (test('-f', scriptName + '.js'))
|
||||
scriptName += '.js';
|
||||
if (test('-f', scriptName + '.coffee'))
|
||||
scriptName += '.coffee';
|
||||
}
|
||||
|
||||
if (!test('-f', scriptName)) {
|
||||
console.log('ShellJS: script not found ('+scriptName+')');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
args = process.argv.slice(3);
|
||||
|
||||
for (var i = 0, l = args.length; i < l; i++) {
|
||||
if (args[i][0] !== "-"){
|
||||
args[i] = '"' + args[i] + '"'; // fixes arguments with multiple words
|
||||
}
|
||||
}
|
||||
|
||||
var path = require('path');
|
||||
var extensions = require('interpret').extensions;
|
||||
var rechoir = require('rechoir');
|
||||
rechoir.prepare(extensions, scriptName);
|
||||
require(require.resolve(path.resolve(process.cwd(), scriptName)));
|
10
node_modules/shelljs/global.js
generated
vendored
Normal file
10
node_modules/shelljs/global.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
var shell = require('./shell.js');
|
||||
var common = require('./src/common');
|
||||
for (var cmd in shell)
|
||||
global[cmd] = shell[cmd];
|
||||
|
||||
var _to = require('./src/to');
|
||||
String.prototype.to = common.wrap('to', _to);
|
||||
|
||||
var _toEnd = require('./src/toEnd');
|
||||
String.prototype.toEnd = common.wrap('toEnd', _toEnd);
|
57
node_modules/shelljs/make.js
generated
vendored
Normal file
57
node_modules/shelljs/make.js
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
require('./global');
|
||||
|
||||
global.config.fatal = true;
|
||||
global.target = {};
|
||||
|
||||
var args = process.argv.slice(2),
|
||||
targetArgs,
|
||||
dashesLoc = args.indexOf('--');
|
||||
|
||||
// split args, everything after -- if only for targets
|
||||
if (dashesLoc > -1) {
|
||||
targetArgs = args.slice(dashesLoc + 1, args.length);
|
||||
args = args.slice(0, dashesLoc);
|
||||
}
|
||||
|
||||
// This ensures we only execute the script targets after the entire script has
|
||||
// been evaluated
|
||||
setTimeout(function() {
|
||||
var t;
|
||||
|
||||
if (args.length === 1 && args[0] === '--help') {
|
||||
console.log('Available targets:');
|
||||
for (t in global.target)
|
||||
console.log(' ' + t);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wrap targets to prevent duplicate execution
|
||||
for (t in global.target) {
|
||||
(function(t, oldTarget){
|
||||
|
||||
// Wrap it
|
||||
global.target[t] = function() {
|
||||
if (!oldTarget.done){
|
||||
oldTarget.done = true;
|
||||
oldTarget.result = oldTarget.apply(oldTarget, arguments);
|
||||
}
|
||||
return oldTarget.result;
|
||||
};
|
||||
|
||||
})(t, global.target[t]);
|
||||
}
|
||||
|
||||
// Execute desired targets
|
||||
if (args.length > 0) {
|
||||
args.forEach(function(arg) {
|
||||
if (arg in global.target)
|
||||
global.target[arg](targetArgs);
|
||||
else {
|
||||
console.log('no such target: ' + arg);
|
||||
}
|
||||
});
|
||||
} else if ('all' in global.target) {
|
||||
global.target.all(targetArgs);
|
||||
}
|
||||
|
||||
}, 0);
|
123
node_modules/shelljs/package.json
generated
vendored
Normal file
123
node_modules/shelljs/package.json
generated
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "shelljs",
|
||||
"raw": "shelljs@^0.7.0",
|
||||
"rawSpec": "^0.7.0",
|
||||
"scope": null,
|
||||
"spec": ">=0.7.0 <0.8.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/home/philkunz/gitlab/pushrocks/smartdrive/node_modules/npmts-g"
|
||||
]
|
||||
],
|
||||
"_from": "shelljs@>=0.7.0 <0.8.0",
|
||||
"_id": "shelljs@0.7.0",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/shelljs",
|
||||
"_nodeVersion": "5.3.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/shelljs-0.7.0.tgz_1461620341411_0.5085073048248887"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "ntfschr@gmail.com",
|
||||
"name": "nfischer"
|
||||
},
|
||||
"_npmVersion": "3.5.2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "shelljs",
|
||||
"raw": "shelljs@^0.7.0",
|
||||
"rawSpec": "^0.7.0",
|
||||
"scope": null,
|
||||
"spec": ">=0.7.0 <0.8.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/npmts-g"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.0.tgz",
|
||||
"_shasum": "3f6f2e4965cec565f65ff3861d644f879281a576",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "shelljs@^0.7.0",
|
||||
"_where": "/home/philkunz/gitlab/pushrocks/smartdrive/node_modules/npmts-g",
|
||||
"bin": {
|
||||
"shjs": "./bin/shjs"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/shelljs/shelljs/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"email": "ari@ariporad.com",
|
||||
"name": "Ari Porad",
|
||||
"url": "http://ariporad.com/"
|
||||
},
|
||||
{
|
||||
"email": "ntfschr@gmail.com",
|
||||
"name": "Nate Fischer",
|
||||
"url": "https://github.com/nfischer"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"glob": "^7.0.0",
|
||||
"interpret": "^1.0.0",
|
||||
"rechoir": "^0.6.2"
|
||||
},
|
||||
"description": "Portable Unix shell commands for Node.js",
|
||||
"devDependencies": {
|
||||
"coffee-script": "^1.10.0",
|
||||
"jshint": "~2.1.11"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "3f6f2e4965cec565f65ff3861d644f879281a576",
|
||||
"tarball": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"iojs": "*",
|
||||
"node": ">=0.11.0"
|
||||
},
|
||||
"gitHead": "bce3a53bb155b7c1ed5f68542943a166fc579dd9",
|
||||
"homepage": "http://github.com/shelljs/shelljs",
|
||||
"keywords": [
|
||||
"shelljs",
|
||||
"bash",
|
||||
"unix",
|
||||
"shell",
|
||||
"makefile",
|
||||
"make",
|
||||
"jake",
|
||||
"synchronous"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "./shell.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "ari@ariporad.com",
|
||||
"name": "ariporad"
|
||||
},
|
||||
{
|
||||
"email": "arturadib@gmail.com",
|
||||
"name": "artur"
|
||||
},
|
||||
{
|
||||
"email": "ntfschr@gmail.com",
|
||||
"name": "nfischer"
|
||||
}
|
||||
],
|
||||
"name": "shelljs",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/shelljs/shelljs.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node scripts/run-tests"
|
||||
},
|
||||
"version": "0.7.0"
|
||||
}
|
26
node_modules/shelljs/scripts/generate-docs.js
generated
vendored
Executable file
26
node_modules/shelljs/scripts/generate-docs.js
generated
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env node
|
||||
/* globals cat, cd, echo, grep, sed, ShellString */
|
||||
require('../global');
|
||||
|
||||
echo('Appending docs to README.md');
|
||||
|
||||
cd(__dirname + '/..');
|
||||
|
||||
// Extract docs from shell.js
|
||||
var docs = grep('//@', 'shell.js');
|
||||
|
||||
docs = docs.replace(/\/\/\@include (.+)/g, function(match, path) {
|
||||
var file = path.match('.js$') ? path : path+'.js';
|
||||
return grep('//@', file);
|
||||
});
|
||||
|
||||
// Remove '//@'
|
||||
docs = docs.replace(/\/\/\@ ?/g, '');
|
||||
|
||||
// Wipe out the old docs
|
||||
ShellString(cat('README.md').replace(/## Command reference(.|\n)*\n## Team/, '## Command reference\n## Team')).to('README.md');
|
||||
|
||||
// Append new docs to README
|
||||
sed('-i', /## Command reference/, '## Command reference\n\n' + docs, 'README.md');
|
||||
|
||||
echo('All done.');
|
55
node_modules/shelljs/scripts/run-tests.js
generated
vendored
Executable file
55
node_modules/shelljs/scripts/run-tests.js
generated
vendored
Executable file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
/* globals cd, echo, exec, exit, ls, pwd, test */
|
||||
require('../global');
|
||||
var common = require('../src/common');
|
||||
|
||||
var failed = false;
|
||||
|
||||
//
|
||||
// Lint
|
||||
//
|
||||
var JSHINT_BIN = 'node_modules/jshint/bin/jshint';
|
||||
cd(__dirname + '/..');
|
||||
|
||||
if (!test('-f', JSHINT_BIN)) {
|
||||
echo('JSHint not found. Run `npm install` in the root dir first.');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
var jsfiles = common.expand([pwd() + '/*.js',
|
||||
pwd() + '/scripts/*.js',
|
||||
pwd() + '/src/*.js',
|
||||
pwd() + '/test/*.js'
|
||||
]).join(' ');
|
||||
if (exec(JSON.stringify(process.execPath)+' '+pwd()+'/'+JSHINT_BIN+' '+jsfiles).code !== 0) {
|
||||
failed = true;
|
||||
echo('*** JSHINT FAILED! (return code != 0)');
|
||||
echo();
|
||||
} else {
|
||||
echo('All JSHint tests passed');
|
||||
echo();
|
||||
}
|
||||
|
||||
//
|
||||
// Unit tests
|
||||
//
|
||||
cd(__dirname + '/../test');
|
||||
ls('*.js').forEach(function(file) {
|
||||
echo('Running test:', file);
|
||||
if (exec(JSON.stringify(process.execPath)+' '+file).code !== 123) { // 123 avoids false positives (e.g. premature exit)
|
||||
failed = true;
|
||||
echo('*** TEST FAILED! (missing exit code "123")');
|
||||
echo();
|
||||
}
|
||||
});
|
||||
|
||||
if (failed) {
|
||||
echo();
|
||||
echo('*******************************************************');
|
||||
echo('WARNING: Some tests did not pass!');
|
||||
echo('*******************************************************');
|
||||
exit(1);
|
||||
} else {
|
||||
echo();
|
||||
echo('All tests passed.');
|
||||
}
|
228
node_modules/shelljs/shell.js
generated
vendored
Normal file
228
node_modules/shelljs/shell.js
generated
vendored
Normal file
@ -0,0 +1,228 @@
|
||||
//
|
||||
// ShellJS
|
||||
// Unix shell commands on top of Node's API
|
||||
//
|
||||
// Copyright (c) 2012 Artur Adib
|
||||
// http://github.com/arturadib/shelljs
|
||||
//
|
||||
|
||||
var common = require('./src/common');
|
||||
|
||||
|
||||
//@
|
||||
//@ All commands run synchronously, unless otherwise stated.
|
||||
//@ All commands accept standard bash globbing characters (`*`, `?`, etc.),
|
||||
//@ compatible with the [node glob module](https://github.com/isaacs/node-glob).
|
||||
//@
|
||||
//@ For less-commonly used commands and features, please check out our [wiki
|
||||
//@ page](https://github.com/shelljs/shelljs/wiki).
|
||||
//@
|
||||
|
||||
//@include ./src/cd
|
||||
var _cd = require('./src/cd');
|
||||
exports.cd = common.wrap('cd', _cd, {idx: 1});
|
||||
|
||||
//@include ./src/pwd
|
||||
var _pwd = require('./src/pwd');
|
||||
exports.pwd = common.wrap('pwd', _pwd);
|
||||
|
||||
//@include ./src/ls
|
||||
var _ls = require('./src/ls');
|
||||
exports.ls = common.wrap('ls', _ls, {idx: 1});
|
||||
|
||||
//@include ./src/find
|
||||
var _find = require('./src/find');
|
||||
exports.find = common.wrap('find', _find, {idx: 1});
|
||||
|
||||
//@include ./src/cp
|
||||
var _cp = require('./src/cp');
|
||||
exports.cp = common.wrap('cp', _cp, {idx: 1});
|
||||
|
||||
//@include ./src/rm
|
||||
var _rm = require('./src/rm');
|
||||
exports.rm = common.wrap('rm', _rm, {idx: 1});
|
||||
|
||||
//@include ./src/mv
|
||||
var _mv = require('./src/mv');
|
||||
exports.mv = common.wrap('mv', _mv, {idx: 1});
|
||||
|
||||
//@include ./src/mkdir
|
||||
var _mkdir = require('./src/mkdir');
|
||||
exports.mkdir = common.wrap('mkdir', _mkdir, {idx: 1});
|
||||
|
||||
//@include ./src/test
|
||||
var _test = require('./src/test');
|
||||
exports.test = common.wrap('test', _test);
|
||||
|
||||
//@include ./src/cat
|
||||
var _cat = require('./src/cat');
|
||||
exports.cat = common.wrap('cat', _cat, {idx: 1});
|
||||
|
||||
//@include ./src/head
|
||||
var _head = require('./src/head');
|
||||
exports.head = common.wrap('head', _head, {idx: 1});
|
||||
|
||||
//@include ./src/tail
|
||||
var _tail = require('./src/tail');
|
||||
exports.tail = common.wrap('tail', _tail, {idx: 1});
|
||||
|
||||
// The below commands have been moved to common.ShellString(), and are only here
|
||||
// for generating the docs
|
||||
//@include ./src/to
|
||||
//@include ./src/toEnd
|
||||
|
||||
//@include ./src/sed
|
||||
var _sed = require('./src/sed');
|
||||
exports.sed = common.wrap('sed', _sed, {idx: 3});
|
||||
|
||||
//@include ./src/sort
|
||||
var _sort = require('./src/sort');
|
||||
exports.sort = common.wrap('sort', _sort, {idx: 1});
|
||||
|
||||
//@include ./src/grep
|
||||
var _grep = require('./src/grep');
|
||||
exports.grep = common.wrap('grep', _grep, {idx: 2});
|
||||
|
||||
//@include ./src/which
|
||||
var _which = require('./src/which');
|
||||
exports.which = common.wrap('which', _which);
|
||||
|
||||
//@include ./src/echo
|
||||
var _echo = require('./src/echo');
|
||||
exports.echo = common.wrap('echo', _echo);
|
||||
|
||||
//@include ./src/dirs
|
||||
var _dirs = require('./src/dirs').dirs;
|
||||
exports.dirs = common.wrap('dirs', _dirs, {idx: 1});
|
||||
var _pushd = require('./src/dirs').pushd;
|
||||
exports.pushd = common.wrap('pushd', _pushd, {idx: 1});
|
||||
var _popd = require('./src/dirs').popd;
|
||||
exports.popd = common.wrap('popd', _popd, {idx: 1});
|
||||
|
||||
//@include ./src/ln
|
||||
var _ln = require('./src/ln');
|
||||
exports.ln = common.wrap('ln', _ln, {idx: 1});
|
||||
|
||||
//@
|
||||
//@ ### exit(code)
|
||||
//@ Exits the current process with the given exit code.
|
||||
exports.exit = process.exit;
|
||||
|
||||
//@
|
||||
//@ ### env['VAR_NAME']
|
||||
//@ Object containing environment variables (both getter and setter). Shortcut to process.env.
|
||||
exports.env = process.env;
|
||||
|
||||
//@include ./src/exec
|
||||
var _exec = require('./src/exec');
|
||||
exports.exec = common.wrap('exec', _exec, {notUnix:true});
|
||||
|
||||
//@include ./src/chmod
|
||||
var _chmod = require('./src/chmod');
|
||||
exports.chmod = common.wrap('chmod', _chmod, {idx: 1});
|
||||
|
||||
//@include ./src/touch
|
||||
var _touch = require('./src/touch');
|
||||
exports.touch = common.wrap('touch', _touch, {idx: 1});
|
||||
|
||||
//@include ./src/set
|
||||
var _set = require('./src/set');
|
||||
exports.set = common.wrap('set', _set);
|
||||
|
||||
|
||||
//@
|
||||
//@ ## Non-Unix commands
|
||||
//@
|
||||
|
||||
//@include ./src/tempdir
|
||||
var _tempDir = require('./src/tempdir');
|
||||
exports.tempdir = common.wrap('tempdir', _tempDir);
|
||||
|
||||
//@include ./src/error
|
||||
var _error = require('./src/error');
|
||||
exports.error = _error;
|
||||
|
||||
//@include ./src/common
|
||||
exports.ShellString = common.ShellString;
|
||||
|
||||
//@
|
||||
//@ ### Pipes
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ grep('foo', 'file1.txt', 'file2.txt').sed(/o/g, 'a').to('output.txt');
|
||||
//@ echo('files with o\'s in the name:\n' + ls().grep('o'));
|
||||
//@ cat('test.js').exec('node'); // pipe to exec() call
|
||||
//@ ```
|
||||
//@
|
||||
//@ Commands can send their output to another command in a pipe-like fashion.
|
||||
//@ `sed`, `grep`, `cat`, `exec`, `to`, and `toEnd` can appear on the right-hand
|
||||
//@ side of a pipe. Pipes can be chained.
|
||||
|
||||
//@
|
||||
//@ ## Configuration
|
||||
//@
|
||||
|
||||
exports.config = common.config;
|
||||
|
||||
//@
|
||||
//@ ### config.silent
|
||||
//@
|
||||
//@ Example:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var sh = require('shelljs');
|
||||
//@ var silentState = sh.config.silent; // save old silent state
|
||||
//@ sh.config.silent = true;
|
||||
//@ /* ... */
|
||||
//@ sh.config.silent = silentState; // restore old silent state
|
||||
//@ ```
|
||||
//@
|
||||
//@ Suppresses all command output if `true`, except for `echo()` calls.
|
||||
//@ Default is `false`.
|
||||
|
||||
//@
|
||||
//@ ### config.fatal
|
||||
//@
|
||||
//@ Example:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ require('shelljs/global');
|
||||
//@ config.fatal = true; // or set('-e');
|
||||
//@ cp('this_file_does_not_exist', '/dev/null'); // throws Error here
|
||||
//@ /* more commands... */
|
||||
//@ ```
|
||||
//@
|
||||
//@ If `true` the script will throw a Javascript error when any shell.js
|
||||
//@ command encounters an error. Default is `false`. This is analogous to
|
||||
//@ Bash's `set -e`
|
||||
|
||||
//@
|
||||
//@ ### config.verbose
|
||||
//@
|
||||
//@ Example:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ config.verbose = true; // or set('-v');
|
||||
//@ cd('dir/');
|
||||
//@ ls('subdir/');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Will print each command as follows:
|
||||
//@
|
||||
//@ ```
|
||||
//@ cd dir/
|
||||
//@ ls subdir/
|
||||
//@ ```
|
||||
|
||||
//@
|
||||
//@ ### config.globOptions
|
||||
//@
|
||||
//@ Example:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ config.globOptions = {nodir: true};
|
||||
//@ ```
|
||||
//@
|
||||
//@ Use this value for calls to `glob.sync()` instead of the default options.
|
36
node_modules/shelljs/src/cat.js
generated
vendored
Normal file
36
node_modules/shelljs/src/cat.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
//@
|
||||
//@ ### cat(file [, file ...])
|
||||
//@ ### cat(file_array)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var str = cat('file*.txt');
|
||||
//@ var str = cat('file1', 'file2');
|
||||
//@ var str = cat(['file1', 'file2']); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Returns a string containing the given file, or a concatenated string
|
||||
//@ containing the files if more than one file is given (a new line character is
|
||||
//@ introduced between each file).
|
||||
function _cat(options, files) {
|
||||
var cat = common.readFromPipe(this);
|
||||
|
||||
if (!files && !cat)
|
||||
common.error('no paths given');
|
||||
|
||||
files = [].slice.call(arguments, 1);
|
||||
|
||||
files.forEach(function(file) {
|
||||
if (!fs.existsSync(file))
|
||||
common.error('no such file or directory: ' + file);
|
||||
|
||||
cat += fs.readFileSync(file, 'utf8');
|
||||
});
|
||||
|
||||
return new common.ShellString(cat, common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _cat;
|
36
node_modules/shelljs/src/cd.js
generated
vendored
Normal file
36
node_modules/shelljs/src/cd.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
var fs = require('fs');
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### cd([dir])
|
||||
//@ Changes to directory `dir` for the duration of the script. Changes to home
|
||||
//@ directory if no argument is supplied.
|
||||
function _cd(options, dir) {
|
||||
if (!dir)
|
||||
dir = common.getUserHome();
|
||||
|
||||
if (dir === '-') {
|
||||
if (!process.env.OLDPWD)
|
||||
common.error('could not find previous directory');
|
||||
else
|
||||
dir = process.env.OLDPWD;
|
||||
}
|
||||
|
||||
try {
|
||||
var curDir = process.cwd();
|
||||
process.chdir(dir);
|
||||
process.env.OLDPWD = curDir;
|
||||
} catch (e) {
|
||||
// something went wrong, let's figure out the error
|
||||
var err;
|
||||
try {
|
||||
fs.statSync(dir); // if this succeeds, it must be some sort of file
|
||||
err = 'not a directory: ' + dir;
|
||||
} catch (e) {
|
||||
err = 'no such file or directory: ' + dir;
|
||||
}
|
||||
if (err) common.error(err);
|
||||
}
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _cd;
|
213
node_modules/shelljs/src/chmod.js
generated
vendored
Normal file
213
node_modules/shelljs/src/chmod.js
generated
vendored
Normal file
@ -0,0 +1,213 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
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.
|
||||
[].unshift.call(arguments, '');
|
||||
}
|
||||
else {
|
||||
common.error('You must specify a file.');
|
||||
}
|
||||
}
|
||||
|
||||
options = common.parseOptions(options, {
|
||||
'R': 'recursive',
|
||||
'c': 'changes',
|
||||
'v': 'verbose'
|
||||
});
|
||||
|
||||
filePattern = [].slice.call(arguments, 2);
|
||||
|
||||
var files;
|
||||
|
||||
// TODO: replace this with a call to common.expand()
|
||||
if (options.recursive) {
|
||||
files = [];
|
||||
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 = filePattern;
|
||||
}
|
||||
|
||||
files.forEach(function innerChmod(file) {
|
||||
file = path.resolve(file);
|
||||
if (!fs.existsSync(file)) {
|
||||
common.error('File not found: ' + file);
|
||||
}
|
||||
|
||||
// When recursing, don't follow symlinks.
|
||||
if (options.recursive && fs.lstatSync(file).isSymbolicLink()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var stat = fs.statSync(file);
|
||||
var isDir = stat.isDirectory();
|
||||
var perms = stat.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 changeExecDir = change.indexOf('X') != -1;
|
||||
var changeSticky = change.indexOf('t') != -1;
|
||||
var changeSetuid = change.indexOf('s') != -1;
|
||||
|
||||
if (changeExecDir && isDir)
|
||||
changeExec = true;
|
||||
|
||||
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) {
|
||||
console.log(file + ' -> ' + newPerms.toString(8));
|
||||
}
|
||||
|
||||
if (perms != newPerms) {
|
||||
if (!options.verbose && options.changes) {
|
||||
console.log(file + ' -> ' + newPerms.toString(8));
|
||||
}
|
||||
fs.chmodSync(file, newPerms);
|
||||
perms = newPerms; // for the next round of changes!
|
||||
}
|
||||
}
|
||||
else {
|
||||
common.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);
|
||||
}
|
||||
});
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _chmod;
|
330
node_modules/shelljs/src/common.js
generated
vendored
Normal file
330
node_modules/shelljs/src/common.js
generated
vendored
Normal file
@ -0,0 +1,330 @@
|
||||
// jshint -W053
|
||||
// Ignore warning about 'new String()'
|
||||
'use strict';
|
||||
|
||||
var os = require('os');
|
||||
var fs = require('fs');
|
||||
var glob = require('glob');
|
||||
var shell = require('..');
|
||||
var _to = require('./to');
|
||||
var _toEnd = require('./toEnd');
|
||||
|
||||
var DEFAULT_ERROR_CODE = 1;
|
||||
|
||||
// Module globals
|
||||
var config = {
|
||||
silent: false,
|
||||
fatal: false,
|
||||
verbose: false,
|
||||
noglob: false,
|
||||
globOptions: {},
|
||||
maxdepth: 255
|
||||
};
|
||||
exports.config = config;
|
||||
|
||||
var state = {
|
||||
error: null,
|
||||
errorCode: 0,
|
||||
currentCmd: 'shell.js',
|
||||
tempDir: null
|
||||
};
|
||||
exports.state = state;
|
||||
|
||||
delete process.env.OLDPWD; // initially, there's no previous directory
|
||||
|
||||
var platform = os.type().match(/^Win/) ? 'win' : 'unix';
|
||||
exports.platform = platform;
|
||||
|
||||
function log() {
|
||||
if (!config.silent)
|
||||
console.error.apply(console, arguments);
|
||||
}
|
||||
exports.log = log;
|
||||
|
||||
// Shows error message. Throws if config.fatal is true
|
||||
function error(msg, _code, _continue) {
|
||||
if (typeof _code === 'boolean') {
|
||||
_continue = _code;
|
||||
_code = DEFAULT_ERROR_CODE;
|
||||
}
|
||||
if (typeof _code !== 'number')
|
||||
_code = DEFAULT_ERROR_CODE;
|
||||
|
||||
if (state.errorCode === 0)
|
||||
state.errorCode = _code;
|
||||
|
||||
if (state.error === null)
|
||||
state.error = '';
|
||||
var log_entry = state.currentCmd + ': ' + msg;
|
||||
if (state.error === '')
|
||||
state.error = log_entry;
|
||||
else
|
||||
state.error += '\n' + log_entry;
|
||||
|
||||
if(config.fatal)
|
||||
throw new Error(log_entry);
|
||||
|
||||
if (msg.length > 0)
|
||||
log(log_entry);
|
||||
|
||||
if(!_continue) {
|
||||
throw {
|
||||
msg: 'earlyExit',
|
||||
retValue: (new ShellString('', state.error, state.errorCode))
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.error = error;
|
||||
|
||||
//@
|
||||
//@ ### ShellString(str)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var foo = ShellString('hello world');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Turns a regular string into a string-like object similar to what each
|
||||
//@ command returns. This has special methods, like `.to()` and `.toEnd()`
|
||||
var ShellString = function (stdout, stderr, code) {
|
||||
var that;
|
||||
if (stdout instanceof Array) {
|
||||
that = stdout;
|
||||
that.stdout = stdout.join('\n');
|
||||
if (stdout.length > 0) that.stdout += '\n';
|
||||
} else {
|
||||
that = new String(stdout);
|
||||
that.stdout = stdout;
|
||||
}
|
||||
that.stderr = stderr;
|
||||
that.code = code;
|
||||
that.to = function() {wrap('to', _to, {idx: 1}).apply(that.stdout, arguments); return that;};
|
||||
that.toEnd = function() {wrap('toEnd', _toEnd, {idx: 1}).apply(that.stdout, arguments); return that;};
|
||||
['cat', 'head', 'sed', 'sort', 'tail', 'grep', 'exec'].forEach(function (cmd) {
|
||||
that[cmd] = function() {return shell[cmd].apply(that.stdout, arguments);};
|
||||
});
|
||||
return that;
|
||||
};
|
||||
|
||||
exports.ShellString = ShellString;
|
||||
|
||||
// Return the home directory in a platform-agnostic way, with consideration for
|
||||
// older versions of node
|
||||
function getUserHome() {
|
||||
var result;
|
||||
if (os.homedir)
|
||||
result = os.homedir(); // node 3+
|
||||
else
|
||||
result = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
|
||||
return result;
|
||||
}
|
||||
exports.getUserHome = getUserHome;
|
||||
|
||||
// Returns {'alice': true, 'bob': false} when passed a string and dictionary as follows:
|
||||
// parseOptions('-a', {'a':'alice', 'b':'bob'});
|
||||
// Returns {'reference': 'string-value', 'bob': false} when passed two dictionaries of the form:
|
||||
// parseOptions({'-r': 'string-value'}, {'r':'reference', 'b':'bob'});
|
||||
function parseOptions(opt, map) {
|
||||
if (!map)
|
||||
error('parseOptions() internal error: no map given');
|
||||
|
||||
// All options are false by default
|
||||
var options = {};
|
||||
for (var letter in map) {
|
||||
if (map[letter][0] !== '!')
|
||||
options[map[letter]] = false;
|
||||
}
|
||||
|
||||
if (!opt)
|
||||
return options; // defaults
|
||||
|
||||
var optionName;
|
||||
if (typeof opt === 'string') {
|
||||
if (opt[0] !== '-')
|
||||
return options;
|
||||
|
||||
// e.g. chars = ['R', 'f']
|
||||
var chars = opt.slice(1).split('');
|
||||
|
||||
chars.forEach(function(c) {
|
||||
if (c in map) {
|
||||
optionName = map[c];
|
||||
if (optionName[0] === '!')
|
||||
options[optionName.slice(1, optionName.length-1)] = false;
|
||||
else
|
||||
options[optionName] = true;
|
||||
} else {
|
||||
error('option not recognized: '+c);
|
||||
}
|
||||
});
|
||||
} else if (typeof opt === 'object') {
|
||||
for (var key in opt) {
|
||||
// key is a string of the form '-r', '-d', etc.
|
||||
var c = key[1];
|
||||
if (c in map) {
|
||||
optionName = map[c];
|
||||
options[optionName] = opt[key]; // assign the given value
|
||||
} else {
|
||||
error('option not recognized: '+c);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error('options must be strings or key-value pairs');
|
||||
}
|
||||
return options;
|
||||
}
|
||||
exports.parseOptions = parseOptions;
|
||||
|
||||
// Expands wildcards with matching (ie. existing) file names.
|
||||
// For example:
|
||||
// expand(['file*.js']) = ['file1.js', 'file2.js', ...]
|
||||
// (if the files 'file1.js', 'file2.js', etc, exist in the current dir)
|
||||
function expand(list) {
|
||||
if (!Array.isArray(list)) {
|
||||
throw new TypeError('must be an array');
|
||||
}
|
||||
var expanded = [];
|
||||
list.forEach(function(listEl) {
|
||||
// Don't expand non-strings
|
||||
if (typeof listEl !== 'string') {
|
||||
expanded.push(listEl);
|
||||
} else {
|
||||
var ret = glob.sync(listEl, config.globOptions);
|
||||
// if glob fails, interpret the string literally
|
||||
expanded = expanded.concat(ret.length > 0 ? ret : [listEl]);
|
||||
}
|
||||
});
|
||||
return expanded;
|
||||
}
|
||||
exports.expand = expand;
|
||||
|
||||
// Normalizes _unlinkSync() across platforms to match Unix behavior, i.e.
|
||||
// file can be unlinked even if it's read-only, see https://github.com/joyent/node/issues/3006
|
||||
function unlinkSync(file) {
|
||||
try {
|
||||
fs.unlinkSync(file);
|
||||
} catch(e) {
|
||||
// Try to override file permission
|
||||
if (e.code === 'EPERM') {
|
||||
fs.chmodSync(file, '0666');
|
||||
fs.unlinkSync(file);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.unlinkSync = unlinkSync;
|
||||
|
||||
// e.g. 'shelljs_a5f185d0443ca...'
|
||||
function randomFileName() {
|
||||
function randomHash(count) {
|
||||
if (count === 1)
|
||||
return parseInt(16*Math.random(), 10).toString(16);
|
||||
else {
|
||||
var hash = '';
|
||||
for (var i=0; i<count; i++)
|
||||
hash += randomHash(1);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
return 'shelljs_'+randomHash(20);
|
||||
}
|
||||
exports.randomFileName = randomFileName;
|
||||
|
||||
// extend(target_obj, source_obj1 [, source_obj2 ...])
|
||||
// Shallow extend, e.g.:
|
||||
// extend({A:1}, {b:2}, {c:3}) returns {A:1, b:2, c:3}
|
||||
function extend(target) {
|
||||
var sources = [].slice.call(arguments, 1);
|
||||
sources.forEach(function(source) {
|
||||
for (var key in source)
|
||||
target[key] = source[key];
|
||||
});
|
||||
|
||||
return target;
|
||||
}
|
||||
exports.extend = extend;
|
||||
|
||||
// Common wrapper for all Unix-like commands
|
||||
function wrap(cmd, fn, options) {
|
||||
return function() {
|
||||
var retValue = null;
|
||||
|
||||
state.currentCmd = cmd;
|
||||
state.error = null;
|
||||
state.errorCode = 0;
|
||||
|
||||
try {
|
||||
var args = [].slice.call(arguments, 0);
|
||||
|
||||
if (config.verbose) {
|
||||
args.unshift(cmd);
|
||||
console.error.apply(console, args);
|
||||
args.shift();
|
||||
}
|
||||
|
||||
if (options && options.notUnix) {
|
||||
retValue = fn.apply(this, args);
|
||||
} else {
|
||||
if (args[0] instanceof Object && args[0].constructor.name === 'Object') {
|
||||
args = args; // object count as options
|
||||
} else if (args.length === 0 || typeof args[0] !== 'string' || args[0].length <= 1 || args[0][0] !== '-') {
|
||||
args.unshift(''); // only add dummy option if '-option' not already present
|
||||
}
|
||||
|
||||
args = args.reduce(function(accum, cur) {
|
||||
if (Array.isArray(cur)) {
|
||||
return accum.concat(cur);
|
||||
} else {
|
||||
accum.push(cur);
|
||||
return accum;
|
||||
}
|
||||
}, []);
|
||||
// Convert ShellStrings to regular strings
|
||||
args = args.map(function(arg) {
|
||||
if (arg instanceof Object && arg.constructor.name === 'String') {
|
||||
return arg.toString();
|
||||
} else
|
||||
return arg;
|
||||
});
|
||||
// Expand the '~' if appropriate
|
||||
var homeDir = getUserHome();
|
||||
args = args.map(function(arg) {
|
||||
if (typeof arg === 'string' && arg.slice(0, 2) === '~/' || arg === '~')
|
||||
return arg.replace(/^~/, homeDir);
|
||||
else
|
||||
return arg;
|
||||
});
|
||||
if (!config.noglob && options && typeof options.idx === 'number')
|
||||
args = args.slice(0, options.idx).concat(expand(args.slice(options.idx)));
|
||||
try {
|
||||
retValue = fn.apply(this, args);
|
||||
} catch (e) {
|
||||
if (e.msg === 'earlyExit')
|
||||
retValue = e.retValue;
|
||||
else throw e;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (!state.error) {
|
||||
// If state.error hasn't been set it's an error thrown by Node, not us - probably a bug...
|
||||
console.error('shell.js: internal error');
|
||||
console.error(e.stack || e);
|
||||
process.exit(1);
|
||||
}
|
||||
if (config.fatal)
|
||||
throw e;
|
||||
}
|
||||
|
||||
state.currentCmd = 'shell.js';
|
||||
return retValue;
|
||||
};
|
||||
} // wrap
|
||||
exports.wrap = wrap;
|
||||
|
||||
function _readFromPipe(that) {
|
||||
return that instanceof String ? that.toString() : '';
|
||||
}
|
||||
exports.readFromPipe = _readFromPipe;
|
252
node_modules/shelljs/src/cp.js
generated
vendored
Normal file
252
node_modules/shelljs/src/cp.js
generated
vendored
Normal file
@ -0,0 +1,252 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var common = require('./common');
|
||||
var os = require('os');
|
||||
|
||||
// Buffered file copy, synchronous
|
||||
// (Using readFileSync() + writeFileSync() could easily cause a memory overflow
|
||||
// with large files)
|
||||
function copyFileSync(srcFile, destFile, options) {
|
||||
if (!fs.existsSync(srcFile))
|
||||
common.error('copyFileSync: no such file or directory: ' + srcFile);
|
||||
|
||||
if (fs.lstatSync(srcFile).isSymbolicLink() && !options.followsymlink) {
|
||||
try {
|
||||
fs.lstatSync(destFile);
|
||||
common.unlinkSync(destFile); // re-link it
|
||||
} catch (e) {
|
||||
// it doesn't exist, so no work needs to be done
|
||||
}
|
||||
|
||||
var symlinkFull = fs.readlinkSync(srcFile);
|
||||
fs.symlinkSync(symlinkFull, destFile, os.platform() === "win32" ? "junction" : null);
|
||||
} else {
|
||||
var BUF_LENGTH = 64*1024,
|
||||
buf = new Buffer(BUF_LENGTH),
|
||||
bytesRead = BUF_LENGTH,
|
||||
pos = 0,
|
||||
fdr = null,
|
||||
fdw = null;
|
||||
|
||||
try {
|
||||
fdr = fs.openSync(srcFile, 'r');
|
||||
} catch(e) {
|
||||
common.error('copyFileSync: could not read src file ('+srcFile+')');
|
||||
}
|
||||
|
||||
try {
|
||||
fdw = fs.openSync(destFile, 'w');
|
||||
} catch(e) {
|
||||
common.error('copyFileSync: could not write to dest file (code='+e.code+'):'+destFile);
|
||||
}
|
||||
|
||||
while (bytesRead === BUF_LENGTH) {
|
||||
bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
|
||||
fs.writeSync(fdw, buf, 0, bytesRead);
|
||||
pos += bytesRead;
|
||||
}
|
||||
|
||||
fs.closeSync(fdr);
|
||||
fs.closeSync(fdw);
|
||||
|
||||
fs.chmodSync(destFile, fs.statSync(srcFile).mode);
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively copies 'sourceDir' into 'destDir'
|
||||
// Adapted from https://github.com/ryanmcgrath/wrench-js
|
||||
//
|
||||
// Copyright (c) 2010 Ryan McGrath
|
||||
// Copyright (c) 2012 Artur Adib
|
||||
//
|
||||
// Licensed under the MIT License
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
function cpdirSyncRecursive(sourceDir, destDir, opts) {
|
||||
if (!opts) opts = {};
|
||||
|
||||
/* Ensure there is not a run away recursive copy. */
|
||||
if (typeof opts.depth === 'undefined') {
|
||||
opts.depth = 0;
|
||||
}
|
||||
if (opts.depth >= common.config.maxdepth) {
|
||||
// Max depth has been reached, end copy.
|
||||
return;
|
||||
} else {
|
||||
opts.depth++;
|
||||
}
|
||||
|
||||
/* Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */
|
||||
try {
|
||||
var checkDir = fs.statSync(sourceDir);
|
||||
fs.mkdirSync(destDir, checkDir.mode);
|
||||
} catch (e) {
|
||||
//if the directory already exists, that's okay
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
}
|
||||
|
||||
var files = fs.readdirSync(sourceDir);
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var srcFile = sourceDir + "/" + files[i];
|
||||
var destFile = destDir + "/" + files[i];
|
||||
var srcFileStat = fs.lstatSync(srcFile);
|
||||
|
||||
var symlinkFull;
|
||||
if (opts.followsymlink) {
|
||||
if (cpcheckcycle(sourceDir, srcFile)) {
|
||||
// Cycle link found.
|
||||
console.error('Cycle link found.');
|
||||
symlinkFull = fs.readlinkSync(srcFile);
|
||||
fs.symlinkSync(symlinkFull, destFile, os.platform() === "win32" ? "junction" : null);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (srcFileStat.isDirectory()) {
|
||||
/* recursion this thing right on back. */
|
||||
cpdirSyncRecursive(srcFile, destFile, opts);
|
||||
} else if (srcFileStat.isSymbolicLink() && !opts.followsymlink) {
|
||||
symlinkFull = fs.readlinkSync(srcFile);
|
||||
try {
|
||||
fs.lstatSync(destFile);
|
||||
common.unlinkSync(destFile); // re-link it
|
||||
} catch (e) {
|
||||
// it doesn't exist, so no work needs to be done
|
||||
}
|
||||
fs.symlinkSync(symlinkFull, destFile, os.platform() === "win32" ? "junction" : null);
|
||||
} else if (srcFileStat.isSymbolicLink() && opts.followsymlink) {
|
||||
srcFileStat = fs.statSync(srcFile);
|
||||
if (srcFileStat.isDirectory()) {
|
||||
cpdirSyncRecursive(srcFile, destFile, opts);
|
||||
} else {
|
||||
copyFileSync(srcFile, destFile, opts);
|
||||
}
|
||||
} else {
|
||||
/* At this point, we've hit a file actually worth copying... so copy it on over. */
|
||||
if (fs.existsSync(destFile) && opts.no_force) {
|
||||
common.log('skipping existing file: ' + files[i]);
|
||||
} else {
|
||||
copyFileSync(srcFile, destFile, opts);
|
||||
}
|
||||
}
|
||||
|
||||
} // for files
|
||||
} // cpdirSyncRecursive
|
||||
|
||||
function cpcheckcycle(sourceDir, srcFile) {
|
||||
var srcFileStat = fs.lstatSync(srcFile);
|
||||
if (srcFileStat.isSymbolicLink()) {
|
||||
// Do cycle check. For example mkdir -p 1/2/3/4 ; cd 1/2/3/4; ln -s ../../3 link ; cd ../../../.. ; cp -RL 1 copy
|
||||
var cyclecheck = fs.statSync(srcFile);
|
||||
if (cyclecheck.isDirectory()) {
|
||||
var sourcerealpath = fs.realpathSync(sourceDir);
|
||||
var symlinkrealpath = fs.realpathSync(srcFile);
|
||||
var re = new RegExp(symlinkrealpath);
|
||||
if (re.test(sourcerealpath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### cp([options,] source [, source ...], dest)
|
||||
//@ ### cp([options,] source_array, dest)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-f`: force (default behavior)
|
||||
//@ + `-n`: no-clobber
|
||||
//@ + `-r`, `-R`: recursive
|
||||
//@ + `-L`: follow symlinks
|
||||
//@ + `-P`: don't follow symlinks
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ cp('file1', 'dir1');
|
||||
//@ cp('-R', 'path/to/dir/', '~/newCopy/');
|
||||
//@ cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp');
|
||||
//@ cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Copies files.
|
||||
function _cp(options, sources, dest) {
|
||||
options = common.parseOptions(options, {
|
||||
'f': '!no_force',
|
||||
'n': 'no_force',
|
||||
'R': 'recursive',
|
||||
'r': 'recursive',
|
||||
'L': 'followsymlink',
|
||||
'P': 'noFollowsymlink',
|
||||
});
|
||||
|
||||
// If we're missing -R, it actually implies -L (unless -P is explicit)
|
||||
if (options.followsymlink)
|
||||
options.noFollowsymlink = false;
|
||||
if (!options.recursive && !options.noFollowsymlink)
|
||||
options.followsymlink = true;
|
||||
|
||||
// Get sources, dest
|
||||
if (arguments.length < 3) {
|
||||
common.error('missing <source> and/or <dest>');
|
||||
} else {
|
||||
sources = [].slice.call(arguments, 1, arguments.length - 1);
|
||||
dest = arguments[arguments.length - 1];
|
||||
}
|
||||
|
||||
var destExists = fs.existsSync(dest),
|
||||
destStat = destExists && fs.statSync(dest);
|
||||
|
||||
// Dest is not existing dir, but multiple sources given
|
||||
if ((!destExists || !destStat.isDirectory()) && sources.length > 1)
|
||||
common.error('dest is not a directory (too many sources)');
|
||||
|
||||
// Dest is an existing file, but -n is given
|
||||
if (destExists && destStat.isFile() && options.no_force)
|
||||
common.error('dest file already exists: ' + dest);
|
||||
|
||||
sources.forEach(function(src) {
|
||||
if (!fs.existsSync(src)) {
|
||||
common.error('no such file or directory: '+src, true);
|
||||
return; // skip file
|
||||
}
|
||||
var srcStat = fs.statSync(src);
|
||||
if (!options.noFollowsymlink && srcStat.isDirectory()) {
|
||||
if (!options.recursive) {
|
||||
// Non-Recursive
|
||||
common.error("omitting directory '" + src + "'", true);
|
||||
} else {
|
||||
// Recursive
|
||||
// 'cp /a/source dest' should create 'source' in 'dest'
|
||||
var newDest = (destStat && destStat.isDirectory()) ?
|
||||
path.join(dest, path.basename(src)) :
|
||||
dest;
|
||||
|
||||
try {
|
||||
fs.statSync(path.dirname(dest));
|
||||
cpdirSyncRecursive(src, newDest, {no_force: options.no_force, followsymlink: options.followsymlink});
|
||||
} catch(e) {
|
||||
common.error("cannot create directory '" + dest + "': No such file or directory");
|
||||
}
|
||||
}
|
||||
return; // done with dir
|
||||
} else {
|
||||
// If here, src is a file
|
||||
|
||||
// When copying to '/path/dir':
|
||||
// thisDest = '/path/dir/file1'
|
||||
var thisDest = dest;
|
||||
if (destStat && destStat.isDirectory())
|
||||
thisDest = path.normalize(dest + '/' + path.basename(src));
|
||||
|
||||
if (fs.existsSync(thisDest) && options.no_force) {
|
||||
common.error('dest file already exists: ' + thisDest, true);
|
||||
return; // skip file
|
||||
}
|
||||
|
||||
copyFileSync(src, thisDest, options);
|
||||
}
|
||||
}); // forEach(src)
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _cp;
|
191
node_modules/shelljs/src/dirs.js
generated
vendored
Normal file
191
node_modules/shelljs/src/dirs.js
generated
vendored
Normal file
@ -0,0 +1,191 @@
|
||||
var common = require('./common');
|
||||
var _cd = require('./cd');
|
||||
var path = require('path');
|
||||
|
||||
// Pushd/popd/dirs internals
|
||||
var _dirStack = [];
|
||||
|
||||
function _isStackIndex(index) {
|
||||
return (/^[\-+]\d+$/).test(index);
|
||||
}
|
||||
|
||||
function _parseStackIndex(index) {
|
||||
if (_isStackIndex(index)) {
|
||||
if (Math.abs(index) < _dirStack.length + 1) { // +1 for pwd
|
||||
return (/^-/).test(index) ? Number(index) - 1 : Number(index);
|
||||
} else {
|
||||
common.error(index + ': directory stack index out of range');
|
||||
}
|
||||
} else {
|
||||
common.error(index + ': invalid number');
|
||||
}
|
||||
}
|
||||
|
||||
function _actualDirStack() {
|
||||
return [process.cwd()].concat(_dirStack);
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### 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.
|
||||
function _pushd(options, dir) {
|
||||
if (_isStackIndex(options)) {
|
||||
dir = options;
|
||||
options = '';
|
||||
}
|
||||
|
||||
options = common.parseOptions(options, {
|
||||
'n' : 'no-cd'
|
||||
});
|
||||
|
||||
var dirs = _actualDirStack();
|
||||
|
||||
if (dir === '+0') {
|
||||
return dirs; // +0 is a noop
|
||||
} else if (!dir) {
|
||||
if (dirs.length > 1) {
|
||||
dirs = dirs.splice(1, 1).concat(dirs);
|
||||
} else {
|
||||
return common.error('no other directory');
|
||||
}
|
||||
} else if (_isStackIndex(dir)) {
|
||||
var n = _parseStackIndex(dir);
|
||||
dirs = dirs.slice(n).concat(dirs.slice(0, n));
|
||||
} else {
|
||||
if (options['no-cd']) {
|
||||
dirs.splice(1, 0, dir);
|
||||
} else {
|
||||
dirs.unshift(dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (options['no-cd']) {
|
||||
dirs = dirs.slice(1);
|
||||
} else {
|
||||
dir = path.resolve(dirs.shift());
|
||||
_cd('', dir);
|
||||
}
|
||||
|
||||
_dirStack = dirs;
|
||||
return _dirs('');
|
||||
}
|
||||
exports.pushd = _pushd;
|
||||
|
||||
//@
|
||||
//@ ### 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.
|
||||
function _popd(options, index) {
|
||||
if (_isStackIndex(options)) {
|
||||
index = options;
|
||||
options = '';
|
||||
}
|
||||
|
||||
options = common.parseOptions(options, {
|
||||
'n' : 'no-cd'
|
||||
});
|
||||
|
||||
if (!_dirStack.length) {
|
||||
return common.error('directory stack empty');
|
||||
}
|
||||
|
||||
index = _parseStackIndex(index || '+0');
|
||||
|
||||
if (options['no-cd'] || index > 0 || _dirStack.length + index === 0) {
|
||||
index = index > 0 ? index - 1 : index;
|
||||
_dirStack.splice(index, 1);
|
||||
} else {
|
||||
var dir = path.resolve(_dirStack.shift());
|
||||
_cd('', dir);
|
||||
}
|
||||
|
||||
return _dirs('');
|
||||
}
|
||||
exports.popd = _popd;
|
||||
|
||||
//@
|
||||
//@ ### 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
|
||||
function _dirs(options, index) {
|
||||
if (_isStackIndex(options)) {
|
||||
index = options;
|
||||
options = '';
|
||||
}
|
||||
|
||||
options = common.parseOptions(options, {
|
||||
'c' : 'clear'
|
||||
});
|
||||
|
||||
if (options['clear']) {
|
||||
_dirStack = [];
|
||||
return _dirStack;
|
||||
}
|
||||
|
||||
var stack = _actualDirStack();
|
||||
|
||||
if (index) {
|
||||
index = _parseStackIndex(index);
|
||||
|
||||
if (index < 0) {
|
||||
index = stack.length + index;
|
||||
}
|
||||
|
||||
common.log(stack[index]);
|
||||
return stack[index];
|
||||
}
|
||||
|
||||
common.log(stack.join(' '));
|
||||
|
||||
return stack;
|
||||
}
|
||||
exports.dirs = _dirs;
|
21
node_modules/shelljs/src/echo.js
generated
vendored
Normal file
21
node_modules/shelljs/src/echo.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### echo(string [, string ...])
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ echo('hello world');
|
||||
//@ var str = echo('hello world');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Prints string to stdout, and returns string with additional utility methods
|
||||
//@ like `.to()`.
|
||||
function _echo(opts, messages) {
|
||||
// allow strings starting with '-', see issue #20
|
||||
messages = [].slice.call(arguments, opts ? 0 : 1);
|
||||
console.log.apply(console, messages);
|
||||
return new common.ShellString(messages.join(' '), '', 0);
|
||||
}
|
||||
module.exports = _echo;
|
14
node_modules/shelljs/src/error.js
generated
vendored
Normal file
14
node_modules/shelljs/src/error.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### error()
|
||||
//@ Tests if error occurred in the last command. Returns a truthy value if an
|
||||
//@ error returned and a falsy value otherwise.
|
||||
//@
|
||||
//@ **Note**: do not rely on the
|
||||
//@ return value to be an error message. If you need the last error message, use
|
||||
//@ the `.stderr` attribute from the last command's return value instead.
|
||||
function error() {
|
||||
return common.state.error;
|
||||
}
|
||||
module.exports = error;
|
259
node_modules/shelljs/src/exec.js
generated
vendored
Normal file
259
node_modules/shelljs/src/exec.js
generated
vendored
Normal file
@ -0,0 +1,259 @@
|
||||
var common = require('./common');
|
||||
var _tempDir = require('./tempdir');
|
||||
var _pwd = require('./pwd');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var child = require('child_process');
|
||||
|
||||
var DEFAULT_MAXBUFFER_SIZE = 20*1024*1024;
|
||||
|
||||
// Hack to run child_process.exec() synchronously (sync avoids callback hell)
|
||||
// Uses a custom wait loop that checks for a flag file, created when the child process is done.
|
||||
// (Can't do a wait loop that checks for internal Node variables/messages as
|
||||
// Node is single-threaded; callbacks and other internal state changes are done in the
|
||||
// event loop).
|
||||
function execSync(cmd, opts, pipe) {
|
||||
var tempDir = _tempDir();
|
||||
var stdoutFile = path.resolve(tempDir+'/'+common.randomFileName()),
|
||||
stderrFile = path.resolve(tempDir+'/'+common.randomFileName()),
|
||||
codeFile = path.resolve(tempDir+'/'+common.randomFileName()),
|
||||
scriptFile = path.resolve(tempDir+'/'+common.randomFileName()),
|
||||
sleepFile = path.resolve(tempDir+'/'+common.randomFileName());
|
||||
|
||||
opts = common.extend({
|
||||
silent: common.config.silent,
|
||||
cwd: _pwd().toString(),
|
||||
env: process.env,
|
||||
maxBuffer: DEFAULT_MAXBUFFER_SIZE
|
||||
}, opts);
|
||||
|
||||
var previousStdoutContent = '',
|
||||
previousStderrContent = '';
|
||||
// Echoes stdout and stderr changes from running process, if not silent
|
||||
function updateStream(streamFile) {
|
||||
if (opts.silent || !fs.existsSync(streamFile))
|
||||
return;
|
||||
|
||||
var previousStreamContent,
|
||||
proc_stream;
|
||||
if (streamFile === stdoutFile) {
|
||||
previousStreamContent = previousStdoutContent;
|
||||
proc_stream = process.stdout;
|
||||
} else { // assume stderr
|
||||
previousStreamContent = previousStderrContent;
|
||||
proc_stream = process.stderr;
|
||||
}
|
||||
|
||||
var streamContent = fs.readFileSync(streamFile, 'utf8');
|
||||
// No changes since last time?
|
||||
if (streamContent.length <= previousStreamContent.length)
|
||||
return;
|
||||
|
||||
proc_stream.write(streamContent.substr(previousStreamContent.length));
|
||||
previousStreamContent = streamContent;
|
||||
}
|
||||
|
||||
if (fs.existsSync(scriptFile)) common.unlinkSync(scriptFile);
|
||||
if (fs.existsSync(stdoutFile)) common.unlinkSync(stdoutFile);
|
||||
if (fs.existsSync(stderrFile)) common.unlinkSync(stderrFile);
|
||||
if (fs.existsSync(codeFile)) common.unlinkSync(codeFile);
|
||||
|
||||
var execCommand = JSON.stringify(process.execPath) + ' ' + JSON.stringify(scriptFile);
|
||||
var script;
|
||||
|
||||
opts.cwd = path.resolve(opts.cwd);
|
||||
var optString = JSON.stringify(opts);
|
||||
|
||||
if (typeof child.execSync === 'function') {
|
||||
script = [
|
||||
"var child = require('child_process')",
|
||||
" , fs = require('fs');",
|
||||
"var childProcess = child.exec("+JSON.stringify(cmd)+", "+optString+", function(err) {",
|
||||
" fs.writeFileSync("+JSON.stringify(codeFile)+", err ? err.code.toString() : '0');",
|
||||
"});",
|
||||
"var stdoutStream = fs.createWriteStream("+JSON.stringify(stdoutFile)+");",
|
||||
"var stderrStream = fs.createWriteStream("+JSON.stringify(stderrFile)+");",
|
||||
"childProcess.stdout.pipe(stdoutStream, {end: false});",
|
||||
"childProcess.stderr.pipe(stderrStream, {end: false});",
|
||||
"childProcess.stdout.pipe(process.stdout);",
|
||||
"childProcess.stderr.pipe(process.stderr);"
|
||||
].join('\n') +
|
||||
(pipe ? "\nchildProcess.stdin.end("+JSON.stringify(pipe)+");\n" : '\n') +
|
||||
[
|
||||
"var stdoutEnded = false, stderrEnded = false;",
|
||||
"function tryClosingStdout(){ if(stdoutEnded){ stdoutStream.end(); } }",
|
||||
"function tryClosingStderr(){ if(stderrEnded){ stderrStream.end(); } }",
|
||||
"childProcess.stdout.on('end', function(){ stdoutEnded = true; tryClosingStdout(); });",
|
||||
"childProcess.stderr.on('end', function(){ stderrEnded = true; tryClosingStderr(); });"
|
||||
].join('\n');
|
||||
|
||||
fs.writeFileSync(scriptFile, script);
|
||||
|
||||
if (opts.silent) {
|
||||
opts.stdio = 'ignore';
|
||||
} else {
|
||||
opts.stdio = [0, 1, 2];
|
||||
}
|
||||
|
||||
// Welcome to the future
|
||||
try {
|
||||
child.execSync(execCommand, opts);
|
||||
} catch (e) {
|
||||
// Clean up immediately if we have an exception
|
||||
try { common.unlinkSync(scriptFile); } catch(e) {}
|
||||
try { common.unlinkSync(stdoutFile); } catch(e) {}
|
||||
try { common.unlinkSync(stderrFile); } catch(e) {}
|
||||
try { common.unlinkSync(codeFile); } catch(e) {}
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
cmd += ' > '+stdoutFile+' 2> '+stderrFile; // works on both win/unix
|
||||
|
||||
script = [
|
||||
"var child = require('child_process')",
|
||||
" , fs = require('fs');",
|
||||
"var childProcess = child.exec("+JSON.stringify(cmd)+", "+optString+", function(err) {",
|
||||
" fs.writeFileSync("+JSON.stringify(codeFile)+", err ? err.code.toString() : '0');",
|
||||
"});"
|
||||
].join('\n') +
|
||||
(pipe ? "\nchildProcess.stdin.end("+JSON.stringify(pipe)+");\n" : '\n');
|
||||
|
||||
fs.writeFileSync(scriptFile, script);
|
||||
|
||||
child.exec(execCommand, opts);
|
||||
|
||||
// The wait loop
|
||||
// sleepFile is used as a dummy I/O op to mitigate unnecessary CPU usage
|
||||
// (tried many I/O sync ops, writeFileSync() seems to be only one that is effective in reducing
|
||||
// CPU usage, though apparently not so much on Windows)
|
||||
while (!fs.existsSync(codeFile)) { updateStream(stdoutFile); fs.writeFileSync(sleepFile, 'a'); }
|
||||
while (!fs.existsSync(stdoutFile)) { updateStream(stdoutFile); fs.writeFileSync(sleepFile, 'a'); }
|
||||
while (!fs.existsSync(stderrFile)) { updateStream(stderrFile); fs.writeFileSync(sleepFile, 'a'); }
|
||||
try { common.unlinkSync(sleepFile); } catch(e) {}
|
||||
}
|
||||
|
||||
// At this point codeFile exists, but it's not necessarily flushed yet.
|
||||
// Keep reading it until it is.
|
||||
var code = parseInt('', 10);
|
||||
while (isNaN(code)) {
|
||||
code = parseInt(fs.readFileSync(codeFile, 'utf8'), 10);
|
||||
}
|
||||
|
||||
var stdout = fs.readFileSync(stdoutFile, 'utf8');
|
||||
var stderr = fs.readFileSync(stderrFile, 'utf8');
|
||||
|
||||
// No biggie if we can't erase the files now -- they're in a temp dir anyway
|
||||
try { common.unlinkSync(scriptFile); } catch(e) {}
|
||||
try { common.unlinkSync(stdoutFile); } catch(e) {}
|
||||
try { common.unlinkSync(stderrFile); } catch(e) {}
|
||||
try { common.unlinkSync(codeFile); } catch(e) {}
|
||||
|
||||
if (code !== 0) {
|
||||
common.error('', code, true);
|
||||
}
|
||||
var obj = common.ShellString(stdout, stderr, code);
|
||||
return obj;
|
||||
} // execSync()
|
||||
|
||||
// Wrapper around exec() to enable echoing output to console in real time
|
||||
function execAsync(cmd, opts, pipe, callback) {
|
||||
var stdout = '';
|
||||
var stderr = '';
|
||||
|
||||
opts = common.extend({
|
||||
silent: common.config.silent,
|
||||
cwd: _pwd().toString(),
|
||||
env: process.env,
|
||||
maxBuffer: DEFAULT_MAXBUFFER_SIZE
|
||||
}, opts);
|
||||
|
||||
var c = child.exec(cmd, opts, function(err) {
|
||||
if (callback)
|
||||
callback(err ? err.code : 0, stdout, stderr);
|
||||
});
|
||||
|
||||
if (pipe)
|
||||
c.stdin.end(pipe);
|
||||
|
||||
c.stdout.on('data', function(data) {
|
||||
stdout += data;
|
||||
if (!opts.silent)
|
||||
process.stdout.write(data);
|
||||
});
|
||||
|
||||
c.stderr.on('data', function(data) {
|
||||
stderr += data;
|
||||
if (!opts.silent)
|
||||
process.stderr.write(data);
|
||||
});
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### exec(command [, options] [, callback])
|
||||
//@ Available options (all `false` by default):
|
||||
//@
|
||||
//@ + `async`: Asynchronous execution. If a callback is provided, it will be set to
|
||||
//@ `true`, regardless of the passed value.
|
||||
//@ + `silent`: Do not echo program output to console.
|
||||
//@ + and any option available to NodeJS's
|
||||
//@ [child_process.exec()](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var version = exec('node --version', {silent:true}).stdout;
|
||||
//@
|
||||
//@ var child = exec('some_long_running_process', {async:true});
|
||||
//@ child.stdout.on('data', function(data) {
|
||||
//@ /* ... do something with data ... */
|
||||
//@ });
|
||||
//@
|
||||
//@ exec('some_long_running_process', function(code, stdout, stderr) {
|
||||
//@ console.log('Exit code:', code);
|
||||
//@ console.log('Program output:', stdout);
|
||||
//@ console.log('Program stderr:', stderr);
|
||||
//@ });
|
||||
//@ ```
|
||||
//@
|
||||
//@ Executes the given `command` _synchronously_, unless otherwise specified. When in synchronous
|
||||
//@ mode, this returns a ShellString (compatible with ShellJS v0.6.x, which returns an object
|
||||
//@ of the form `{ code:..., stdout:... , stderr:... }`). Otherwise, this returns the child process
|
||||
//@ object, and the `callback` gets the arguments `(code, stdout, stderr)`.
|
||||
//@
|
||||
//@ **Note:** For long-lived processes, it's best to run `exec()` asynchronously as
|
||||
//@ the current synchronous implementation uses a lot of CPU. This should be getting
|
||||
//@ fixed soon.
|
||||
function _exec(command, options, callback) {
|
||||
if (!command)
|
||||
common.error('must specify command');
|
||||
|
||||
var pipe = common.readFromPipe(this);
|
||||
|
||||
// Callback is defined instead of options.
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = { async: true };
|
||||
}
|
||||
|
||||
// Callback is defined with options.
|
||||
if (typeof options === 'object' && typeof callback === 'function') {
|
||||
options.async = true;
|
||||
}
|
||||
|
||||
options = common.extend({
|
||||
silent: common.config.silent,
|
||||
async: false
|
||||
}, options);
|
||||
|
||||
try {
|
||||
if (options.async)
|
||||
return execAsync(command, options, pipe, callback);
|
||||
else
|
||||
return execSync(command, options, pipe);
|
||||
} catch (e) {
|
||||
common.error('internal error');
|
||||
}
|
||||
}
|
||||
module.exports = _exec;
|
51
node_modules/shelljs/src/find.js
generated
vendored
Normal file
51
node_modules/shelljs/src/find.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var common = require('./common');
|
||||
var _ls = require('./ls');
|
||||
|
||||
//@
|
||||
//@ ### find(path [, path ...])
|
||||
//@ ### find(path_array)
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ find('src', 'lib');
|
||||
//@ find(['src', 'lib']); // same as above
|
||||
//@ find('.').filter(function(file) { return file.match(/\.js$/); });
|
||||
//@ ```
|
||||
//@
|
||||
//@ Returns array of all files (however deep) in the given paths.
|
||||
//@
|
||||
//@ 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`.
|
||||
function _find(options, paths) {
|
||||
if (!paths)
|
||||
common.error('no path specified');
|
||||
else if (typeof paths === 'string')
|
||||
paths = [].slice.call(arguments, 1);
|
||||
|
||||
var list = [];
|
||||
|
||||
function pushFile(file) {
|
||||
if (common.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) {
|
||||
pushFile(file);
|
||||
|
||||
if (fs.statSync(file).isDirectory()) {
|
||||
_ls('-RA', file).forEach(function(subfile) {
|
||||
pushFile(path.join(file, subfile));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return new common.ShellString(list, common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _find;
|
61
node_modules/shelljs/src/grep.js
generated
vendored
Normal file
61
node_modules/shelljs/src/grep.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
//@
|
||||
//@ ### grep([options,] regex_filter, file [, file ...])
|
||||
//@ ### grep([options,] regex_filter, file_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-v`: Inverse the sense of the regex and print the lines not matching the criteria.
|
||||
//@ + `-l`: Print only filenames of matching files
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ grep('-v', 'GLOBAL_VARIABLE', '*.js');
|
||||
//@ grep('GLOBAL_VARIABLE', '*.js');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Reads input string from given files and returns a string containing all lines of the
|
||||
//@ file that match the given `regex_filter`.
|
||||
function _grep(options, regex, files) {
|
||||
options = common.parseOptions(options, {
|
||||
'v': 'inverse',
|
||||
'l': 'nameOnly'
|
||||
});
|
||||
|
||||
// Check if this is coming from a pipe
|
||||
var pipe = common.readFromPipe(this);
|
||||
|
||||
if (!files && !pipe)
|
||||
common.error('no paths given', 2);
|
||||
|
||||
files = [].slice.call(arguments, 2);
|
||||
|
||||
if (pipe)
|
||||
files.unshift('-');
|
||||
|
||||
var grep = [];
|
||||
files.forEach(function(file) {
|
||||
if (!fs.existsSync(file) && file !== '-') {
|
||||
common.error('no such file or directory: ' + file, 2, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var contents = file === '-' ? pipe : fs.readFileSync(file, 'utf8');
|
||||
var lines = contents.split(/\r*\n/);
|
||||
if (options.nameOnly) {
|
||||
if (contents.match(regex))
|
||||
grep.push(file);
|
||||
} else {
|
||||
lines.forEach(function(line) {
|
||||
var matched = line.match(regex);
|
||||
if ((options.inverse && !matched) || (!options.inverse && matched))
|
||||
grep.push(line);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return new common.ShellString(grep.join('\n')+'\n', common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _grep;
|
96
node_modules/shelljs/src/head.js
generated
vendored
Normal file
96
node_modules/shelljs/src/head.js
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
// This reads n or more lines, or the entire file, whichever is less.
|
||||
function readSomeLines(file, numLines) {
|
||||
var BUF_LENGTH = 64*1024,
|
||||
buf = new Buffer(BUF_LENGTH),
|
||||
bytesRead = BUF_LENGTH,
|
||||
pos = 0,
|
||||
fdr = null;
|
||||
|
||||
try {
|
||||
fdr = fs.openSync(file, 'r');
|
||||
} catch(e) {
|
||||
common.error('cannot read file: ' + file);
|
||||
}
|
||||
|
||||
var numLinesRead = 0;
|
||||
var ret = '';
|
||||
while (bytesRead === BUF_LENGTH && numLinesRead < numLines) {
|
||||
bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
|
||||
var bufStr = buf.toString('utf8', 0, bytesRead);
|
||||
numLinesRead += bufStr.split('\n').length - 1;
|
||||
ret += bufStr;
|
||||
pos += bytesRead;
|
||||
}
|
||||
|
||||
fs.closeSync(fdr);
|
||||
return ret;
|
||||
}
|
||||
//@
|
||||
//@ ### head([{'-n', \<num\>},] file [, file ...])
|
||||
//@ ### head([{'-n', \<num\>},] file_array)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var str = head({'-n', 1}, 'file*.txt');
|
||||
//@ var str = head('file1', 'file2');
|
||||
//@ var str = head(['file1', 'file2']); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Output the first 10 lines of a file (or the first `<num>` if `-n` is
|
||||
//@ specified)
|
||||
function _head(options, files) {
|
||||
options = common.parseOptions(options, {
|
||||
'n': 'numLines'
|
||||
});
|
||||
var head = [];
|
||||
var pipe = common.readFromPipe(this);
|
||||
|
||||
if (!files && !pipe)
|
||||
common.error('no paths given');
|
||||
|
||||
var idx = 1;
|
||||
if (options.numLines === true) {
|
||||
idx = 2;
|
||||
options.numLines = Number(arguments[1]);
|
||||
} else if (options.numLines === false) {
|
||||
options.numLines = 10;
|
||||
}
|
||||
files = [].slice.call(arguments, idx);
|
||||
|
||||
if (pipe)
|
||||
files.unshift('-');
|
||||
|
||||
var shouldAppendNewline = false;
|
||||
files.forEach(function(file) {
|
||||
if (!fs.existsSync(file) && file !== '-') {
|
||||
common.error('no such file or directory: ' + file, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var contents;
|
||||
if (file === '-')
|
||||
contents = pipe;
|
||||
else if (options.numLines < 0) {
|
||||
contents = fs.readFileSync(file, 'utf8');
|
||||
} else {
|
||||
contents = readSomeLines(file, options.numLines);
|
||||
}
|
||||
|
||||
var lines = contents.split('\n');
|
||||
var hasTrailingNewline = (lines[lines.length-1] === '');
|
||||
if (hasTrailingNewline)
|
||||
lines.pop();
|
||||
shouldAppendNewline = (hasTrailingNewline || options.numLines < lines.length);
|
||||
|
||||
head = head.concat(lines.slice(0, options.numLines));
|
||||
});
|
||||
|
||||
if (shouldAppendNewline)
|
||||
head.push(''); // to add a trailing newline once we join
|
||||
return new common.ShellString(head.join('\n'), common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _head;
|
70
node_modules/shelljs/src/ln.js
generated
vendored
Normal file
70
node_modules/shelljs/src/ln.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### ln([options,] source, dest)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-s`: symlink
|
||||
//@ + `-f`: force
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ ln('file', 'newlink');
|
||||
//@ ln('-sf', 'file', 'existing');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Links source to dest. Use -f to force the link, should dest already exist.
|
||||
function _ln(options, source, dest) {
|
||||
options = common.parseOptions(options, {
|
||||
's': 'symlink',
|
||||
'f': 'force'
|
||||
});
|
||||
|
||||
if (!source || !dest) {
|
||||
common.error('Missing <source> and/or <dest>');
|
||||
}
|
||||
|
||||
source = String(source);
|
||||
var sourcePath = path.normalize(source).replace(RegExp(path.sep + '$'), '');
|
||||
var isAbsolute = (path.resolve(source) === sourcePath);
|
||||
dest = path.resolve(process.cwd(), String(dest));
|
||||
|
||||
if (fs.existsSync(dest)) {
|
||||
if (!options.force) {
|
||||
common.error('Destination file exists', true);
|
||||
}
|
||||
|
||||
fs.unlinkSync(dest);
|
||||
}
|
||||
|
||||
if (options.symlink) {
|
||||
var isWindows = common.platform === 'win';
|
||||
var linkType = isWindows ? 'file' : null;
|
||||
var resolvedSourcePath = isAbsolute ? sourcePath : path.resolve(process.cwd(), path.dirname(dest), source);
|
||||
if (!fs.existsSync(resolvedSourcePath)) {
|
||||
common.error('Source file does not exist', true);
|
||||
} else if (isWindows && fs.statSync(resolvedSourcePath).isDirectory()) {
|
||||
linkType = 'junction';
|
||||
}
|
||||
|
||||
try {
|
||||
fs.symlinkSync(linkType === 'junction' ? resolvedSourcePath: source, dest, linkType);
|
||||
} catch (err) {
|
||||
common.error(err.message);
|
||||
}
|
||||
} else {
|
||||
if (!fs.existsSync(source)) {
|
||||
common.error('Source file does not exist', true);
|
||||
}
|
||||
try {
|
||||
fs.linkSync(source, dest);
|
||||
} catch (err) {
|
||||
common.error(err.message);
|
||||
}
|
||||
}
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _ln;
|
116
node_modules/shelljs/src/ls.js
generated
vendored
Normal file
116
node_modules/shelljs/src/ls.js
generated
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var common = require('./common');
|
||||
var glob = require('glob');
|
||||
|
||||
var globPatternRecursive = path.sep + '**' + path.sep + '*';
|
||||
|
||||
//@
|
||||
//@ ### ls([options,] [path, ...])
|
||||
//@ ### ls([options,] path_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-R`: recursive
|
||||
//@ + `-A`: all files (include files beginning with `.`, except for `.` and `..`)
|
||||
//@ + `-d`: list directories themselves, not their contents
|
||||
//@ + `-l`: list objects representing each file, each with fields containing `ls
|
||||
//@ -l` output fields. See
|
||||
//@ [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
//@ for more info
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ ls('projs/*.js');
|
||||
//@ ls('-R', '/users/me', '/tmp');
|
||||
//@ ls('-R', ['/users/me', '/tmp']); // same as above
|
||||
//@ ls('-l', 'file.txt'); // { name: 'file.txt', mode: 33188, nlink: 1, ...}
|
||||
//@ ```
|
||||
//@
|
||||
//@ Returns array of files in the given path, or in current directory if no path provided.
|
||||
function _ls(options, paths) {
|
||||
options = common.parseOptions(options, {
|
||||
'R': 'recursive',
|
||||
'A': 'all',
|
||||
'a': 'all_deprecated',
|
||||
'd': 'directory',
|
||||
'l': 'long'
|
||||
});
|
||||
|
||||
if (options.all_deprecated) {
|
||||
// We won't support the -a option as it's hard to image why it's useful
|
||||
// (it includes '.' and '..' in addition to '.*' files)
|
||||
// For backwards compatibility we'll dump a deprecated message and proceed as before
|
||||
common.log('ls: Option -a is deprecated. Use -A instead');
|
||||
options.all = true;
|
||||
}
|
||||
|
||||
if (!paths)
|
||||
paths = ['.'];
|
||||
else
|
||||
paths = [].slice.call(arguments, 1);
|
||||
|
||||
var list = [];
|
||||
|
||||
function pushFile(abs, relName, stat) {
|
||||
if (process.platform === 'win32')
|
||||
relName = relName.replace(/\\/g, '/');
|
||||
if (options.long) {
|
||||
stat = stat || fs.lstatSync(abs);
|
||||
list.push(addLsAttributes(relName, stat));
|
||||
} else {
|
||||
// list.push(path.relative(rel || '.', file));
|
||||
list.push(relName);
|
||||
}
|
||||
}
|
||||
|
||||
paths.forEach(function(p) {
|
||||
var stat;
|
||||
|
||||
try {
|
||||
stat = fs.lstatSync(p);
|
||||
} catch (e) {
|
||||
common.error('no such file or directory: ' + p, 2, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the stat succeeded
|
||||
if (stat.isDirectory() && !options.directory) {
|
||||
if (options.recursive) {
|
||||
// use glob, because it's simple
|
||||
glob.sync(p + globPatternRecursive, { dot: options.all })
|
||||
.forEach(function (item) {
|
||||
pushFile(item, path.relative(p, item));
|
||||
});
|
||||
} else if (options.all) {
|
||||
// use fs.readdirSync, because it's fast
|
||||
fs.readdirSync(p).forEach(function (item) {
|
||||
pushFile(path.join(p, item), item);
|
||||
});
|
||||
} else {
|
||||
// use fs.readdirSync and then filter out secret files
|
||||
fs.readdirSync(p).forEach(function (item) {
|
||||
if (item[0] !== '.')
|
||||
pushFile(path.join(p, item), item);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
pushFile(p, p, stat);
|
||||
}
|
||||
});
|
||||
|
||||
// Add methods, to make this more compatible with ShellStrings
|
||||
return new common.ShellString(list, common.state.error, common.state.errorCode);
|
||||
}
|
||||
|
||||
function addLsAttributes(path, stats) {
|
||||
// Note: this object will contain more information than .toString() returns
|
||||
stats.name = path;
|
||||
stats.toString = function() {
|
||||
// Return a string resembling unix's `ls -l` format
|
||||
return [this.mode, this.nlink, this.uid, this.gid, this.size, this.mtime, this.name].join(' ');
|
||||
};
|
||||
return stats;
|
||||
}
|
||||
|
||||
module.exports = _ls;
|
72
node_modules/shelljs/src/mkdir.js
generated
vendored
Normal file
72
node_modules/shelljs/src/mkdir.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
// Recursively creates 'dir'
|
||||
function mkdirSyncRecursive(dir) {
|
||||
var baseDir = path.dirname(dir);
|
||||
|
||||
// Base dir exists, no recursion necessary
|
||||
if (fs.existsSync(baseDir)) {
|
||||
fs.mkdirSync(dir, parseInt('0777', 8));
|
||||
return;
|
||||
}
|
||||
|
||||
// Base dir does not exist, go recursive
|
||||
mkdirSyncRecursive(baseDir);
|
||||
|
||||
// Base dir created, can create dir
|
||||
fs.mkdirSync(dir, parseInt('0777', 8));
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### mkdir([options,] dir [, dir ...])
|
||||
//@ ### mkdir([options,] dir_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-p`: full path (will create intermediate dirs if necessary)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g');
|
||||
//@ mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Creates directories.
|
||||
function _mkdir(options, dirs) {
|
||||
options = common.parseOptions(options, {
|
||||
'p': 'fullpath'
|
||||
});
|
||||
if (!dirs)
|
||||
common.error('no paths given');
|
||||
|
||||
if (typeof dirs === 'string')
|
||||
dirs = [].slice.call(arguments, 1);
|
||||
// if it's array leave it as it is
|
||||
|
||||
dirs.forEach(function(dir) {
|
||||
try {
|
||||
fs.lstatSync(dir);
|
||||
if (!options.fullpath)
|
||||
common.error('path already exists: ' + dir, true);
|
||||
return; // skip dir
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// Base dir does not exist, and no -p option given
|
||||
var baseDir = path.dirname(dir);
|
||||
if (!fs.existsSync(baseDir) && !options.fullpath) {
|
||||
common.error('no such file or directory: ' + baseDir, true);
|
||||
return; // skip dir
|
||||
}
|
||||
|
||||
if (options.fullpath)
|
||||
mkdirSyncRecursive(dir);
|
||||
else
|
||||
fs.mkdirSync(dir, parseInt('0777', 8));
|
||||
});
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
} // mkdir
|
||||
module.exports = _mkdir;
|
79
node_modules/shelljs/src/mv.js
generated
vendored
Normal file
79
node_modules/shelljs/src/mv.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### mv([options ,] source [, source ...], dest')
|
||||
//@ ### mv([options ,] source_array, dest')
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-f`: force (default behavior)
|
||||
//@ + `-n`: no-clobber
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ mv('-n', 'file', 'dir/');
|
||||
//@ mv('file1', 'file2', 'dir/');
|
||||
//@ mv(['file1', 'file2'], 'dir/'); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Moves files.
|
||||
function _mv(options, sources, dest) {
|
||||
options = common.parseOptions(options, {
|
||||
'f': '!no_force',
|
||||
'n': 'no_force'
|
||||
});
|
||||
|
||||
// Get sources, dest
|
||||
if (arguments.length < 3) {
|
||||
common.error('missing <source> and/or <dest>');
|
||||
} else if (arguments.length > 3) {
|
||||
sources = [].slice.call(arguments, 1, arguments.length - 1);
|
||||
dest = arguments[arguments.length - 1];
|
||||
} else if (typeof sources === 'string') {
|
||||
sources = [sources];
|
||||
} else {
|
||||
common.error('invalid arguments');
|
||||
}
|
||||
|
||||
var exists = fs.existsSync(dest),
|
||||
stats = exists && fs.statSync(dest);
|
||||
|
||||
// Dest is not existing dir, but multiple sources given
|
||||
if ((!exists || !stats.isDirectory()) && sources.length > 1)
|
||||
common.error('dest is not a directory (too many sources)');
|
||||
|
||||
// Dest is an existing file, but no -f given
|
||||
if (exists && stats.isFile() && options.no_force)
|
||||
common.error('dest file already exists: ' + dest);
|
||||
|
||||
sources.forEach(function(src) {
|
||||
if (!fs.existsSync(src)) {
|
||||
common.error('no such file or directory: '+src, true);
|
||||
return; // skip file
|
||||
}
|
||||
|
||||
// If here, src exists
|
||||
|
||||
// When copying to '/path/dir':
|
||||
// thisDest = '/path/dir/file1'
|
||||
var thisDest = dest;
|
||||
if (fs.existsSync(dest) && fs.statSync(dest).isDirectory())
|
||||
thisDest = path.normalize(dest + '/' + path.basename(src));
|
||||
|
||||
if (fs.existsSync(thisDest) && options.no_force) {
|
||||
common.error('dest file already exists: ' + thisDest, true);
|
||||
return; // skip file
|
||||
}
|
||||
|
||||
if (path.resolve(src) === path.dirname(path.resolve(thisDest))) {
|
||||
common.error('cannot move to self: '+src, true);
|
||||
return; // skip file
|
||||
}
|
||||
|
||||
fs.renameSync(src, thisDest);
|
||||
}); // forEach(src)
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
} // mv
|
||||
module.exports = _mv;
|
1
node_modules/shelljs/src/popd.js
generated
vendored
Normal file
1
node_modules/shelljs/src/popd.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
// see dirs.js
|
1
node_modules/shelljs/src/pushd.js
generated
vendored
Normal file
1
node_modules/shelljs/src/pushd.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
// see dirs.js
|
11
node_modules/shelljs/src/pwd.js
generated
vendored
Normal file
11
node_modules/shelljs/src/pwd.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
var path = require('path');
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### pwd()
|
||||
//@ Returns the current directory.
|
||||
function _pwd() {
|
||||
var pwd = path.resolve(process.cwd());
|
||||
return new common.ShellString(pwd, '', common.state.errorCode);
|
||||
}
|
||||
module.exports = _pwd;
|
150
node_modules/shelljs/src/rm.js
generated
vendored
Normal file
150
node_modules/shelljs/src/rm.js
generated
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
// Recursively removes 'dir'
|
||||
// Adapted from https://github.com/ryanmcgrath/wrench-js
|
||||
//
|
||||
// Copyright (c) 2010 Ryan McGrath
|
||||
// Copyright (c) 2012 Artur Adib
|
||||
//
|
||||
// Licensed under the MIT License
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
function rmdirSyncRecursive(dir, force) {
|
||||
var files;
|
||||
|
||||
files = fs.readdirSync(dir);
|
||||
|
||||
// Loop through and delete everything in the sub-tree after checking it
|
||||
for(var i = 0; i < files.length; i++) {
|
||||
var file = dir + "/" + files[i],
|
||||
currFile = fs.lstatSync(file);
|
||||
|
||||
if(currFile.isDirectory()) { // Recursive function back to the beginning
|
||||
rmdirSyncRecursive(file, force);
|
||||
} else { // Assume it's a file - perhaps a try/catch belongs here?
|
||||
if (force || isWriteable(file)) {
|
||||
try {
|
||||
common.unlinkSync(file);
|
||||
} catch (e) {
|
||||
common.error('could not remove file (code '+e.code+'): ' + file, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we know everything in the sub-tree has been deleted, we can delete the main directory.
|
||||
// Huzzah for the shopkeep.
|
||||
|
||||
var result;
|
||||
try {
|
||||
// Retry on windows, sometimes it takes a little time before all the files in the directory are gone
|
||||
var start = Date.now();
|
||||
while (true) {
|
||||
try {
|
||||
result = fs.rmdirSync(dir);
|
||||
if (fs.existsSync(dir)) throw { code: "EAGAIN" };
|
||||
break;
|
||||
} catch(er) {
|
||||
// In addition to error codes, also check if the directory still exists and loop again if true
|
||||
if (process.platform === "win32" && (er.code === "ENOTEMPTY" || er.code === "EBUSY" || er.code === "EPERM" || er.code === "EAGAIN")) {
|
||||
if (Date.now() - start > 1000) throw er;
|
||||
} else if (er.code === "ENOENT") {
|
||||
// Directory did not exist, deletion was successful
|
||||
break;
|
||||
} else {
|
||||
throw er;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
common.error('could not remove directory (code '+e.code+'): ' + dir, true);
|
||||
}
|
||||
|
||||
return result;
|
||||
} // rmdirSyncRecursive
|
||||
|
||||
// Hack to determine if file has write permissions for current user
|
||||
// Avoids having to check user, group, etc, but it's probably slow
|
||||
function isWriteable(file) {
|
||||
var writePermission = true;
|
||||
try {
|
||||
var __fd = fs.openSync(file, 'a');
|
||||
fs.closeSync(__fd);
|
||||
} catch(e) {
|
||||
writePermission = false;
|
||||
}
|
||||
|
||||
return writePermission;
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### rm([options,] file [, file ...])
|
||||
//@ ### rm([options,] file_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-f`: force
|
||||
//@ + `-r, -R`: recursive
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ rm('-rf', '/tmp/*');
|
||||
//@ rm('some_file.txt', 'another_file.txt');
|
||||
//@ rm(['some_file.txt', 'another_file.txt']); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Removes files.
|
||||
function _rm(options, files) {
|
||||
options = common.parseOptions(options, {
|
||||
'f': 'force',
|
||||
'r': 'recursive',
|
||||
'R': 'recursive'
|
||||
});
|
||||
if (!files)
|
||||
common.error('no paths given');
|
||||
|
||||
// Convert to array
|
||||
files = [].slice.call(arguments, 1);
|
||||
|
||||
files.forEach(function(file) {
|
||||
var stats;
|
||||
try {
|
||||
stats = fs.lstatSync(file); // test for existence
|
||||
} catch (e) {
|
||||
// Path does not exist, no force flag given
|
||||
if (!options.force)
|
||||
common.error('no such file or directory: '+file, true);
|
||||
return; // skip file
|
||||
}
|
||||
|
||||
// If here, path exists
|
||||
if (stats.isFile() || stats.isSymbolicLink()) {
|
||||
|
||||
// Do not check for file writing permissions
|
||||
if (options.force) {
|
||||
common.unlinkSync(file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isWriteable(file))
|
||||
common.unlinkSync(file);
|
||||
else
|
||||
common.error('permission denied: '+file, true);
|
||||
|
||||
return;
|
||||
} // simple file
|
||||
|
||||
// Path is an existing directory, but no -r flag given
|
||||
if (stats.isDirectory() && !options.recursive) {
|
||||
common.error('path is a directory', true);
|
||||
return; // skip path
|
||||
}
|
||||
|
||||
// Recursively remove existing directory
|
||||
if (stats.isDirectory() && options.recursive) {
|
||||
rmdirSyncRecursive(file, options.force);
|
||||
}
|
||||
}); // forEach(file)
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
} // rm
|
||||
module.exports = _rm;
|
68
node_modules/shelljs/src/sed.js
generated
vendored
Normal file
68
node_modules/shelljs/src/sed.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
//@
|
||||
//@ ### sed([options,] search_regex, replacement, file [, file ...])
|
||||
//@ ### sed([options,] search_regex, replacement, file_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');
|
||||
//@ sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Reads an input string from `files` and performs a JavaScript `replace()` on the input
|
||||
//@ using the given search regex and replacement string or function. Returns the new string after replacement.
|
||||
function _sed(options, regex, replacement, files) {
|
||||
options = common.parseOptions(options, {
|
||||
'i': 'inplace'
|
||||
});
|
||||
|
||||
// Check if this is coming from a pipe
|
||||
var pipe = common.readFromPipe(this);
|
||||
|
||||
if (typeof replacement === 'string' || typeof replacement === 'function')
|
||||
replacement = replacement; // no-op
|
||||
else if (typeof replacement === 'number')
|
||||
replacement = replacement.toString(); // fallback
|
||||
else
|
||||
common.error('invalid replacement string');
|
||||
|
||||
// Convert all search strings to RegExp
|
||||
if (typeof regex === 'string')
|
||||
regex = RegExp(regex);
|
||||
|
||||
if (!files && !pipe)
|
||||
common.error('no files given');
|
||||
|
||||
files = [].slice.call(arguments, 3);
|
||||
|
||||
if (pipe)
|
||||
files.unshift('-');
|
||||
|
||||
var sed = [];
|
||||
files.forEach(function(file) {
|
||||
if (!fs.existsSync(file) && file !== '-') {
|
||||
common.error('no such file or directory: ' + file, 2, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var contents = file === '-' ? pipe : fs.readFileSync(file, 'utf8');
|
||||
var lines = contents.split(/\r*\n/);
|
||||
var result = lines.map(function (line) {
|
||||
return line.replace(regex, replacement);
|
||||
}).join('\n');
|
||||
|
||||
sed.push(result);
|
||||
|
||||
if (options.inplace)
|
||||
fs.writeFileSync(file, result, 'utf8');
|
||||
});
|
||||
|
||||
return new common.ShellString(sed.join('\n'), common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _sed;
|
51
node_modules/shelljs/src/set.js
generated
vendored
Normal file
51
node_modules/shelljs/src/set.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
var common = require('./common');
|
||||
|
||||
//@
|
||||
//@ ### set(options)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `+/-e`: exit upon error (`config.fatal`)
|
||||
//@ + `+/-v`: verbose: show all commands (`config.verbose`)
|
||||
//@ + `+/-f`: disable filename expansion (globbing)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ set('-e'); // exit upon first error
|
||||
//@ set('+e'); // this undoes a "set('-e')"
|
||||
//@ ```
|
||||
//@
|
||||
//@ Sets global configuration variables
|
||||
function _set(options) {
|
||||
if (!options) {
|
||||
var args = [].slice.call(arguments, 0);
|
||||
if (args.length < 2)
|
||||
common.error('must provide an argument');
|
||||
options = args[1];
|
||||
}
|
||||
var negate = (options[0] === '+');
|
||||
if (negate) {
|
||||
options = '-' + options.slice(1); // parseOptions needs a '-' prefix
|
||||
}
|
||||
options = common.parseOptions(options, {
|
||||
'e': 'fatal',
|
||||
'v': 'verbose',
|
||||
'f': 'noglob'
|
||||
});
|
||||
|
||||
var key;
|
||||
if (negate) {
|
||||
for (key in options)
|
||||
options[key] = !options[key];
|
||||
}
|
||||
|
||||
for (key in options) {
|
||||
// Only change the global config if `negate` is false and the option is true
|
||||
// or if `negate` is true and the option is false (aka negate !== option)
|
||||
if (negate !== options[key]) {
|
||||
common.config[key] = options[key];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
module.exports = _set;
|
87
node_modules/shelljs/src/sort.js
generated
vendored
Normal file
87
node_modules/shelljs/src/sort.js
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
// parse out the number prefix of a line
|
||||
function parseNumber (str) {
|
||||
var match = str.match(/^\s*(\d*)\s*(.*)$/);
|
||||
return {num: Number(match[1]), value: match[2]};
|
||||
}
|
||||
|
||||
// compare two strings case-insensitively, but examine case for strings that are
|
||||
// case-insensitive equivalent
|
||||
function unixCmp(a, b) {
|
||||
var aLower = a.toLowerCase();
|
||||
var bLower = b.toLowerCase();
|
||||
return (aLower === bLower ?
|
||||
-1 * a.localeCompare(b) : // unix sort treats case opposite how javascript does
|
||||
aLower.localeCompare(bLower));
|
||||
}
|
||||
|
||||
// compare two strings in the fashion that unix sort's -n option works
|
||||
function numericalCmp(a, b) {
|
||||
var objA = parseNumber(a);
|
||||
var objB = parseNumber(b);
|
||||
if (objA.hasOwnProperty('num') && objB.hasOwnProperty('num')) {
|
||||
return ((objA.num !== objB.num) ?
|
||||
(objA.num - objB.num) :
|
||||
unixCmp(objA.value, objB.value));
|
||||
} else {
|
||||
return unixCmp(objA.value, objB.value);
|
||||
}
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### sort([options,] file [, file ...])
|
||||
//@ ### sort([options,] file_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-r`: Reverse the result of comparisons
|
||||
//@ + `-n`: Compare according to numerical value
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ sort('foo.txt', 'bar.txt');
|
||||
//@ sort('-r', 'foo.txt');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Return the contents of the files, sorted line-by-line. Sorting multiple
|
||||
//@ files mixes their content, just like unix sort does.
|
||||
function _sort(options, files) {
|
||||
options = common.parseOptions(options, {
|
||||
'r': 'reverse',
|
||||
'n': 'numerical'
|
||||
});
|
||||
|
||||
// Check if this is coming from a pipe
|
||||
var pipe = common.readFromPipe(this);
|
||||
|
||||
if (!files && !pipe)
|
||||
common.error('no files given');
|
||||
|
||||
files = [].slice.call(arguments, 1);
|
||||
|
||||
if (pipe)
|
||||
files.unshift('-');
|
||||
|
||||
var lines = [];
|
||||
files.forEach(function(file) {
|
||||
if (!fs.existsSync(file) && file !== '-') {
|
||||
// exit upon any sort of error
|
||||
common.error('no such file or directory: ' + file);
|
||||
}
|
||||
|
||||
var contents = file === '-' ? pipe : fs.readFileSync(file, 'utf8');
|
||||
lines = lines.concat(contents.trimRight().split(/\r*\n/));
|
||||
});
|
||||
|
||||
var sorted;
|
||||
sorted = lines.sort(options.numerical ? numericalCmp : unixCmp);
|
||||
|
||||
if (options.reverse)
|
||||
sorted = sorted.reverse();
|
||||
|
||||
return new common.ShellString(sorted.join('\n')+'\n', common.state.error, common.state.errorCode);
|
||||
}
|
||||
|
||||
module.exports = _sort;
|
65
node_modules/shelljs/src/tail.js
generated
vendored
Normal file
65
node_modules/shelljs/src/tail.js
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
//@
|
||||
//@ ### tail([{'-n', \<num\>},] file [, file ...])
|
||||
//@ ### tail([{'-n', \<num\>},] file_array)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var str = tail({'-n', 1}, 'file*.txt');
|
||||
//@ var str = tail('file1', 'file2');
|
||||
//@ var str = tail(['file1', 'file2']); // same as above
|
||||
//@ ```
|
||||
//@
|
||||
//@ Output the last 10 lines of a file (or the last `<num>` if `-n` is
|
||||
//@ specified)
|
||||
function _tail(options, files) {
|
||||
options = common.parseOptions(options, {
|
||||
'n': 'numLines'
|
||||
});
|
||||
var tail = [];
|
||||
var pipe = common.readFromPipe(this);
|
||||
|
||||
if (!files && !pipe)
|
||||
common.error('no paths given');
|
||||
|
||||
var idx = 1;
|
||||
if (options.numLines === true) {
|
||||
idx = 2;
|
||||
options.numLines = Number(arguments[1]);
|
||||
} else if (options.numLines === false) {
|
||||
options.numLines = 10;
|
||||
}
|
||||
options.numLines = -1 * Math.abs(options.numLines);
|
||||
files = [].slice.call(arguments, idx);
|
||||
|
||||
if (pipe)
|
||||
files.unshift('-');
|
||||
|
||||
var shouldAppendNewline = false;
|
||||
files.forEach(function(file) {
|
||||
if (!fs.existsSync(file) && file !== '-') {
|
||||
common.error('no such file or directory: ' + file, true);
|
||||
return;
|
||||
}
|
||||
|
||||
var contents = file === '-' ? pipe : fs.readFileSync(file, 'utf8');
|
||||
|
||||
var lines = contents.split('\n');
|
||||
if (lines[lines.length-1] === '') {
|
||||
lines.pop();
|
||||
shouldAppendNewline = true;
|
||||
} else {
|
||||
shouldAppendNewline = false;
|
||||
}
|
||||
|
||||
tail = tail.concat(lines.slice(options.numLines));
|
||||
});
|
||||
|
||||
if (shouldAppendNewline)
|
||||
tail.push(''); // to add a trailing newline once we join
|
||||
return new common.ShellString(tail.join('\n'), common.state.error, common.state.errorCode);
|
||||
}
|
||||
module.exports = _tail;
|
57
node_modules/shelljs/src/tempdir.js
generated
vendored
Normal file
57
node_modules/shelljs/src/tempdir.js
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
var common = require('./common');
|
||||
var os = require('os');
|
||||
var fs = require('fs');
|
||||
|
||||
// Returns false if 'dir' is not a writeable directory, 'dir' otherwise
|
||||
function writeableDir(dir) {
|
||||
if (!dir || !fs.existsSync(dir))
|
||||
return false;
|
||||
|
||||
if (!fs.statSync(dir).isDirectory())
|
||||
return false;
|
||||
|
||||
var testFile = dir+'/'+common.randomFileName();
|
||||
try {
|
||||
fs.writeFileSync(testFile, ' ');
|
||||
common.unlinkSync(testFile);
|
||||
return dir;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
//@ ### tempdir()
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var tmp = tempdir(); // "/tmp" for most *nix platforms
|
||||
//@ ```
|
||||
//@
|
||||
//@ Searches and returns string containing a writeable, platform-dependent temporary directory.
|
||||
//@ Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
||||
function _tempDir() {
|
||||
var state = common.state;
|
||||
if (state.tempDir)
|
||||
return state.tempDir; // from cache
|
||||
|
||||
state.tempDir = writeableDir(os.tmpdir && os.tmpdir()) || // node 0.10+
|
||||
writeableDir(os.tmpDir && os.tmpDir()) || // node 0.8+
|
||||
writeableDir(process.env['TMPDIR']) ||
|
||||
writeableDir(process.env['TEMP']) ||
|
||||
writeableDir(process.env['TMP']) ||
|
||||
writeableDir(process.env['Wimp$ScrapDir']) || // RiscOS
|
||||
writeableDir('C:\\TEMP') || // Windows
|
||||
writeableDir('C:\\TMP') || // Windows
|
||||
writeableDir('\\TEMP') || // Windows
|
||||
writeableDir('\\TMP') || // Windows
|
||||
writeableDir('/tmp') ||
|
||||
writeableDir('/var/tmp') ||
|
||||
writeableDir('/usr/tmp') ||
|
||||
writeableDir('.'); // last resort
|
||||
|
||||
return state.tempDir;
|
||||
}
|
||||
module.exports = _tempDir;
|
85
node_modules/shelljs/src/test.js
generated
vendored
Normal file
85
node_modules/shelljs/src/test.js
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
//@
|
||||
//@ ### test(expression)
|
||||
//@ Available expression primaries:
|
||||
//@
|
||||
//@ + `'-b', 'path'`: true if path is a block device
|
||||
//@ + `'-c', 'path'`: true if path is a character device
|
||||
//@ + `'-d', 'path'`: true if path is a directory
|
||||
//@ + `'-e', 'path'`: true if path exists
|
||||
//@ + `'-f', 'path'`: true if path is a regular file
|
||||
//@ + `'-L', 'path'`: true if path is a symbolic link
|
||||
//@ + `'-p', 'path'`: true if path is a pipe (FIFO)
|
||||
//@ + `'-S', 'path'`: true if path is a socket
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ if (test('-d', path)) { /* do something with dir */ };
|
||||
//@ if (!test('-f', path)) continue; // skip if it's a regular file
|
||||
//@ ```
|
||||
//@
|
||||
//@ Evaluates expression using the available primaries and returns corresponding value.
|
||||
function _test(options, path) {
|
||||
if (!path)
|
||||
common.error('no path given');
|
||||
|
||||
// hack - only works with unary primaries
|
||||
options = common.parseOptions(options, {
|
||||
'b': 'block',
|
||||
'c': 'character',
|
||||
'd': 'directory',
|
||||
'e': 'exists',
|
||||
'f': 'file',
|
||||
'L': 'link',
|
||||
'p': 'pipe',
|
||||
'S': 'socket'
|
||||
});
|
||||
|
||||
var canInterpret = false;
|
||||
for (var key in options)
|
||||
if (options[key] === true) {
|
||||
canInterpret = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!canInterpret)
|
||||
common.error('could not interpret expression');
|
||||
|
||||
if (options.link) {
|
||||
try {
|
||||
return fs.lstatSync(path).isSymbolicLink();
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path))
|
||||
return false;
|
||||
|
||||
if (options.exists)
|
||||
return true;
|
||||
|
||||
var stats = fs.statSync(path);
|
||||
|
||||
if (options.block)
|
||||
return stats.isBlockDevice();
|
||||
|
||||
if (options.character)
|
||||
return stats.isCharacterDevice();
|
||||
|
||||
if (options.directory)
|
||||
return stats.isDirectory();
|
||||
|
||||
if (options.file)
|
||||
return stats.isFile();
|
||||
|
||||
if (options.pipe)
|
||||
return stats.isFIFO();
|
||||
|
||||
if (options.socket)
|
||||
return stats.isSocket();
|
||||
} // test
|
||||
module.exports = _test;
|
31
node_modules/shelljs/src/to.js
generated
vendored
Normal file
31
node_modules/shelljs/src/to.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
//@
|
||||
//@ ### ShellString.prototype.to(file)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ cat('input.txt').to('output.txt');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Analogous to the redirection operator `>` in Unix, but works with
|
||||
//@ ShellStrings (such as those returned by `cat`, `grep`, etc). _Like Unix
|
||||
//@ redirections, `to()` will overwrite any existing file!_
|
||||
function _to(options, file) {
|
||||
if (!file)
|
||||
common.error('wrong arguments');
|
||||
|
||||
if (!fs.existsSync( path.dirname(file) ))
|
||||
common.error('no such file or directory: ' + path.dirname(file));
|
||||
|
||||
try {
|
||||
fs.writeFileSync(file, this.toString(), 'utf8');
|
||||
return this;
|
||||
} catch(e) {
|
||||
common.error('could not write to file (code '+e.code+'): '+file, true);
|
||||
}
|
||||
}
|
||||
module.exports = _to;
|
30
node_modules/shelljs/src/toEnd.js
generated
vendored
Normal file
30
node_modules/shelljs/src/toEnd.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
//@
|
||||
//@ ### ShellString.prototype.toEnd(file)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ cat('input.txt').toEnd('output.txt');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Analogous to the redirect-and-append operator `>>` in Unix, but works with
|
||||
//@ ShellStrings (such as those returned by `cat`, `grep`, etc).
|
||||
function _toEnd(options, file) {
|
||||
if (!file)
|
||||
common.error('wrong arguments');
|
||||
|
||||
if (!fs.existsSync( path.dirname(file) ))
|
||||
common.error('no such file or directory: ' + path.dirname(file));
|
||||
|
||||
try {
|
||||
fs.appendFileSync(file, this.toString(), 'utf8');
|
||||
return this;
|
||||
} catch(e) {
|
||||
common.error('could not append to file (code '+e.code+'): '+file, true);
|
||||
}
|
||||
}
|
||||
module.exports = _toEnd;
|
107
node_modules/shelljs/src/touch.js
generated
vendored
Normal file
107
node_modules/shelljs/src/touch.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
|
||||
//@
|
||||
//@ ### touch([options,] file [, file ...])
|
||||
//@ ### touch([options,] file_array)
|
||||
//@ Available options:
|
||||
//@
|
||||
//@ + `-a`: Change only the access time
|
||||
//@ + `-c`: Do not create any files
|
||||
//@ + `-m`: Change only the modification time
|
||||
//@ + `-d DATE`: Parse DATE and use it instead of current time
|
||||
//@ + `-r FILE`: Use FILE's times instead of current time
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ touch('source.js');
|
||||
//@ touch('-c', '/path/to/some/dir/source.js');
|
||||
//@ touch({ '-r': FILE }, '/path/to/some/dir/source.js');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Update the access and modification times of each FILE to the current time.
|
||||
//@ A FILE argument that does not exist is created empty, unless -c is supplied.
|
||||
//@ This is a partial implementation of *[touch(1)](http://linux.die.net/man/1/touch)*.
|
||||
function _touch(opts, files) {
|
||||
opts = common.parseOptions(opts, {
|
||||
'a': 'atime_only',
|
||||
'c': 'no_create',
|
||||
'd': 'date',
|
||||
'm': 'mtime_only',
|
||||
'r': 'reference',
|
||||
});
|
||||
|
||||
if (!files)
|
||||
common.error('no files given');
|
||||
else if (typeof files === 'string')
|
||||
files = [].slice.call(arguments, 1);
|
||||
else
|
||||
common.error('file arg should be a string file path or an Array of string file paths');
|
||||
|
||||
files.forEach(function(f) {
|
||||
touchFile(opts, f);
|
||||
});
|
||||
return new common.ShellString('', common.state.error, common.state.errorCode);
|
||||
}
|
||||
|
||||
function touchFile(opts, file) {
|
||||
var stat = tryStatFile(file);
|
||||
|
||||
if (stat && stat.isDirectory()) {
|
||||
// don't error just exit
|
||||
return;
|
||||
}
|
||||
|
||||
// if the file doesn't already exist and the user has specified --no-create then
|
||||
// this script is finished
|
||||
if (!stat && opts.no_create) {
|
||||
return;
|
||||
}
|
||||
|
||||
// open the file and then close it. this will create it if it doesn't exist but will
|
||||
// not truncate the file
|
||||
fs.closeSync(fs.openSync(file, 'a'));
|
||||
|
||||
//
|
||||
// Set timestamps
|
||||
//
|
||||
|
||||
// setup some defaults
|
||||
var now = new Date();
|
||||
var mtime = opts.date || now;
|
||||
var atime = opts.date || now;
|
||||
|
||||
// use reference file
|
||||
if (opts.reference) {
|
||||
var refStat = tryStatFile(opts.reference);
|
||||
if (!refStat) {
|
||||
common.error('failed to get attributess of ' + opts.reference);
|
||||
}
|
||||
mtime = refStat.mtime;
|
||||
atime = refStat.atime;
|
||||
} else if (opts.date) {
|
||||
mtime = opts.date;
|
||||
atime = opts.date;
|
||||
}
|
||||
|
||||
if (opts.atime_only && opts.mtime_only) {
|
||||
// keep the new values of mtime and atime like GNU
|
||||
} else if (opts.atime_only) {
|
||||
mtime = stat.mtime;
|
||||
} else if (opts.mtime_only) {
|
||||
atime = stat.atime;
|
||||
}
|
||||
|
||||
fs.utimesSync(file, atime, mtime);
|
||||
}
|
||||
|
||||
module.exports = _touch;
|
||||
|
||||
function tryStatFile(filePath) {
|
||||
try {
|
||||
return fs.statSync(filePath);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
98
node_modules/shelljs/src/which.js
generated
vendored
Normal file
98
node_modules/shelljs/src/which.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
var common = require('./common');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
// XP's system default value for PATHEXT system variable, just in case it's not
|
||||
// set on Windows.
|
||||
var XP_DEFAULT_PATHEXT = '.com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh';
|
||||
|
||||
// Cross-platform method for splitting environment PATH variables
|
||||
function splitPath(p) {
|
||||
if (!p)
|
||||
return [];
|
||||
|
||||
if (common.platform === 'win')
|
||||
return p.split(';');
|
||||
else
|
||||
return p.split(':');
|
||||
}
|
||||
|
||||
function checkPath(path) {
|
||||
return fs.existsSync(path) && !fs.statSync(path).isDirectory();
|
||||
}
|
||||
|
||||
//@
|
||||
//@ ### which(command)
|
||||
//@
|
||||
//@ Examples:
|
||||
//@
|
||||
//@ ```javascript
|
||||
//@ var nodeExec = which('node');
|
||||
//@ ```
|
||||
//@
|
||||
//@ Searches for `command` in the system's PATH. On Windows, this uses the
|
||||
//@ `PATHEXT` variable to append the extension if it's not already executable.
|
||||
//@ Returns string containing the absolute path to the command.
|
||||
function _which(options, cmd) {
|
||||
if (!cmd)
|
||||
common.error('must specify command');
|
||||
|
||||
var pathEnv = process.env.path || process.env.Path || process.env.PATH,
|
||||
pathArray = splitPath(pathEnv),
|
||||
where = null;
|
||||
|
||||
// No relative/absolute paths provided?
|
||||
if (cmd.search(/\//) === -1) {
|
||||
// Search for command in PATH
|
||||
pathArray.forEach(function(dir) {
|
||||
if (where)
|
||||
return; // already found it
|
||||
|
||||
var attempt = path.resolve(dir, cmd);
|
||||
|
||||
if (common.platform === 'win') {
|
||||
attempt = attempt.toUpperCase();
|
||||
|
||||
// In case the PATHEXT variable is somehow not set (e.g.
|
||||
// child_process.spawn with an empty environment), use the XP default.
|
||||
var pathExtEnv = process.env.PATHEXT || XP_DEFAULT_PATHEXT;
|
||||
var pathExtArray = splitPath(pathExtEnv.toUpperCase());
|
||||
var i;
|
||||
|
||||
// If the extension is already in PATHEXT, just return that.
|
||||
for (i = 0; i < pathExtArray.length; i++) {
|
||||
var ext = pathExtArray[i];
|
||||
if (attempt.slice(-ext.length) === ext && checkPath(attempt)) {
|
||||
where = attempt;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle through the PATHEXT variable
|
||||
var baseAttempt = attempt;
|
||||
for (i = 0; i < pathExtArray.length; i++) {
|
||||
attempt = baseAttempt + pathExtArray[i];
|
||||
if (checkPath(attempt)) {
|
||||
where = attempt;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Assume it's Unix-like
|
||||
if (checkPath(attempt)) {
|
||||
where = attempt;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Command not found anywhere?
|
||||
if (!checkPath(cmd) && !where)
|
||||
return null;
|
||||
|
||||
where = where || path.resolve(cmd);
|
||||
|
||||
return new common.ShellString(where, '', common.state.errorCode);
|
||||
}
|
||||
module.exports = _which;
|
Reference in New Issue
Block a user