selenium
This commit is contained in:
28
node_modules/exeq/.npmignore
generated
vendored
Normal file
28
node_modules/exeq/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
*.iml
|
||||
.idea/
|
||||
.ipr
|
||||
.iws
|
||||
*~
|
||||
~*
|
||||
*.diff
|
||||
*.patch
|
||||
*.bak
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
.project
|
||||
.*proj
|
||||
.svn/
|
||||
*.swp
|
||||
*.swo
|
||||
*.log
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
node_modules/
|
||||
dist/
|
||||
tmp/
|
||||
.spm-build
|
||||
.buildpath
|
||||
.settings
|
||||
.yml
|
||||
_site
|
||||
example.js
|
||||
5
node_modules/exeq/.travis.yml
generated
vendored
Normal file
5
node_modules/exeq/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "4"
|
||||
- "5"
|
||||
18
node_modules/exeq/LICENSE
generated
vendored
Normal file
18
node_modules/exeq/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
140
node_modules/exeq/README.md
generated
vendored
Normal file
140
node_modules/exeq/README.md
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
# exeq
|
||||
|
||||
Excute shell commands in queue.
|
||||
|
||||
[](https://npmjs.org/package/exeq)
|
||||
[](https://travis-ci.org/afc163/exeq)
|
||||
[](https://david-dm.org/afc163/exeq)
|
||||
[](https://npmjs.org/package/exeq)
|
||||
|
||||
---
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
$ npm install exeq --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### exeq()
|
||||
|
||||
```js
|
||||
exeq(
|
||||
'mkdir example',
|
||||
'rm -rf example'
|
||||
);
|
||||
```
|
||||
|
||||
### Promise `2.0.0+`
|
||||
|
||||
```js
|
||||
// promise
|
||||
exeq(
|
||||
'mkdir example',
|
||||
'cd example',
|
||||
'touch README.md',
|
||||
'touch somefile',
|
||||
'rm somefile',
|
||||
'ls -l',
|
||||
'cd ..',
|
||||
'rm -rf example',
|
||||
'ls -l > output.txt'
|
||||
).then(function() {
|
||||
console.log('done!');
|
||||
}).catch(function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
```
|
||||
|
||||
### Array
|
||||
|
||||
```js
|
||||
exeq([
|
||||
'mkdir example',
|
||||
'rm -rf example'
|
||||
]);
|
||||
```
|
||||
|
||||
### stdout & stderr
|
||||
|
||||
```js
|
||||
exeq(
|
||||
'echo 123',
|
||||
'echo 456',
|
||||
'echo 789'
|
||||
).then(function(results) {
|
||||
console.log(results[0].stdout); // '123'
|
||||
console.log(results[1].stdout); // '456'
|
||||
console.log(results[2].stdout); // '789'
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
exeq(
|
||||
'not-existed-command'
|
||||
).then(function(results) {
|
||||
}).catch(function(err) {
|
||||
console.log(err); // { code: '127', stderr: ' ... ' }
|
||||
});
|
||||
```
|
||||
|
||||
### change cwd
|
||||
|
||||
```js
|
||||
// cd command would change spawn cwd automatically
|
||||
// create README.md in example
|
||||
exeq(
|
||||
'mkdir example',
|
||||
'cd example',
|
||||
'touch README.md'
|
||||
);
|
||||
```
|
||||
|
||||
### Kill the execution
|
||||
|
||||
```js
|
||||
var proc = exeq([
|
||||
'echo 1',
|
||||
'sleep 10',
|
||||
'echo 2'
|
||||
]);
|
||||
proc.q.kill();
|
||||
```
|
||||
|
||||
### Events
|
||||
|
||||
```js
|
||||
var proc = exeq([
|
||||
'echo 1',
|
||||
'echo 2'
|
||||
]);
|
||||
|
||||
proc.q.on('stdour', function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
proc.q.on('stderr', function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
proc.q.on('killed', function(reason) {
|
||||
console.log(reason);
|
||||
});
|
||||
|
||||
proc.q.on('done', function() {
|
||||
});
|
||||
|
||||
proc.q.on('failed', function() {
|
||||
});
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
$ npm test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
138
node_modules/exeq/index.js
generated
vendored
Normal file
138
node_modules/exeq/index.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var inherits = require('util').inherits;
|
||||
var spawn = require('child_process').spawn;
|
||||
var path = require('path');
|
||||
var Promise = require('native-or-bluebird');
|
||||
var platform = require('os').platform();
|
||||
|
||||
function Exeq(commands) {
|
||||
EventEmitter.call(this);
|
||||
this.commands = commands || [];
|
||||
this.cwd = '';
|
||||
this.results = [];
|
||||
|
||||
var instance = new Promise(this.run.bind(this));
|
||||
instance.q = this;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
inherits(Exeq, EventEmitter);
|
||||
|
||||
Exeq.prototype.run = function(resolve, reject) {
|
||||
|
||||
var that = this;
|
||||
|
||||
var stdout = new Buffer('');
|
||||
var stderr = new Buffer('');
|
||||
|
||||
// done!
|
||||
if (this.commands.length === 0) {
|
||||
this.emit('done', this.results);
|
||||
resolve(this.results);
|
||||
return;
|
||||
}
|
||||
|
||||
var cmdString = this.commands.shift();
|
||||
var parsed = parseCommand(cmdString);
|
||||
var s = this.proc = spawn(parsed.cmd, parsed.args, {
|
||||
cwd: this.cwd
|
||||
});
|
||||
|
||||
s.stdout.pipe(process.stdout);
|
||||
s.stdout.on('data', function(data) {
|
||||
that.emit('stdout', data);
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
s.stderr.pipe(process.stderr);
|
||||
s.stderr.on('data', function(data) {
|
||||
that.emit('stderr', data);
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
s.on('close', function(code, signal) {
|
||||
var reason;
|
||||
if (code) {
|
||||
reason = {
|
||||
code: code,
|
||||
stdout: stdout.toString(),
|
||||
stderr: stderr.toString()
|
||||
};
|
||||
|
||||
that.emit('failed', reason);
|
||||
return reject(reason);
|
||||
}
|
||||
|
||||
that.results.push({
|
||||
cmd: cmdString,
|
||||
stdout: stdout.toString(),
|
||||
stderr: stderr.toString()
|
||||
});
|
||||
|
||||
if (that.killed) {
|
||||
reason = {
|
||||
code: code,
|
||||
stderr: that.results.map(function(result) {
|
||||
return result.stdout.toString();
|
||||
}).join('') + 'Process has been killed.'
|
||||
};
|
||||
|
||||
if (signal) {
|
||||
reason.errno = signal;
|
||||
}
|
||||
|
||||
that.emit('killed', reason);
|
||||
return reject(reason);
|
||||
}
|
||||
|
||||
// cd /path/to
|
||||
// change cwd to /path/to
|
||||
if (parsed.changeCwd) {
|
||||
that.cwd = path.resolve(that.cwd, parsed.changeCwd);
|
||||
}
|
||||
that.run(resolve, reject);
|
||||
});
|
||||
};
|
||||
|
||||
Exeq.prototype.kill = function() {
|
||||
if (this.proc) {
|
||||
try {
|
||||
this.proc.kill('SIGTERM');
|
||||
this.killed = true;
|
||||
} catch (e) {
|
||||
if (e.errno != 'ESRCH') {
|
||||
throw (e);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = function() {
|
||||
var cmds = [], args = Array.prototype.slice.call(arguments);
|
||||
args.forEach(function(arg) {
|
||||
if (Array.isArray(arg)) {
|
||||
cmds = cmds.concat(arg);
|
||||
} else {
|
||||
cmds.push(arg);
|
||||
}
|
||||
});
|
||||
return new Exeq(cmds);
|
||||
};
|
||||
|
||||
function parseCommand(cmd) {
|
||||
cmd = cmd.trim();
|
||||
var command = (platform === 'win32' ? 'cmd.exe' : 'sh');
|
||||
var args = (platform === 'win32' ? ['/s', '/c'] : ['-c']);
|
||||
var changeCwd;
|
||||
// change cwd for "cd /path/to"
|
||||
if (/^cd\s+/.test(cmd)) {
|
||||
changeCwd = cmd.replace(/^cd\s+/, '');
|
||||
}
|
||||
return {
|
||||
cmd: command,
|
||||
args: args.concat([cmd]),
|
||||
changeCwd: changeCwd
|
||||
};
|
||||
}
|
||||
37
node_modules/exeq/package.json
generated
vendored
Normal file
37
node_modules/exeq/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "exeq",
|
||||
"version": "2.4.0",
|
||||
"description": "Excute shell commands in queue",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:afc163/exeq.git"
|
||||
},
|
||||
"author": "afc163 <afc163@gmail.com>",
|
||||
"keywords": [
|
||||
"spawn",
|
||||
"execute",
|
||||
"exec",
|
||||
"command",
|
||||
"shell",
|
||||
"promise",
|
||||
"synchronously",
|
||||
"bash",
|
||||
"kill"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 0.10.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bluebird": "^3.0.3",
|
||||
"native-or-bluebird": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"is-promise": "~1.0.1",
|
||||
"tape": "~4.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape tests/*.js"
|
||||
}
|
||||
}
|
||||
13
node_modules/exeq/tests/basic.js
generated
vendored
Normal file
13
node_modules/exeq/tests/basic.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
var isPromise = require('is-promise');
|
||||
|
||||
test('basic use', function(t) {
|
||||
|
||||
t.equal(typeof exeq, 'function');
|
||||
t.equal(isPromise(exeq()), true);
|
||||
|
||||
t.end();
|
||||
|
||||
});
|
||||
|
||||
22
node_modules/exeq/tests/cd.js
generated
vendored
Normal file
22
node_modules/exeq/tests/cd.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('cd change cwd', function(t) {
|
||||
|
||||
var tempDirName = '__temp-for-tests';
|
||||
|
||||
exeq(
|
||||
'mkdir ' + tempDirName,
|
||||
'cd ' + tempDirName,
|
||||
'pwd',
|
||||
'cd ..',
|
||||
'pwd',
|
||||
'rm -rf ' + tempDirName
|
||||
).then(function(results) {
|
||||
t.ok(results[2].stdout.indexOf(tempDirName) > -1);
|
||||
t.notOk(results[4].stdout.indexOf(tempDirName) > -1);
|
||||
t.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
17
node_modules/exeq/tests/command-name.js
generated
vendored
Normal file
17
node_modules/exeq/tests/command-name.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('command name', function(t) {
|
||||
exeq(
|
||||
[
|
||||
'ls -l',
|
||||
'cd ..'
|
||||
],
|
||||
'ps'
|
||||
).then(function(results) {
|
||||
t.equal(results[0].cmd, 'ls -l');
|
||||
t.equal(results[1].cmd, 'cd ..');
|
||||
t.equal(results[2].cmd, 'ps');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
18
node_modules/exeq/tests/count.js
generated
vendored
Normal file
18
node_modules/exeq/tests/count.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('command count', function(t) {
|
||||
|
||||
exeq(
|
||||
'cd /usr/bin',
|
||||
'cd ..',
|
||||
'cd /usr/bin'
|
||||
).then(function(results) {
|
||||
t.equal(results.length, 3);
|
||||
return exeq();
|
||||
}).then(function(results) {
|
||||
t.equal(results.length, 0);
|
||||
t.end();
|
||||
});
|
||||
|
||||
});
|
||||
16
node_modules/exeq/tests/error.js
generated
vendored
Normal file
16
node_modules/exeq/tests/error.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('catch error', function(t) {
|
||||
|
||||
exeq('not-existed-cmd').then(function(results) {
|
||||
}).catch(function(err) {
|
||||
t.equal(err.code, 127);
|
||||
t.ok(err.stderr.indexOf('not found') > -1);
|
||||
}).finally(function() {
|
||||
t.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
70
node_modules/exeq/tests/events.js
generated
vendored
Normal file
70
node_modules/exeq/tests/events.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('event done', function(t) {
|
||||
|
||||
// Keep the origin promise instance
|
||||
var proc = exeq([
|
||||
'echo 1',
|
||||
'echo 2'
|
||||
]);
|
||||
|
||||
var stdout = [];
|
||||
|
||||
proc.q.on('stdout', function(data) {
|
||||
stdout.push(data);
|
||||
});
|
||||
|
||||
proc.q.on('done', function() {
|
||||
t.equal(stdout.join(''), '1\n2\n');
|
||||
t.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('event fail', function(t) {
|
||||
|
||||
var proc = exeq([
|
||||
'fail-me'
|
||||
]);
|
||||
|
||||
var stderr = [];
|
||||
|
||||
proc.catch(function(){});
|
||||
|
||||
proc.q.on('stderr', function(data) {
|
||||
stderr.push(data);
|
||||
});
|
||||
|
||||
proc.q.on('failed', function() {
|
||||
t.ok(stderr.join('').indexOf('not found') > -1 );
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('event killed', function(t) {
|
||||
var proc = exeq([
|
||||
'echo 1',
|
||||
'sleep 10',
|
||||
'echo 2'
|
||||
]);
|
||||
|
||||
var stdout = [];
|
||||
|
||||
|
||||
proc.q.on('stdout', function(data) {
|
||||
stdout.push(data);
|
||||
});
|
||||
|
||||
proc.q.on('killed', function(data) {
|
||||
t.equal(stdout.join(''), '1\n');
|
||||
t.equal(data.stderr, '1\nProcess has been killed.');
|
||||
t.end();
|
||||
});
|
||||
|
||||
proc.catch(function(){});
|
||||
|
||||
setTimeout(function(){
|
||||
proc.q.kill();
|
||||
}, 600);
|
||||
});
|
||||
44
node_modules/exeq/tests/kill.js
generated
vendored
Normal file
44
node_modules/exeq/tests/kill.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('kill process 1', function(t) {
|
||||
|
||||
// Keep the origin promise instance
|
||||
var proc = exeq([
|
||||
'echo 1',
|
||||
'sleep 10',
|
||||
'echo 2'
|
||||
]);
|
||||
|
||||
proc.catch(function(err) {
|
||||
t.equal(err.stderr, '1\nProcess has been killed.');
|
||||
}).finally(function(){
|
||||
t.end();
|
||||
});
|
||||
|
||||
setTimeout(function(){
|
||||
proc.q.kill();
|
||||
}, 300);
|
||||
|
||||
});
|
||||
|
||||
test('kill process 2', function(t) {
|
||||
|
||||
var proc = exeq([
|
||||
'sleep 10',
|
||||
'echo 1',
|
||||
'echo 2'
|
||||
]);
|
||||
|
||||
proc.catch(function(err) {
|
||||
t.equal(err.errno, 'SIGTERM');
|
||||
t.equal(err.stderr, 'Process has been killed.');
|
||||
}).finally(function(){
|
||||
t.end();
|
||||
});
|
||||
|
||||
setTimeout(function(){
|
||||
proc.q.kill();
|
||||
}, 300);
|
||||
|
||||
});
|
||||
21
node_modules/exeq/tests/output-file.js
generated
vendored
Normal file
21
node_modules/exeq/tests/output-file.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
test('output file', function(t) {
|
||||
|
||||
var n = -1;
|
||||
|
||||
exeq(
|
||||
'ls > a.txt'
|
||||
).then(function(results) {
|
||||
t.ok(fs.existsSync(path.resolve('a.txt')));
|
||||
t.ok(fs.readFileSync('a.txt').toString().indexOf('a.txt') >= 0);
|
||||
return exeq('rm a.txt');
|
||||
}).then(function() {
|
||||
t.notOk(fs.existsSync('a.txt'));
|
||||
t.end();
|
||||
});
|
||||
|
||||
});
|
||||
22
node_modules/exeq/tests/stdout.js
generated
vendored
Normal file
22
node_modules/exeq/tests/stdout.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var test = require('tape').test;
|
||||
var exeq = require('..');
|
||||
|
||||
test('stdout', function(t) {
|
||||
|
||||
exeq(
|
||||
'echo 123',
|
||||
'echo "string"',
|
||||
'echo 456',
|
||||
'date'
|
||||
).then(function(results) {
|
||||
t.equal(results[0].stdout.trim(), '123');
|
||||
t.equal(results[1].stdout.trim(), 'string');
|
||||
t.equal(results[2].stdout.trim(), '456');
|
||||
var date = new Date(results[3].stdout.trim());
|
||||
t.notEqual(date.toString(), 'Invalid Date');
|
||||
t.end();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user