bootstrap Smartshell class

This commit is contained in:
2017-03-10 20:14:40 +01:00
parent 2b48edf5b7
commit a91938e463
11 changed files with 203 additions and 46 deletions

View File

@ -4,13 +4,26 @@ import * as smartshellWrap from './smartshell.wrap'
export type TExecutor = 'sh' | 'bash'
export interface ISmartshellContructorOptions {
executor: TExecutor
sourceFiles: string[]
executor: TExecutor
sourceFilePaths: string[]
}
export class Smartshell {
constructor() {
sourceFiles: string[] = []
constructor (optionsArg: ISmartshellContructorOptions) {
for (let sourceFilePath of optionsArg.sourceFilePaths) {
this.sourceFiles.push(sourceFilePath)
}
}
addSourceFiles(sourceFilePathsArray: string[]) {
for(let sourceFilePath of sourceFilePathsArray) {
this.sourceFiles.push(sourceFilePath)
}
}
cleanSourceFiles () {
this.sourceFiles = []
}
}

View File

@ -1,13 +1,26 @@
import * as plugins from './smartshell.plugins'
// interfaces
import { ChildProcess } from 'child_process'
import { Deferred } from 'smartq'
export interface IExecResult {
exitCode: number,
stdout: string
}
export interface IExecResultStreaming {
childProcess: ChildProcess,
finalPromise: Promise<IExecResult>
}
/**
* executes a given command async
* @param commandStringArg
*/
export let exec = (commandStringArg: string): Promise<IExecResult> => {
let done = plugins.smartq.defer<IExecResult>()
plugins.shelljs.exec(commandStringArg,{async: true}, (code, stdout, stderr) => {
plugins.shelljs.exec(commandStringArg, { async: true }, (code, stdout, stderr) => {
done.resolve({
exitCode: code,
stdout: stdout
@ -16,9 +29,13 @@ export let exec = (commandStringArg: string): Promise<IExecResult> => {
return done.promise
}
/**
* executes a given command async and silent
* @param commandStringArg
*/
export let execSilent = (commandStringArg: string) => {
let done = plugins.smartq.defer<IExecResult>()
plugins.shelljs.exec(commandStringArg,{async: true, silent: true}, (code, stdout, stderr) => {
plugins.shelljs.exec(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => {
done.resolve({
exitCode: code,
stdout: stdout
@ -26,3 +43,20 @@ export let execSilent = (commandStringArg: string) => {
})
return done.promise
}
/**
* executes a command and allws you to stream output
*/
export let execStreaming = (commandStringArg: string) => {
let childProcessEnded = plugins.smartq.defer<IExecResult>()
let execChildProcess = plugins.shelljs.exec(commandStringArg, {async: true, silent: true}, (code, stdout, stderr) => {
childProcessEnded.resolve({
exitCode: code,
stdout: stdout
})
})
return {
childProcess: execChildProcess,
finalPromise: childProcessEnded.promise
}
}