Initial Commit

This commit is contained in:
2018-05-19 02:20:19 +02:00
commit 8621248968
6554 changed files with 1121559 additions and 0 deletions

View File

@@ -0,0 +1 @@
/example/node-cmd/

158
ProjectNow/NodeServer/node_modules/node-cmd/README.md generated vendored Normal file
View File

@@ -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 :
[![NPM](https://nodei.co/npm/node-cmd.png?downloads=true&downloadRank=true&stars=true)](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=)
![node-cmd npm version](https://img.shields.io/npm/v/node-cmd.svg) ![supported node version for node-cmd](https://img.shields.io/node/v/node-cmd.svg) ![total npm downloads for node-cmd](https://img.shields.io/npm/dt/node-cmd.svg) ![monthly npm downloads for node-cmd](https://img.shields.io/npm/dm/node-cmd.svg) ![npm licence for node-cmd](https://img.shields.io/npm/l/node-cmd.svg)
[![RIAEvangelist](https://avatars3.githubusercontent.com/u/369041?v=3&s=100)](https://github.com/RIAEvangelist)
GitHub info :
![node-cmd GitHub Release](https://img.shields.io/github/release/RIAEvangelist/node-cmd.svg) ![GitHub license node-cmd license](https://img.shields.io/github/license/RIAEvangelist/node-cmd.svg) ![open issues for node-cmd on GitHub](https://img.shields.io/github/issues/RIAEvangelist/node-cmd.svg)
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
```

32
ProjectNow/NodeServer/node_modules/node-cmd/cmd.js generated vendored Normal file
View File

@@ -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;

View File

@@ -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;

View File

@@ -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)
}
);

View File

@@ -0,0 +1,4 @@
var cmd=require('../cmd.js');
var processRef=cmd.get('node');
console.log(processRef.pid);

View File

@@ -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);

27
ProjectNow/NodeServer/node_modules/node-cmd/licence.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# DON'T BE A DICK PUBLIC LICENSE
> Version 1, December 2009
> Copyright (C) 2009 Philip Sturgeon <email@philsturgeon.co.uk>
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.

View File

@@ -0,0 +1,59 @@
{
"_from": "node-cmd",
"_id": "node-cmd@3.0.0",
"_inBundle": false,
"_integrity": "sha1-OP/3CkqqT2WdID61eGJzcBjiT28=",
"_location": "/node-cmd",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "node-cmd",
"name": "node-cmd",
"escapedName": "node-cmd",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/node-cmd/-/node-cmd-3.0.0.tgz",
"_shasum": "38fff70a4aaa4f659d203eb57862737018e24f6f",
"_spec": "node-cmd",
"_where": "/home/beppe/Documents/Python/proj/1718PROJrpiRadio/NodeServer",
"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"
}