2018-07-30 14:03:48 +00:00
|
|
|
export type TExecutor = 'sh' | 'bash';
|
|
|
|
|
|
|
|
export interface IShellEnvContructorOptions {
|
|
|
|
executor: TExecutor;
|
|
|
|
sourceFilePaths: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ShellEnv {
|
|
|
|
executor: TExecutor;
|
|
|
|
sourceFileArray: string[] = [];
|
2018-07-30 14:08:14 +00:00
|
|
|
|
2018-07-30 14:03:48 +00:00
|
|
|
/**
|
|
|
|
* constructor for the shellenv
|
|
|
|
*/
|
|
|
|
constructor(optionsArg: IShellEnvContructorOptions) {
|
|
|
|
this.executor = optionsArg.executor;
|
|
|
|
for (let sourceFilePath of optionsArg.sourceFilePaths) {
|
|
|
|
this.sourceFileArray.push(sourceFilePath);
|
|
|
|
}
|
2018-07-30 14:08:14 +00:00
|
|
|
}
|
2018-07-30 14:03:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* add files that are going to be sourced when running a command
|
2018-07-30 14:08:14 +00:00
|
|
|
* @param sourceFilePathsArray
|
2018-07-30 14:03:48 +00:00
|
|
|
*/
|
|
|
|
addSourceFiles(sourceFilePathsArray: string[]) {
|
|
|
|
for (let sourceFilePath of sourceFilePathsArray) {
|
|
|
|
this.sourceFileArray.push(sourceFilePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cleans the source files array
|
|
|
|
*/
|
|
|
|
cleanSourceFiles() {
|
|
|
|
this.sourceFileArray = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
createEnvExecString(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;
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 14:08:14 +00:00
|
|
|
}
|