fix(structure): clean up

This commit is contained in:
Philipp Kunz 2018-07-30 16:08:14 +02:00
parent 697f789b55
commit 7c9cf6e70d
7 changed files with 44 additions and 117 deletions

View File

@ -117,8 +117,9 @@ pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g npmpage
- npmci command npmpage
- npmci command npm install -g typedoc typescript
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv

View File

@ -46,7 +46,7 @@ tap.test('smartshell should run async', async () => {
tap.test('should be able to find git', async () => {
testSmartshell.exec('git --version');
})
});
tap.start({
throwOnError: true

View File

@ -17,7 +17,7 @@ export class ShellEnv {
for (let sourceFilePath of optionsArg.sourceFilePaths) {
this.sourceFileArray.push(sourceFilePath);
}
};
}
/**
* add files that are going to be sourced when running a command

View File

@ -1,11 +1,10 @@
// -- imports --
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 * as cp from "child_process";
import { Deferred } from "@pushrocks/smartpromise";
import * as cp from 'child_process';
import { Deferred } from '@pushrocks/smartpromise';
// -- interfaces --
/**
@ -43,7 +42,7 @@ export class Smartshell {
} else {
return stringArg;
}
};
}
/**
* executes a given command async
@ -59,7 +58,7 @@ export class Smartshell {
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
// build commandToExecute
let commandToExecute = commandStringArg
let commandToExecute = commandStringArg;
commandToExecute = this.shellEnv.createEnvExecString(commandStringArg);
commandToExecute = this._importEnvVarPath(commandToExecute);
const spawnlogInstance = new ShellLog();
@ -68,13 +67,13 @@ export class Smartshell {
env: process.env
});
execChildProcess.stdout.on("data", data => {
execChildProcess.stdout.on('data', data => {
if (!silentArg) {
spawnlogInstance.logToConsole(data);
}
spawnlogInstance.addToBuffer(data);
});
execChildProcess.stderr.on("data", data => {
execChildProcess.stderr.on('data', data => {
if (!silentArg) {
spawnlogInstance.logToConsole(data);
}
@ -88,7 +87,7 @@ export class Smartshell {
});
}
execChildProcess.on("exit", (code, signal) => {
execChildProcess.on('exit', (code, signal) => {
if (strictArg && code === 1) {
done.reject();
}
@ -96,7 +95,7 @@ export class Smartshell {
const execResult = {
exitCode: code,
stdout: spawnlogInstance.logStore.toString()
}
};
if (!streamingArg) {
done.resolve(execResult);
@ -106,32 +105,26 @@ export class Smartshell {
const result = await done.promise;
return result;
};
}
async exec (
commandStringArg: string
): Promise<IExecResult> {
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> {
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> {
async execStrict(commandStringArg: string): Promise<IExecResult> {
return (await this._exec(commandStringArg, true, true)) as IExecResult;
};
}
/**
* executes a command and allows you to stream output
@ -141,37 +134,29 @@ export class Smartshell {
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
) {
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) => {
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);
};
}
async execAndWaitForLineSilent(commandStringArg: string, regexArg: RegExp) {
this.execAndWaitForLine(commandStringArg, regexArg, true);
}
}

View File

@ -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);
} */