Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
baa3e4e6e9 | |||
0d68361381 | |||
286d80328c | |||
2a71f00ab0 | |||
80a44a43cb |
@ -1,9 +1,6 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"npmts",
|
||||
"ts-node"
|
||||
],
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
36
package-lock.json
generated
36
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartshell",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.5",
|
||||
"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",
|
||||
@ -51,6 +64,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",
|
||||
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@pushrocks/smartshell",
|
||||
"private": false,
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.5",
|
||||
"description": "shell actions designed as promises",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tsrun test/test.ts)",
|
||||
"build": "(npmts)"
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -24,6 +24,7 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartshell#README",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.21",
|
||||
"@gitzone/tsrun": "^1.1.9",
|
||||
"@pushrocks/tapbundle": "^3.0.1",
|
||||
"@types/node": "^10.5.2"
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user