add smart sourcing of files with bash

This commit is contained in:
2017-03-10 22:08:04 +01:00
parent a91938e463
commit 2d3a4b0a0e
8 changed files with 100 additions and 15 deletions

View File

@ -1 +1,2 @@
export * from './smartshell.wrap'
export * from './smartshell.classes.smartshell'

View File

@ -10,20 +10,47 @@ export interface ISmartshellContructorOptions {
}
export class Smartshell {
sourceFiles: string[] = []
executor: TExecutor
sourceFileArray: string[] = []
constructor (optionsArg: ISmartshellContructorOptions) {
this.executor = optionsArg.executor
for (let sourceFilePath of optionsArg.sourceFilePaths) {
this.sourceFiles.push(sourceFilePath)
this.sourceFileArray.push(sourceFilePath)
}
}
addSourceFiles(sourceFilePathsArray: string[]) {
for(let sourceFilePath of sourceFilePathsArray) {
this.sourceFiles.push(sourceFilePath)
this.sourceFileArray.push(sourceFilePath)
}
}
cleanSourceFiles () {
this.sourceFiles = []
this.sourceFileArray = []
}
}
/**
* executes silently and returns IExecResult
* @param commandArg
*/
execSilent(commandArg: string) {
let execCommand = this.createExecString(commandArg)
return smartshellWrap.execSilent(commandArg)
}
/**
* creates the final sourcing string
* @param commandArg
*/
private createExecString (commandArg): string {
if (this.executor === 'bash') {
let sourceString = ''
for (let sourceFilePath of this.sourceFileArray) {
sourceString = sourceString + `source ${sourceFilePath} && `
}
return `bash -c '${sourceString} ${commandArg}'`
} else {
return commandArg
}
}
}