Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
e6ed457501 | |||
0a6484762c | |||
baa3e4e6e9 | |||
0d68361381 | |||
286d80328c | |||
2a71f00ab0 | |||
80a44a43cb | |||
5ea780acda | |||
7c9cf6e70d | |||
697f789b55 | |||
f452964779 | |||
f2db8dc41f | |||
2ca593297c |
@ -117,8 +117,9 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
# smartshell
|
|
||||||
|
|
||||||
shell actions designed as promises
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartshell)
|
|
||||||
[](https://GitLab.com/pushrocks/smartshell)
|
|
||||||
[](https://github.com/pushrocks/smartshell)
|
|
||||||
[](https://pushrocks.gitlab.io/smartshell/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartshell/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/smartshell/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/smartshell)
|
|
||||||
[](https://david-dm.org/pushrocks/smartshell)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartshell/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartshell)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
@ -1,9 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts",
|
|
||||||
"ts-node"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
99
package-lock.json
generated
99
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartshell",
|
"name": "@pushrocks/smartshell",
|
||||||
"version": "1.0.21",
|
"version": "2.0.6",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -14,6 +14,19 @@
|
|||||||
"nan": "^2.9.2"
|
"nan": "^2.9.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@gitzone/tsbuild": {
|
||||||
|
"version": "2.0.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/@gitzone/tsbuild/-/tsbuild-2.0.21.tgz",
|
||||||
|
"integrity": "sha512-MAKfqnhf+42twSzXziRoBCu+sW61+2Rvc5qXxpEb594Fpnsj28cZ1VIEckSmiAkoBSiCnoU+2/qea2ycwWMBTg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@pushrocks/smartfile": "^6.0.3",
|
||||||
|
"@pushrocks/smartlog": "^2.0.1",
|
||||||
|
"@pushrocks/smartpath": "^4.0.1",
|
||||||
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
|
"typescript": "^2.9.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@gitzone/tsrun": {
|
"@gitzone/tsrun": {
|
||||||
"version": "1.1.9",
|
"version": "1.1.9",
|
||||||
"resolved": "https://registry.npmjs.org/@gitzone/tsrun/-/tsrun-1.1.9.tgz",
|
"resolved": "https://registry.npmjs.org/@gitzone/tsrun/-/tsrun-1.1.9.tgz",
|
||||||
@ -25,6 +38,31 @@
|
|||||||
"typescript": "^2.9.1"
|
"typescript": "^2.9.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@gitzone/tstest": {
|
||||||
|
"version": "1.0.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/@gitzone/tstest/-/tstest-1.0.12.tgz",
|
||||||
|
"integrity": "sha512-nBKOJTI7L/XxH3cre+NtVbdAp1gheDeZX/z107zc4yeQOesZB/w+fkyVrdzAqRVMhyXjrOzwngB1UGqIXSXlSg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@gitzone/tsrun": "^1.1.9",
|
||||||
|
"@pushrocks/consolecolor": "^2.0.1",
|
||||||
|
"@pushrocks/smartfile": "^6.0.3",
|
||||||
|
"@pushrocks/smartlog": "^2.0.1",
|
||||||
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
|
"@pushrocks/smartshell": "^2.0.5",
|
||||||
|
"@types/figures": "^2.0.0",
|
||||||
|
"figures": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@pushrocks/consolecolor": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/consolecolor/-/consolecolor-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-iOFCHVeFZ2OywbdwSxVI4/wokkcLrXVdHLgvMmkNhJ220eeLgjNZWx3EJo3vNW3zq5ybCSCUIq0878djBxrWpw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"ansi-256-colors": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/smartdelay": {
|
"@pushrocks/smartdelay": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.1.tgz",
|
||||||
@ -51,6 +89,27 @@
|
|||||||
"vinyl-file": "^3.0.0"
|
"vinyl-file": "^3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartlog": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-GtsDTGIUF3VuWPyF8FV5dF31ZCEIcaJ56ZlvJsWxjnyJq57X25mk5/K0QAaRE9IIeHg6fORcukFomb5C+AOQrg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@pushrocks/smartlog-interfaces": {
|
||||||
|
"version": "1.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.9.tgz",
|
||||||
|
"integrity": "sha512-0qwpomrRN0kFjmhR9m1iHYXoISoNuXtRP0Wr+JtkYyURLwKHMaW8Xoznf8MzXJptRfqufJi3Fxh5HodpPrIZUA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"@pushrocks/smartpath": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartpath/-/smartpath-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-MaI0+uLQPCr2V3WGnbdgb0pWa9xkWyrP4qYcbsHIjeismGLbn9s3jmP/HIXU8LkgzRgaVb+BJxmZJHOwl32DyA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@pushrocks/smartpromise": {
|
"@pushrocks/smartpromise": {
|
||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-2.0.5.tgz",
|
||||||
@ -65,6 +124,17 @@
|
|||||||
"@pushrocks/smartpromise": "^2.0.5"
|
"@pushrocks/smartpromise": "^2.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartshell": {
|
||||||
|
"version": "2.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartshell/-/smartshell-2.0.5.tgz",
|
||||||
|
"integrity": "sha512-bMmh46jfJxQ7F46bdujmBR8BqPeEFxBqdXab7885v0kaXASIf9+1BMPKfXiPsDrrR8z/2j2cG/Wgh/0+DDD9hQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
|
"@types/which": "^1.3.1",
|
||||||
|
"which": "^1.3.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/tapbundle": {
|
"@pushrocks/tapbundle": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.1.tgz",
|
||||||
@ -102,6 +172,12 @@
|
|||||||
"@types/chai": "*"
|
"@types/chai": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/figures": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/figures/-/figures-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-mcRgJ+ncKuNI+Dwac7omO18B8C8u+YBS+AU/oyLhEyjAnT3cUUThhHgZpbiIvu5ZqSvdD30BXtrqg9nxc3OKMg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/fs-extra": {
|
"@types/fs-extra": {
|
||||||
"version": "5.0.4",
|
"version": "5.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.4.tgz",
|
||||||
@ -112,9 +188,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "10.5.2",
|
"version": "10.5.6",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.6.tgz",
|
||||||
"integrity": "sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q==",
|
"integrity": "sha512-c5Z1j1ysgo4878ptz6gxLcgMfJ6Wf908R3l5KAGabr0XJ72ZFmOCgsaodPpNYTfp4iOrSwgTDvR/BxbFfB4zPQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/vinyl": {
|
"@types/vinyl": {
|
||||||
@ -338,12 +414,27 @@
|
|||||||
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"escape-string-regexp": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||||
|
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"esprima": {
|
"esprima": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
|
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"figures": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"escape-string-regexp": "^1.0.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
"first-chunk-stream": {
|
"first-chunk-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/first-chunk-stream/-/first-chunk-stream-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/first-chunk-stream/-/first-chunk-stream-2.0.0.tgz",
|
||||||
|
10
package.json
10
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartshell",
|
"name": "@pushrocks/smartshell",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "1.0.21",
|
"version": "2.0.6",
|
||||||
"description": "shell actions designed as promises",
|
"description": "shell actions designed as promises",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tsrun test/test.ts)",
|
"test": "(tstest test/)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,9 +24,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartshell#README",
|
"homepage": "https://gitlab.com/pushrocks/smartshell#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@gitzone/tsbuild": "^2.0.21",
|
||||||
"@gitzone/tsrun": "^1.1.9",
|
"@gitzone/tsrun": "^1.1.9",
|
||||||
|
"@gitzone/tstest": "^1.0.12",
|
||||||
"@pushrocks/tapbundle": "^3.0.1",
|
"@pushrocks/tapbundle": "^3.0.1",
|
||||||
"@types/node": "^10.5.2"
|
"@types/node": "^10.5.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
|
58
test/test.ts
58
test/test.ts
@ -1,37 +1,10 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as smartshell from '../ts/index';
|
import * as smartshell from '../ts';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
let testSmartshell: smartshell.Smartshell;
|
let testSmartshell: smartshell.Smartshell;
|
||||||
|
|
||||||
tap.test('smartshell should run async', async () => {
|
|
||||||
let execResult = await smartshell.exec('npm -v');
|
|
||||||
expect(execResult.stdout).to.match(/[0-9\.]*/);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('smartshell should run async and silent', async () => {
|
|
||||||
let execResult = await smartshell.execSilent('npm -v');
|
|
||||||
expect(execResult.stdout).to.match(/[0-9\.]*/);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('smartshell should stream a shell execution', async () => {
|
|
||||||
let done = smartpromise.defer();
|
|
||||||
let execStreamingResponse = smartshell.execStreaming('npm -v');
|
|
||||||
execStreamingResponse.childProcess.stdout.on('data', data => {
|
|
||||||
done.resolve(data);
|
|
||||||
});
|
|
||||||
let data = await done.promise;
|
|
||||||
expect(data).to.match(/[0-9\.]*/);
|
|
||||||
await execStreamingResponse.finalPromise;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('it should execute and wait for a line in the output', async () => {
|
|
||||||
await smartshell.execAndWaitForLine('echo "5.0.4"', /5.0.4/);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Smartshell class
|
|
||||||
|
|
||||||
tap.test('smartshell should create a Smartshell instance', async () => {
|
tap.test('smartshell should create a Smartshell instance', async () => {
|
||||||
testSmartshell = new smartshell.Smartshell({
|
testSmartshell = new smartshell.Smartshell({
|
||||||
executor: 'bash',
|
executor: 'bash',
|
||||||
@ -40,12 +13,41 @@ tap.test('smartshell should create a Smartshell instance', async () => {
|
|||||||
expect(testSmartshell).to.be.instanceof(smartshell.Smartshell);
|
expect(testSmartshell).to.be.instanceof(smartshell.Smartshell);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('smartshell should run async', async () => {
|
||||||
|
let execResult = await testSmartshell.exec('npm -v');
|
||||||
|
expect(execResult.stdout).to.match(/[0-9\.]*/);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('smartshell should run async and silent', async () => {
|
||||||
|
let execResult = await testSmartshell.execSilent('npm -v');
|
||||||
|
expect(execResult.stdout).to.match(/[0-9\.]*/);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('smartshell should stream a shell execution', async () => {
|
||||||
|
let done = smartpromise.defer();
|
||||||
|
let execStreamingResponse = await testSmartshell.execStreaming('npm -v');
|
||||||
|
execStreamingResponse.childProcess.stdout.on('data', data => {
|
||||||
|
done.resolve(data);
|
||||||
|
});
|
||||||
|
let data = await done.promise;
|
||||||
|
expect(data).to.match(/[0-9\.]*/);
|
||||||
|
await execStreamingResponse.finalPromise;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('it should execute and wait for a line in the output', async () => {
|
||||||
|
await testSmartshell.execAndWaitForLine('echo "5.0.4"', /5.0.4/);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('smartshell should run async', async () => {
|
tap.test('smartshell should run async', async () => {
|
||||||
return testSmartshell.execSilent('sleep 1 && npm -v').then(async execResult => {
|
return testSmartshell.execSilent('sleep 1 && npm -v').then(async execResult => {
|
||||||
console.log(execResult.stdout);
|
console.log(execResult.stdout);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should be able to find git', async () => {
|
||||||
|
testSmartshell.exec('git --version');
|
||||||
|
});
|
||||||
|
|
||||||
tap.start({
|
tap.start({
|
||||||
throwOnError: true
|
throwOnError: true
|
||||||
});
|
});
|
||||||
|
@ -1,2 +1 @@
|
|||||||
export * from './smartshell.wrap';
|
|
||||||
export * from './smartshell.classes.smartshell';
|
export * from './smartshell.classes.smartshell';
|
||||||
|
77
ts/smartshell.classes.shellenv.ts
Normal file
77
ts/smartshell.classes.shellenv.ts
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
export type TExecutor = "sh" | "bash";
|
||||||
|
|
||||||
|
export interface IShellEnvContructorOptions {
|
||||||
|
executor: TExecutor;
|
||||||
|
sourceFilePaths?: string[];
|
||||||
|
pathDirectories?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ShellEnv {
|
||||||
|
executor: TExecutor;
|
||||||
|
sourceFileArray: string[] = [];
|
||||||
|
pathDirArray: string[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor for the shellenv
|
||||||
|
*/
|
||||||
|
constructor(optionsArg: IShellEnvContructorOptions) {
|
||||||
|
this.executor = optionsArg.executor;
|
||||||
|
|
||||||
|
// add sourcefiles
|
||||||
|
if (optionsArg.sourceFilePaths) {
|
||||||
|
this.sourceFileArray = this.sourceFileArray.concat(
|
||||||
|
optionsArg.sourceFilePaths
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add pathDirectories
|
||||||
|
if (optionsArg.pathDirectories) {
|
||||||
|
this.pathDirArray = this.pathDirArray.concat(optionsArg.pathDirectories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* imports path into the shell from env if available and returns it with
|
||||||
|
*/
|
||||||
|
private _setPath(commandStringArg): string {
|
||||||
|
let commandResult = commandStringArg;
|
||||||
|
let commandPath = process.env.PATH;
|
||||||
|
if (process.env.SMARTSHELL_PATH) {
|
||||||
|
commandPath = `${commandPath}:${process.env.SMARTSHELL_PATH}`;
|
||||||
|
}
|
||||||
|
commandResult = `PATH=${
|
||||||
|
commandPath
|
||||||
|
} && ${commandStringArg}`;
|
||||||
|
return commandResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add files that are going to be sourced when running a command
|
||||||
|
* @param sourceFilePathsArray
|
||||||
|
*/
|
||||||
|
addSourceFiles(sourceFilePathsArray: string[]) {
|
||||||
|
for (let sourceFilePath of sourceFilePathsArray) {
|
||||||
|
this.sourceFileArray.push(sourceFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cleans the source files array
|
||||||
|
*/
|
||||||
|
cleanSourceFiles() {
|
||||||
|
this.sourceFileArray = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
createEnvExecString(commandArg): string {
|
||||||
|
let commandResult = ''
|
||||||
|
if (this.executor === "bash") {
|
||||||
|
let sourceString = "";
|
||||||
|
for (let sourceFilePath of this.sourceFileArray) {
|
||||||
|
sourceString = sourceString + `source ${sourceFilePath} && `;
|
||||||
|
}
|
||||||
|
commandResult = `bash -c '${sourceString} ${commandArg}'`;
|
||||||
|
}
|
||||||
|
commandResult = this._setPath(commandResult);
|
||||||
|
return commandResult;
|
||||||
|
}
|
||||||
|
}
|
44
ts/smartshell.classes.shelllog.ts
Normal file
44
ts/smartshell.classes.shelllog.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import * as plugins from './smartshell.plugins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a log handler for spawned logs
|
||||||
|
* making sure the process doesn't run out of memory
|
||||||
|
*/
|
||||||
|
export class ShellLog {
|
||||||
|
logStore = Buffer.from('');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* log data to console
|
||||||
|
* @param dataArg
|
||||||
|
*/
|
||||||
|
logToConsole(dataArg: string | Buffer): void {
|
||||||
|
// make sure we have the data as string
|
||||||
|
const dataString: string = (() => {
|
||||||
|
if (Buffer.isBuffer(dataArg)) {
|
||||||
|
return dataArg.toString();
|
||||||
|
}
|
||||||
|
return dataArg;
|
||||||
|
})();
|
||||||
|
console.log(dataString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add data to Buffer for later consumption
|
||||||
|
* @param dataArg
|
||||||
|
*/
|
||||||
|
addToBuffer(dataArg: string | Buffer): void {
|
||||||
|
// make sure we have the data as Buffer
|
||||||
|
const dataBuffer: Buffer = (() => {
|
||||||
|
if (!Buffer.isBuffer(dataArg)) {
|
||||||
|
return Buffer.from(dataArg);
|
||||||
|
}
|
||||||
|
return dataArg;
|
||||||
|
})();
|
||||||
|
this.logStore = Buffer.concat([this.logStore, dataBuffer]);
|
||||||
|
}
|
||||||
|
|
||||||
|
logAndAdd(dataArg: string | Buffer): void {
|
||||||
|
this.logToConsole(dataArg);
|
||||||
|
this.addToBuffer(dataArg);
|
||||||
|
}
|
||||||
|
}
|
@ -1,64 +1,148 @@
|
|||||||
|
// -- imports --
|
||||||
import * as plugins from './smartshell.plugins';
|
import * as plugins from './smartshell.plugins';
|
||||||
import * as smartshellWrap from './smartshell.wrap';
|
import { ShellEnv, IShellEnvContructorOptions, TExecutor } from './smartshell.classes.shellenv';
|
||||||
|
import { ShellLog } from './smartshell.classes.shelllog';
|
||||||
|
|
||||||
export type TExecutor = 'sh' | 'bash';
|
import * as cp from 'child_process';
|
||||||
|
import { Deferred } from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export interface ISmartshellContructorOptions {
|
// -- interfaces --
|
||||||
executor: TExecutor;
|
/**
|
||||||
sourceFilePaths: string[];
|
* interface for ExecResult
|
||||||
|
*/
|
||||||
|
export interface IExecResult {
|
||||||
|
exitCode: number;
|
||||||
|
stdout: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* interface for streaming ExecResult
|
||||||
|
*/
|
||||||
|
export interface IExecResultStreaming {
|
||||||
|
childProcess: cp.ChildProcess;
|
||||||
|
finalPromise: Promise<IExecResult>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- SmartShell --
|
||||||
export class Smartshell {
|
export class Smartshell {
|
||||||
executor: TExecutor;
|
shellEnv: ShellEnv;
|
||||||
sourceFileArray: string[] = [];
|
|
||||||
constructor(optionsArg: ISmartshellContructorOptions) {
|
|
||||||
this.executor = optionsArg.executor;
|
|
||||||
for (let sourceFilePath of optionsArg.sourceFilePaths) {
|
|
||||||
this.sourceFileArray.push(sourceFilePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addSourceFiles(sourceFilePathsArray: string[]) {
|
constructor(optionsArg: IShellEnvContructorOptions) {
|
||||||
for (let sourceFilePath of sourceFilePathsArray) {
|
this.shellEnv = new ShellEnv(optionsArg);
|
||||||
this.sourceFileArray.push(sourceFilePath);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanSourceFiles() {
|
|
||||||
this.sourceFileArray = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes silently and returns IExecResult
|
* executes a given command async
|
||||||
* @param commandArg
|
* @param commandStringArg
|
||||||
*/
|
*/
|
||||||
async execSilent(commandArg: string) {
|
private async _exec(
|
||||||
let execCommand = this.createExecString(commandArg);
|
commandStringArg: string,
|
||||||
return await smartshellWrap.execSilent(execCommand);
|
silentArg: boolean = false,
|
||||||
}
|
strictArg = false,
|
||||||
|
streamingArg = false
|
||||||
|
): Promise<IExecResult | IExecResultStreaming> {
|
||||||
|
// flow control promises
|
||||||
|
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
||||||
|
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
||||||
|
// build commandToExecute
|
||||||
|
let commandToExecute = commandStringArg;
|
||||||
|
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
|
||||||
|
const spawnlogInstance = new ShellLog();
|
||||||
|
const execChildProcess = cp.spawn(commandToExecute, [], {
|
||||||
|
shell: true,
|
||||||
|
env: process.env
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
execChildProcess.stdout.on('data', data => {
|
||||||
* executes and returns IExecResult
|
if (!silentArg) {
|
||||||
* @param commandArg
|
spawnlogInstance.logToConsole(data);
|
||||||
*/
|
|
||||||
async exec(commandArg: string) {
|
|
||||||
let execCommand = this.createExecString(commandArg);
|
|
||||||
return await smartshellWrap.exec(execCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates the final sourcing string
|
|
||||||
* @param commandArg
|
|
||||||
*/
|
|
||||||
private createExecString(commandArg): string {
|
|
||||||
if (this.executor === 'bash') {
|
|
||||||
let sourceString = '';
|
|
||||||
for (let sourceFilePath of this.sourceFileArray) {
|
|
||||||
sourceString = sourceString + `source ${sourceFilePath} && `;
|
|
||||||
}
|
}
|
||||||
return `bash -c '${sourceString} ${commandArg}'`;
|
spawnlogInstance.addToBuffer(data);
|
||||||
} else {
|
});
|
||||||
return commandArg;
|
execChildProcess.stderr.on('data', data => {
|
||||||
|
if (!silentArg) {
|
||||||
|
spawnlogInstance.logToConsole(data);
|
||||||
|
}
|
||||||
|
spawnlogInstance.addToBuffer(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (streamingArg) {
|
||||||
|
done.resolve({
|
||||||
|
childProcess: execChildProcess,
|
||||||
|
finalPromise: childProcessEnded.promise
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
execChildProcess.on('exit', (code, signal) => {
|
||||||
|
if (strictArg && code === 1) {
|
||||||
|
done.reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
const execResult = {
|
||||||
|
exitCode: code,
|
||||||
|
stdout: spawnlogInstance.logStore.toString()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!streamingArg) {
|
||||||
|
done.resolve(execResult);
|
||||||
|
}
|
||||||
|
childProcessEnded.resolve(execResult);
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await done.promise;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async exec(commandStringArg: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec(commandStringArg, false)) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a given command async and silent
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
|
async execSilent(commandStringArg: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec(commandStringArg, true)) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a command async and strict, meaning it rejects the promise if something happens
|
||||||
|
*/
|
||||||
|
async execStrict(commandStringArg: string): Promise<IExecResult> {
|
||||||
|
return (await this._exec(commandStringArg, true, true)) as IExecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a command and allows you to stream output
|
||||||
|
*/
|
||||||
|
async execStreaming(
|
||||||
|
commandStringArg: string,
|
||||||
|
silentArg: boolean = false
|
||||||
|
): Promise<IExecResultStreaming> {
|
||||||
|
return (await this._exec(commandStringArg, silentArg, false, true)) as IExecResultStreaming;
|
||||||
|
}
|
||||||
|
|
||||||
|
async execStreamingSilent(commandStringArg: string) {
|
||||||
|
return (await this.execStreaming(commandStringArg, true)) as IExecResultStreaming;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
|
||||||
|
* @param commandStringArg
|
||||||
|
* @param regexArg
|
||||||
|
*/
|
||||||
|
async execAndWaitForLine(commandStringArg: string, regexArg: RegExp, silentArg: boolean = false) {
|
||||||
|
let done = plugins.smartpromise.defer();
|
||||||
|
let execStreamingResult = await this.execStreaming(commandStringArg, silentArg);
|
||||||
|
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => {
|
||||||
|
if (regexArg.test(stdOutChunk)) {
|
||||||
|
done.resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
async execAndWaitForLineSilent(commandStringArg: string, regexArg: RegExp) {
|
||||||
|
this.execAndWaitForLine(commandStringArg, regexArg, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,204 +0,0 @@
|
|||||||
import * as plugins from "./smartshell.plugins";
|
|
||||||
|
|
||||||
// interfaces
|
|
||||||
import * as cp from "child_process";
|
|
||||||
import { Deferred } from "@pushrocks/smartpromise";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* interface for ExecResult
|
|
||||||
*/
|
|
||||||
export interface IExecResult {
|
|
||||||
exitCode: number;
|
|
||||||
stdout: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* interface for streaming ExecResult
|
|
||||||
*/
|
|
||||||
export interface IExecResultStreaming {
|
|
||||||
childProcess: cp.ChildProcess;
|
|
||||||
finalPromise: Promise<IExecResult>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* imports path into the shell from env if available and returns it with
|
|
||||||
*/
|
|
||||||
let importEnvVarPath = (stringArg): string => {
|
|
||||||
if (process.env.SMARTSHELL_PATH) {
|
|
||||||
let commandResult = `PATH=${process.env.SMARTSHELL_PATH} && ${stringArg}`;
|
|
||||||
// console.log(commandResult)
|
|
||||||
return commandResult;
|
|
||||||
} else {
|
|
||||||
return stringArg;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes a given command async
|
|
||||||
* @param commandStringArg
|
|
||||||
*/
|
|
||||||
export let exec = (
|
|
||||||
commandStringArg: string,
|
|
||||||
silentArg: boolean = false,
|
|
||||||
strictArg = false
|
|
||||||
): Promise<IExecResult> => {
|
|
||||||
let done = plugins.smartpromise.defer<IExecResult>();
|
|
||||||
const commandToExecute = importEnvVarPath(commandStringArg);
|
|
||||||
try {
|
|
||||||
const execChildProcess = cp.exec(commandToExecute, {
|
|
||||||
timeout: null,
|
|
||||||
maxBuffer: 1000000,
|
|
||||||
env: process.env
|
|
||||||
});
|
|
||||||
|
|
||||||
let logStore = "";
|
|
||||||
|
|
||||||
execChildProcess.stdout.on("data", (data: string) => {
|
|
||||||
if (!silentArg) {
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
logStore += data;
|
|
||||||
});
|
|
||||||
execChildProcess.stderr.on("data", data => {
|
|
||||||
if (!silentArg) {
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
logStore += data;
|
|
||||||
});
|
|
||||||
execChildProcess.on("exit", (code, signal) => {
|
|
||||||
done.resolve({
|
|
||||||
exitCode: code,
|
|
||||||
stdout: logStore
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*plugins.shelljs.exec(importEnvVarPath(commandStringArg), { async: true, silent: silentArg }, (code, stdout, stderr) => {
|
|
||||||
if (
|
|
||||||
stderr
|
|
||||||
&& (stderr !== '')
|
|
||||||
&& (!silentArg || strictArg)
|
|
||||||
&& (process.env.DEBUG === 'true')
|
|
||||||
) {
|
|
||||||
console.log('StdErr found.')
|
|
||||||
console.log(stderr)
|
|
||||||
}
|
|
||||||
if (strictArg) {
|
|
||||||
done.reject(new Error(stderr))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
done.resolve({
|
|
||||||
exitCode: code,
|
|
||||||
stdout: stdout
|
|
||||||
})
|
|
||||||
})*/
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes a given command async and silent
|
|
||||||
* @param commandStringArg
|
|
||||||
*/
|
|
||||||
export let execSilent = async (
|
|
||||||
commandStringArg: string
|
|
||||||
): Promise<IExecResult> => {
|
|
||||||
return await exec(commandStringArg, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes strict, meaning it rejects the promise if something happens
|
|
||||||
*/
|
|
||||||
export let execStrict = async (
|
|
||||||
commandStringArg: string
|
|
||||||
): Promise<IExecResult> => {
|
|
||||||
return await exec(commandStringArg, true, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes a command and allws you to stream output
|
|
||||||
*/
|
|
||||||
export let execStreaming = (
|
|
||||||
commandStringArg: string,
|
|
||||||
silentArg: boolean = false
|
|
||||||
) => {
|
|
||||||
let childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
|
||||||
const commandToExecute = importEnvVarPath(commandStringArg);
|
|
||||||
let execChildProcess = cp.exec(commandToExecute, {
|
|
||||||
timeout: null,
|
|
||||||
maxBuffer: 1000000,
|
|
||||||
env: process.env
|
|
||||||
});
|
|
||||||
|
|
||||||
let logStore = "";
|
|
||||||
|
|
||||||
execChildProcess.stdout.on("data", (data: string) => {
|
|
||||||
if (!silentArg) {
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
logStore += data;
|
|
||||||
});
|
|
||||||
execChildProcess.stderr.on("data", data => {
|
|
||||||
if (!silentArg) {
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
logStore += data;
|
|
||||||
});
|
|
||||||
execChildProcess.on("exit", (code, signal) => {
|
|
||||||
childProcessEnded.resolve({
|
|
||||||
exitCode: code,
|
|
||||||
stdout: logStore
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
childProcess: execChildProcess,
|
|
||||||
finalPromise: childProcessEnded.promise
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export let execStreamingSilent = (commandStringArg: string) => {
|
|
||||||
return execStreaming(commandStringArg, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
|
|
||||||
* @param commandStringArg
|
|
||||||
* @param regexArg
|
|
||||||
*/
|
|
||||||
export let execAndWaitForLine = (
|
|
||||||
commandStringArg: string,
|
|
||||||
regexArg: RegExp,
|
|
||||||
silentArg: boolean = false
|
|
||||||
) => {
|
|
||||||
let done = plugins.smartpromise.defer();
|
|
||||||
let execStreamingResult = execStreaming(commandStringArg, silentArg);
|
|
||||||
execStreamingResult.childProcess.stdout.on("data", (stdOutChunk: string) => {
|
|
||||||
if (regexArg.test(stdOutChunk)) {
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
export let execAndWaitForLineSilent = (
|
|
||||||
commandStringArg: string,
|
|
||||||
regexArg: RegExp
|
|
||||||
) => {
|
|
||||||
execAndWaitForLine(commandStringArg, regexArg, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a path
|
|
||||||
*/
|
|
||||||
export let which = (cmd: string): Promise<string> => {
|
|
||||||
let done = plugins.smartpromise.defer<string>();
|
|
||||||
plugins.which(cmd, (err, path: string) => {
|
|
||||||
if (err) {
|
|
||||||
done.reject(err);
|
|
||||||
}
|
|
||||||
done.resolve(path);
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
Reference in New Issue
Block a user