Compare commits

...

7 Commits

Author SHA1 Message Date
e6ed457501 2.0.6 2018-08-05 23:27:38 +02:00
0a6484762c fix(ci): update testing framework 2018-08-05 23:27:37 +02:00
baa3e4e6e9 2.0.5 2018-08-04 16:43:02 +02:00
0d68361381 fix(PATH): add proper PATH handling for child processes 2018-08-04 16:43:02 +02:00
286d80328c 2.0.4 2018-07-30 16:34:45 +02:00
2a71f00ab0 2.0.3 2018-07-30 16:19:38 +02:00
80a44a43cb fix(ci): update build step to be faster 2018-07-30 16:19:38 +02:00
5 changed files with 139 additions and 36 deletions

View File

@ -1,9 +1,6 @@
{
"npmci": {
"npmGlobalTools": [
"npmts",
"ts-node"
],
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}

99
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartshell",
"version": "2.0.2",
"version": "2.0.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -14,6 +14,19 @@
"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": {
"version": "1.1.9",
"resolved": "https://registry.npmjs.org/@gitzone/tsrun/-/tsrun-1.1.9.tgz",
@ -25,6 +38,31 @@
"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": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.1.tgz",
@ -51,6 +89,27 @@
"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": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-2.0.5.tgz",
@ -65,6 +124,17 @@
"@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": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@pushrocks/tapbundle/-/tapbundle-3.0.1.tgz",
@ -102,6 +172,12 @@
"@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": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.4.tgz",
@ -112,9 +188,9 @@
}
},
"@types/node": {
"version": "10.5.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.2.tgz",
"integrity": "sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q==",
"version": "10.5.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.6.tgz",
"integrity": "sha512-c5Z1j1ysgo4878ptz6gxLcgMfJ6Wf908R3l5KAGabr0XJ72ZFmOCgsaodPpNYTfp4iOrSwgTDvR/BxbFfB4zPQ==",
"dev": true
},
"@types/vinyl": {
@ -338,12 +414,27 @@
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
"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": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"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": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/first-chunk-stream/-/first-chunk-stream-2.0.0.tgz",

View File

@ -1,13 +1,13 @@
{
"name": "@pushrocks/smartshell",
"private": false,
"version": "2.0.2",
"version": "2.0.6",
"description": "shell actions designed as promises",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(tsrun test/test.ts)",
"build": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -24,9 +24,11 @@
},
"homepage": "https://gitlab.com/pushrocks/smartshell#README",
"devDependencies": {
"@gitzone/tsbuild": "^2.0.21",
"@gitzone/tsrun": "^1.1.9",
"@gitzone/tstest": "^1.0.12",
"@pushrocks/tapbundle": "^3.0.1",
"@types/node": "^10.5.2"
"@types/node": "^10.5.6"
},
"dependencies": {
"@pushrocks/smartpromise": "^2.0.5",

View File

@ -1,22 +1,48 @@
export type TExecutor = 'sh' | 'bash';
export type TExecutor = "sh" | "bash";
export interface IShellEnvContructorOptions {
executor: TExecutor;
sourceFilePaths: string[];
sourceFilePaths?: string[];
pathDirectories?: string[];
}
export class ShellEnv {
executor: TExecutor;
sourceFileArray: string[] = [];
pathDirArray: string[] = [];
/**
* constructor for the shellenv
*/
constructor(optionsArg: IShellEnvContructorOptions) {
this.executor = optionsArg.executor;
for (let sourceFilePath of optionsArg.sourceFilePaths) {
this.sourceFileArray.push(sourceFilePath);
// 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;
}
/**
@ -37,14 +63,15 @@ export class ShellEnv {
}
createEnvExecString(commandArg): string {
if (this.executor === 'bash') {
let sourceString = '';
let commandResult = ''
if (this.executor === "bash") {
let sourceString = "";
for (let sourceFilePath of this.sourceFileArray) {
sourceString = sourceString + `source ${sourceFilePath} && `;
}
return `bash -c '${sourceString} ${commandArg}'`;
} else {
return commandArg;
commandResult = `bash -c '${sourceString} ${commandArg}'`;
}
commandResult = this._setPath(commandResult);
return commandResult;
}
}

View File

@ -29,20 +29,7 @@ export class Smartshell {
constructor(optionsArg: IShellEnvContructorOptions) {
this.shellEnv = new ShellEnv(optionsArg);
}
/**
* imports path into the shell from env if available and returns it with
*/
private _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
@ -60,7 +47,6 @@ export class Smartshell {
// build commandToExecute
let commandToExecute = commandStringArg;
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
commandToExecute = this._importEnvVarPath(commandToExecute);
const spawnlogInstance = new ShellLog();
const execChildProcess = cp.spawn(commandToExecute, [], {
shell: true,