fix(structure): clean up
This commit is contained in:
parent
697f789b55
commit
7c9cf6e70d
@ -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
|
||||||
|
@ -33,4 +33,4 @@
|
|||||||
"@types/which": "^1.3.1",
|
"@types/which": "^1.3.1",
|
||||||
"which": "^1.3.1"
|
"which": "^1.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,7 +46,7 @@ tap.test('smartshell should run async', async () => {
|
|||||||
|
|
||||||
tap.test('should be able to find git', async () => {
|
tap.test('should be able to find git', async () => {
|
||||||
testSmartshell.exec('git --version');
|
testSmartshell.exec('git --version');
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start({
|
tap.start({
|
||||||
throwOnError: true
|
throwOnError: true
|
||||||
|
@ -8,7 +8,7 @@ export interface IShellEnvContructorOptions {
|
|||||||
export class ShellEnv {
|
export class ShellEnv {
|
||||||
executor: TExecutor;
|
executor: TExecutor;
|
||||||
sourceFileArray: string[] = [];
|
sourceFileArray: string[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor for the shellenv
|
* constructor for the shellenv
|
||||||
*/
|
*/
|
||||||
@ -17,11 +17,11 @@ export class ShellEnv {
|
|||||||
for (let sourceFilePath of optionsArg.sourceFilePaths) {
|
for (let sourceFilePath of optionsArg.sourceFilePaths) {
|
||||||
this.sourceFileArray.push(sourceFilePath);
|
this.sourceFileArray.push(sourceFilePath);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add files that are going to be sourced when running a command
|
* add files that are going to be sourced when running a command
|
||||||
* @param sourceFilePathsArray
|
* @param sourceFilePathsArray
|
||||||
*/
|
*/
|
||||||
addSourceFiles(sourceFilePathsArray: string[]) {
|
addSourceFiles(sourceFilePathsArray: string[]) {
|
||||||
for (let sourceFilePath of sourceFilePathsArray) {
|
for (let sourceFilePath of sourceFilePathsArray) {
|
||||||
@ -47,4 +47,4 @@ export class ShellEnv {
|
|||||||
return commandArg;
|
return commandArg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export class ShellLog {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* log data to console
|
* log data to console
|
||||||
* @param dataArg
|
* @param dataArg
|
||||||
*/
|
*/
|
||||||
logToConsole(dataArg: string | Buffer): void {
|
logToConsole(dataArg: string | Buffer): void {
|
||||||
// make sure we have the data as string
|
// make sure we have the data as string
|
||||||
@ -34,11 +34,11 @@ export class ShellLog {
|
|||||||
}
|
}
|
||||||
return dataArg;
|
return dataArg;
|
||||||
})();
|
})();
|
||||||
this.logStore = Buffer.concat([this.logStore,dataBuffer]);
|
this.logStore = Buffer.concat([this.logStore, dataBuffer]);
|
||||||
}
|
}
|
||||||
|
|
||||||
logAndAdd(dataArg: string | Buffer): void {
|
logAndAdd(dataArg: string | Buffer): void {
|
||||||
this.logToConsole(dataArg);
|
this.logToConsole(dataArg);
|
||||||
this.addToBuffer(dataArg);
|
this.addToBuffer(dataArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
// -- imports --
|
// -- 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 { ShellEnv, IShellEnvContructorOptions, TExecutor, } from './smartshell.classes.shellenv';
|
|
||||||
import { ShellLog } from './smartshell.classes.shelllog';
|
import { ShellLog } from './smartshell.classes.shelllog';
|
||||||
|
|
||||||
import * as cp from "child_process";
|
import * as cp from 'child_process';
|
||||||
import { Deferred } from "@pushrocks/smartpromise";
|
import { Deferred } from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
// -- interfaces --
|
// -- interfaces --
|
||||||
/**
|
/**
|
||||||
@ -35,7 +34,7 @@ export class Smartshell {
|
|||||||
/**
|
/**
|
||||||
* imports path into the shell from env if available and returns it with
|
* imports path into the shell from env if available and returns it with
|
||||||
*/
|
*/
|
||||||
private _importEnvVarPath (stringArg): string {
|
private _importEnvVarPath(stringArg): string {
|
||||||
if (process.env.SMARTSHELL_PATH) {
|
if (process.env.SMARTSHELL_PATH) {
|
||||||
let commandResult = `PATH=${process.env.SMARTSHELL_PATH} && ${stringArg}`;
|
let commandResult = `PATH=${process.env.SMARTSHELL_PATH} && ${stringArg}`;
|
||||||
// console.log(commandResult)
|
// console.log(commandResult)
|
||||||
@ -43,13 +42,13 @@ export class Smartshell {
|
|||||||
} else {
|
} else {
|
||||||
return stringArg;
|
return stringArg;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes a given command async
|
* executes a given command async
|
||||||
* @param commandStringArg
|
* @param commandStringArg
|
||||||
*/
|
*/
|
||||||
private async _exec (
|
private async _exec(
|
||||||
commandStringArg: string,
|
commandStringArg: string,
|
||||||
silentArg: boolean = false,
|
silentArg: boolean = false,
|
||||||
strictArg = false,
|
strictArg = false,
|
||||||
@ -59,7 +58,7 @@ export class Smartshell {
|
|||||||
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
||||||
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
||||||
// build commandToExecute
|
// build commandToExecute
|
||||||
let commandToExecute = commandStringArg
|
let commandToExecute = commandStringArg;
|
||||||
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
|
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
|
||||||
commandToExecute = this._importEnvVarPath(commandToExecute);
|
commandToExecute = this._importEnvVarPath(commandToExecute);
|
||||||
const spawnlogInstance = new ShellLog();
|
const spawnlogInstance = new ShellLog();
|
||||||
@ -68,37 +67,37 @@ export class Smartshell {
|
|||||||
env: process.env
|
env: process.env
|
||||||
});
|
});
|
||||||
|
|
||||||
execChildProcess.stdout.on("data", data => {
|
execChildProcess.stdout.on('data', data => {
|
||||||
if (!silentArg) {
|
if (!silentArg) {
|
||||||
spawnlogInstance.logToConsole(data);
|
spawnlogInstance.logToConsole(data);
|
||||||
}
|
}
|
||||||
spawnlogInstance.addToBuffer(data);
|
spawnlogInstance.addToBuffer(data);
|
||||||
});
|
});
|
||||||
execChildProcess.stderr.on("data", data => {
|
execChildProcess.stderr.on('data', data => {
|
||||||
if (!silentArg) {
|
if (!silentArg) {
|
||||||
spawnlogInstance.logToConsole(data);
|
spawnlogInstance.logToConsole(data);
|
||||||
}
|
}
|
||||||
spawnlogInstance.addToBuffer(data);
|
spawnlogInstance.addToBuffer(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(streamingArg) {
|
if (streamingArg) {
|
||||||
done.resolve({
|
done.resolve({
|
||||||
childProcess: execChildProcess,
|
childProcess: execChildProcess,
|
||||||
finalPromise: childProcessEnded.promise
|
finalPromise: childProcessEnded.promise
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
execChildProcess.on("exit", (code, signal) => {
|
execChildProcess.on('exit', (code, signal) => {
|
||||||
if(strictArg && code === 1) {
|
if (strictArg && code === 1) {
|
||||||
done.reject();
|
done.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
const execResult = {
|
const execResult = {
|
||||||
exitCode: code,
|
exitCode: code,
|
||||||
stdout: spawnlogInstance.logStore.toString()
|
stdout: spawnlogInstance.logStore.toString()
|
||||||
}
|
};
|
||||||
|
|
||||||
if(!streamingArg) {
|
if (!streamingArg) {
|
||||||
done.resolve(execResult);
|
done.resolve(execResult);
|
||||||
}
|
}
|
||||||
childProcessEnded.resolve(execResult);
|
childProcessEnded.resolve(execResult);
|
||||||
@ -106,72 +105,58 @@ export class Smartshell {
|
|||||||
|
|
||||||
const result = await done.promise;
|
const result = await done.promise;
|
||||||
return result;
|
return result;
|
||||||
};
|
}
|
||||||
|
|
||||||
async exec (
|
async exec(commandStringArg: string): Promise<IExecResult> {
|
||||||
commandStringArg: string
|
|
||||||
): Promise<IExecResult> {
|
|
||||||
return (await this._exec(commandStringArg, false)) as IExecResult;
|
return (await this._exec(commandStringArg, false)) as IExecResult;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes a given command async and silent
|
* executes a given command async and silent
|
||||||
* @param commandStringArg
|
* @param commandStringArg
|
||||||
*/
|
*/
|
||||||
async execSilent (
|
async execSilent(commandStringArg: string): Promise<IExecResult> {
|
||||||
commandStringArg: string
|
|
||||||
): Promise<IExecResult> {
|
|
||||||
return (await this._exec(commandStringArg, true)) as IExecResult;
|
return (await this._exec(commandStringArg, true)) as IExecResult;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes a command async and strict, meaning it rejects the promise if something happens
|
* executes a command async and strict, meaning it rejects the promise if something happens
|
||||||
*/
|
*/
|
||||||
async execStrict (
|
async execStrict(commandStringArg: string): Promise<IExecResult> {
|
||||||
commandStringArg: string
|
return (await this._exec(commandStringArg, true, true)) as IExecResult;
|
||||||
): Promise<IExecResult> {
|
}
|
||||||
return (await this._exec(commandStringArg, true, true)) as IExecResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes a command and allows you to stream output
|
* executes a command and allows you to stream output
|
||||||
*/
|
*/
|
||||||
async execStreaming (
|
async execStreaming(
|
||||||
commandStringArg: string,
|
commandStringArg: string,
|
||||||
silentArg: boolean = false
|
silentArg: boolean = false
|
||||||
): Promise<IExecResultStreaming> {
|
): Promise<IExecResultStreaming> {
|
||||||
return (await this._exec(commandStringArg, silentArg, false, true)) as IExecResultStreaming;
|
return (await this._exec(commandStringArg, silentArg, false, true)) as IExecResultStreaming;
|
||||||
};
|
}
|
||||||
|
|
||||||
async execStreamingSilent (commandStringArg: string) {
|
async execStreamingSilent(commandStringArg: string) {
|
||||||
return (await this.execStreaming(commandStringArg, true)) as IExecResultStreaming;
|
return (await this.execStreaming(commandStringArg, true)) as IExecResultStreaming;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
|
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
|
||||||
* @param commandStringArg
|
* @param commandStringArg
|
||||||
* @param regexArg
|
* @param regexArg
|
||||||
*/
|
*/
|
||||||
async execAndWaitForLine (
|
async execAndWaitForLine(commandStringArg: string, regexArg: RegExp, silentArg: boolean = false) {
|
||||||
commandStringArg: string,
|
|
||||||
regexArg: RegExp,
|
|
||||||
silentArg: boolean = false
|
|
||||||
) {
|
|
||||||
let done = plugins.smartpromise.defer();
|
let done = plugins.smartpromise.defer();
|
||||||
let execStreamingResult = await this.execStreaming(commandStringArg, silentArg);
|
let execStreamingResult = await this.execStreaming(commandStringArg, silentArg);
|
||||||
execStreamingResult.childProcess.stdout.on("data", (stdOutChunk: string) => {
|
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => {
|
||||||
if (regexArg.test(stdOutChunk)) {
|
if (regexArg.test(stdOutChunk)) {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
}
|
||||||
|
|
||||||
async execAndWaitForLineSilent (
|
async execAndWaitForLineSilent(commandStringArg: string, regexArg: RegExp) {
|
||||||
commandStringArg: string,
|
|
||||||
regexArg: RegExp
|
|
||||||
) {
|
|
||||||
this.execAndWaitForLine(commandStringArg, regexArg, true);
|
this.execAndWaitForLine(commandStringArg, regexArg, true);
|
||||||
};
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
import * as plugins from "./smartshell.plugins";
|
|
||||||
import { ShellLog } from "./smartshell.classes.shelllog";
|
|
||||||
|
|
||||||
// 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>;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* /////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes silently and returns IExecResult
|
|
||||||
* @param commandArg
|
|
||||||
|
|
||||||
async execSilent(commandArg: string) {
|
|
||||||
let execCommand = this..createExecString(commandArg);
|
|
||||||
return await smartshellWrap.execSilent(execCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes and returns IExecResult
|
|
||||||
* @param commandArg
|
|
||||||
|
|
||||||
async exec(commandArg: string) {
|
|
||||||
let execCommand = this.createExecString(commandArg);
|
|
||||||
return await smartshellWrap.exec(execCommand);
|
|
||||||
} */
|
|
Loading…
Reference in New Issue
Block a user