Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
baa3e4e6e9 | |||
0d68361381 | |||
286d80328c | |||
2a71f00ab0 | |||
80a44a43cb |
@ -1,9 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts",
|
|
||||||
"ts-node"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
36
package-lock.json
generated
36
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartshell",
|
"name": "@pushrocks/smartshell",
|
||||||
"version": "2.0.2",
|
"version": "2.0.5",
|
||||||
"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",
|
||||||
@ -51,6 +64,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",
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartshell",
|
"name": "@pushrocks/smartshell",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "2.0.2",
|
"version": "2.0.5",
|
||||||
"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": "(tsrun test/test.ts)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,6 +24,7 @@
|
|||||||
},
|
},
|
||||||
"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",
|
||||||
"@pushrocks/tapbundle": "^3.0.1",
|
"@pushrocks/tapbundle": "^3.0.1",
|
||||||
"@types/node": "^10.5.2"
|
"@types/node": "^10.5.2"
|
||||||
|
@ -1,22 +1,48 @@
|
|||||||
export type TExecutor = 'sh' | 'bash';
|
export type TExecutor = "sh" | "bash";
|
||||||
|
|
||||||
export interface IShellEnvContructorOptions {
|
export interface IShellEnvContructorOptions {
|
||||||
executor: TExecutor;
|
executor: TExecutor;
|
||||||
sourceFilePaths: string[];
|
sourceFilePaths?: string[];
|
||||||
|
pathDirectories?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ShellEnv {
|
export class ShellEnv {
|
||||||
executor: TExecutor;
|
executor: TExecutor;
|
||||||
sourceFileArray: string[] = [];
|
sourceFileArray: string[] = [];
|
||||||
|
pathDirArray: string[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor for the shellenv
|
* constructor for the shellenv
|
||||||
*/
|
*/
|
||||||
constructor(optionsArg: IShellEnvContructorOptions) {
|
constructor(optionsArg: IShellEnvContructorOptions) {
|
||||||
this.executor = optionsArg.executor;
|
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 {
|
createEnvExecString(commandArg): string {
|
||||||
if (this.executor === 'bash') {
|
let commandResult = ''
|
||||||
let sourceString = '';
|
if (this.executor === "bash") {
|
||||||
|
let sourceString = "";
|
||||||
for (let sourceFilePath of this.sourceFileArray) {
|
for (let sourceFilePath of this.sourceFileArray) {
|
||||||
sourceString = sourceString + `source ${sourceFilePath} && `;
|
sourceString = sourceString + `source ${sourceFilePath} && `;
|
||||||
}
|
}
|
||||||
return `bash -c '${sourceString} ${commandArg}'`;
|
commandResult = `bash -c '${sourceString} ${commandArg}'`;
|
||||||
} else {
|
}
|
||||||
return commandArg;
|
commandResult = this._setPath(commandResult);
|
||||||
}
|
return commandResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,20 +29,7 @@ export class Smartshell {
|
|||||||
|
|
||||||
constructor(optionsArg: IShellEnvContructorOptions) {
|
constructor(optionsArg: IShellEnvContructorOptions) {
|
||||||
this.shellEnv = new ShellEnv(optionsArg);
|
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
|
* executes a given command async
|
||||||
@ -60,7 +47,6 @@ export class Smartshell {
|
|||||||
// build commandToExecute
|
// build commandToExecute
|
||||||
let commandToExecute = commandStringArg;
|
let commandToExecute = commandStringArg;
|
||||||
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
|
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
|
||||||
commandToExecute = this._importEnvVarPath(commandToExecute);
|
|
||||||
const spawnlogInstance = new ShellLog();
|
const spawnlogInstance = new ShellLog();
|
||||||
const execChildProcess = cp.spawn(commandToExecute, [], {
|
const execChildProcess = cp.spawn(commandToExecute, [], {
|
||||||
shell: true,
|
shell: true,
|
||||||
|
Reference in New Issue
Block a user