diff options
Diffstat (limited to 'node_modules/node-cmd')
| -rw-r--r-- | node_modules/node-cmd/.npmignore | 1 | ||||
| -rw-r--r-- | node_modules/node-cmd/README.md | 158 | ||||
| -rw-r--r-- | node_modules/node-cmd/cmd.js | 32 | ||||
| -rw-r--r-- | node_modules/node-cmd/commandline.js | 27 | ||||
| -rw-r--r-- | node_modules/node-cmd/example/basic.js | 28 | ||||
| -rw-r--r-- | node_modules/node-cmd/example/example.created.file | 0 | ||||
| -rw-r--r-- | node_modules/node-cmd/example/getPID.js | 4 | ||||
| -rw-r--r-- | node_modules/node-cmd/example/nodePythonTerminal.js | 27 | ||||
| -rw-r--r-- | node_modules/node-cmd/licence.md | 27 | ||||
| -rw-r--r-- | node_modules/node-cmd/package.json | 58 |
10 files changed, 362 insertions, 0 deletions
diff --git a/node_modules/node-cmd/.npmignore b/node_modules/node-cmd/.npmignore new file mode 100644 index 0000000..8a4f50a --- /dev/null +++ b/node_modules/node-cmd/.npmignore @@ -0,0 +1 @@ +/example/node-cmd/ diff --git a/node_modules/node-cmd/README.md b/node_modules/node-cmd/README.md new file mode 100644 index 0000000..3afbf7a --- /dev/null +++ b/node_modules/node-cmd/README.md @@ -0,0 +1,158 @@ +# node-cmd + +*Node.js commandline/terminal interface.* + +Simple commandline or terminal interface to allow you to run cli or bash style commands as if you were in the terminal. + +Run commands asynchronously, and if needed can get the output as a string. + +#### NPM Stats + +npm info : +[](https://nodei.co/npm/node-cmd/) +[See npm trends and stats for node-cmd](http://npm-stat.com/charts.html?package=node-cmd&author=&from=&to=) +     + +[](https://github.com/RIAEvangelist) + +GitHub info : +   + +Package details websites : +* [GitHub.io site](http://riaevangelist.github.io/node-cmd/ "node-cmd documentation"). A prettier version of this site. +* [NPM Module](https://www.npmjs.org/package/node-cmd "node-cmd npm module"). The npm page for the node-cmd module. + +This work is licenced via the [DBAD Public Licence](http://www.dbad-license.org/). + + +# Methods + +|method | arguments | functionality | +|-------|-----------|---------------| +|run | command | runs a command asynchronously| +|get | command,callback | runs a command asynchronously, when the command is complete all of the stdout will be passed to the callback| + + +## Examples + +```javascript + + var cmd=require('node-cmd'); + + cmd.get( + 'pwd', + function(err, data, stderr){ + console.log('the current working dir is : ',data) + } + ); + + cmd.run('touch example.created.file'); + + cmd.get( + 'ls', + function(err, data, stderr){ + console.log('the current dir contains these files :\n\n',data) + } + ); + + cmd.get( + ` + git clone https://github.com/RIAEvangelist/node-cmd.git + cd node-cmd + ls + `, + function(err, data, stderr){ + if (!err) { + console.log('the node-cmd cloned dir contains these files :\n\n',data) + } else { + console.log('error', err) + } + + } + ); + +``` + +## With promises + +this example by @stephen-last + +``` javascript + +import Promise from 'bluebird' +import cmd from 'node-cmd' + +const getAsync = Promise.promisify(cmd.get, { multiArgs: true, context: cmd }) + +getAsync('node -v').then(data => { + console.log('cmd data', data) +}).catch(err => { + console.log('cmd err', err) +}) + +``` + +## Accessing the CMD Process +If you need PIDs, stdio,stdin, stdout, stderr, etc. access, for use in your code, or cleaning up, @freemany added in some functionality to get a reference to the child process as the returned value of the ` get ` and ` run ` calls. + + +### Getting Process ID + +```javascript + + var cmd=require('../cmd.js'); + + var process=cmd.get('node'); + console.log(process.pid); + +``` + +### Running a python shell from node + +```javascript +const cmd=require('../cmd.js'); + +const processRef=cmd.get('python -i'); +let data_line = ''; + +//listen to the python terminal output +processRef.stdout.on( + 'data', + function(data) { + data_line += data; + if (data_line[data_line.length-1] == '\n') { + console.log(data_line); + } + } +); + +const pythonTerminalInput=`primes = [2, 3, 5, 7] +for prime in primes: + print(prime) + +`; + +//show what we are doing +console.log(`>>>${pythonTerminalInput}`); + +//send it to the open python terminal +processRef.stdin.write(pythonTerminalInput); + +``` + +Output : + +```python + +>>>primes = [2, 3, 5, 7] +for prime in primes: + print(prime) + + +2 +3 +5 +7 + + +``` diff --git a/node_modules/node-cmd/cmd.js b/node_modules/node-cmd/cmd.js new file mode 100644 index 0000000..4cc4a1d --- /dev/null +++ b/node_modules/node-cmd/cmd.js @@ -0,0 +1,32 @@ +var exec = require('child_process').exec; + +var commandline={ + get:getString, + run:runCommand +}; + +function runCommand(command){ + //return refrence to the child process + return exec( + command + ); +} + +function getString(command,callback){ + //return refrence to the child process + return exec( + command, + ( + function(){ + return function(err,data,stderr){ + if(!callback) + return; + + callback(err, data, stderr); + } + } + )(callback) + ); +} + +module.exports=commandline; diff --git a/node_modules/node-cmd/commandline.js b/node_modules/node-cmd/commandline.js new file mode 100644 index 0000000..425ea97 --- /dev/null +++ b/node_modules/node-cmd/commandline.js @@ -0,0 +1,27 @@ +var exec = require('child_process').exec; + +var commandline={ + get:getString, + run:runCommand +}; + +function runCommand(command){ + exec( + command + ); +} + +function getString(command,callback){ + exec( + command, + ( + function(){ + return function(err,data,stderr){ + callback(data,err,stderr); + } + } + )(callback) + ); +} + +module.exports=commandline; diff --git a/node_modules/node-cmd/example/basic.js b/node_modules/node-cmd/example/basic.js new file mode 100644 index 0000000..66fcc54 --- /dev/null +++ b/node_modules/node-cmd/example/basic.js @@ -0,0 +1,28 @@ +var cmd=require('../cmd.js'); + +cmd.get( + 'pwd', + function(data){ + console.log('the current working dir is : ',data) + } +); + +cmd.run('touch example.created.file'); + +cmd.get( + 'ls', + function(data){ + console.log('the current dir contains these files :\n\n',data) + } +); + +cmd.get( + ` + git clone https://github.com/RIAEvangelist/node-cmd.git + cd node-cmd + ls + `, + function(data){ + console.log('the node-cmd clone dir contains these files :\n\n',data) + } +); diff --git a/node_modules/node-cmd/example/example.created.file b/node_modules/node-cmd/example/example.created.file new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/node_modules/node-cmd/example/example.created.file diff --git a/node_modules/node-cmd/example/getPID.js b/node_modules/node-cmd/example/getPID.js new file mode 100644 index 0000000..e5946d4 --- /dev/null +++ b/node_modules/node-cmd/example/getPID.js @@ -0,0 +1,4 @@ +var cmd=require('../cmd.js'); + +var processRef=cmd.get('node'); +console.log(processRef.pid); diff --git a/node_modules/node-cmd/example/nodePythonTerminal.js b/node_modules/node-cmd/example/nodePythonTerminal.js new file mode 100644 index 0000000..59d16e2 --- /dev/null +++ b/node_modules/node-cmd/example/nodePythonTerminal.js @@ -0,0 +1,27 @@ +const cmd=require('../cmd.js'); + +const processRef=cmd.get('python -i'); +let data_line = ''; + +//listen to the python terminal output +processRef.stdout.on( + 'data', + function(data) { + data_line += data; + if (data_line[data_line.length-1] == '\n') { + console.log(data_line); + } + } +); + +const pythonTerminalInput=`primes = [2, 3, 5, 7] +for prime in primes: + print(prime) + +`; + +//show what we are doing +console.log(`>>>${pythonTerminalInput}`); + +//send it to the open python terminal +processRef.stdin.write(pythonTerminalInput); diff --git a/node_modules/node-cmd/licence.md b/node_modules/node-cmd/licence.md new file mode 100644 index 0000000..9169a8f --- /dev/null +++ b/node_modules/node-cmd/licence.md @@ -0,0 +1,27 @@ +# DON'T BE A DICK PUBLIC LICENSE + +> Version 1, December 2009 + +> Copyright (C) 2009 Philip Sturgeon <[email protected]> + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + +> DON'T BE A DICK PUBLIC LICENSE +> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 1. Do whatever you like with the original work, just don't be a dick. + + Being a dick includes - but is not limited to - the following instances: + + 1a. Outright copyright infringement - Don't just copy this and change the name. + 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. + 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. + + 2. If you become rich through modifications, related works/services, or supporting the original work, + share the love. Only a dick would make loads off this work and not buy the original work's + creator(s) a pint. + + 3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes + you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. diff --git a/node_modules/node-cmd/package.json b/node_modules/node-cmd/package.json new file mode 100644 index 0000000..330e1b5 --- /dev/null +++ b/node_modules/node-cmd/package.json @@ -0,0 +1,58 @@ +{ + "_from": "node-cmd@^3.0.0", + "_id": "[email protected]", + "_inBundle": false, + "_integrity": "sha1-OP/3CkqqT2WdID61eGJzcBjiT28=", + "_location": "/node-cmd", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "node-cmd@^3.0.0", + "name": "node-cmd", + "escapedName": "node-cmd", + "rawSpec": "^3.0.0", + "saveSpec": null, + "fetchSpec": "^3.0.0" + }, + "_requiredBy": [ + "/" + ], + "_resolved": "https://registry.npmjs.org/node-cmd/-/node-cmd-3.0.0.tgz", + "_shasum": "38fff70a4aaa4f659d203eb57862737018e24f6f", + "_spec": "node-cmd@^3.0.0", + "_where": "/Users/lucifer/Documents/styx", + "author": { + "name": "Brandon Nozaki Miller" + }, + "bugs": { + "url": "https://github.com/RIAEvangelist/node-cmd/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Simple commandline/terminal interface to allow you to run cli or bash style commands as if you were in the terminal.", + "directories": { + "example": "example" + }, + "homepage": "https://github.com/RIAEvangelist/node-cmd", + "keywords": [ + "commandline", + "terminal", + "cmd", + "cli", + "bash", + "script", + "node" + ], + "license": "DBAD", + "main": "cmd.js", + "name": "node-cmd", + "repository": { + "type": "git", + "url": "git+https://github.com/RIAEvangelist/node-cmd.git" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "version": "3.0.0" +} |
