"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const plugins = require("./smartshell.plugins"); /** * import path */ let importPath = (stringArg) => { if (process.env.SMARTSHELL_PATH) { let commandResult = `PATH=${process.env.SMARTSHELL_PATH} && ${stringArg}`; // console.log(commandResult) return commandResult; } else { return stringArg; } }; /** * executes a given command async * @param commandStringArg */ exports.exec = (commandStringArg) => { let done = plugins.smartq.defer(); plugins.shelljs.exec(importPath(commandStringArg), { async: true }, (code, stdout, stderr) => { if (stderr) { console.log('StdErr found:'); console.log(stderr); done.reject(stderr); return; } done.resolve({ exitCode: code, stdout: stdout }); }); return done.promise; }; /** * executes a given command async and silent * @param commandStringArg */ exports.execSilent = (commandStringArg) => { let done = plugins.smartq.defer(); plugins.shelljs.exec(importPath(commandStringArg), { async: true, silent: true }, (code, stdout, stderr) => { if (stderr && stderr !== '') { console.log('StdErr found:'); console.log(stderr); done.reject(stderr); return; } done.resolve({ exitCode: code, stdout: stdout }); }); return done.promise; }; /** * executes a command and allws you to stream output */ exports.execStreaming = (commandStringArg, silentArg = false) => { let childProcessEnded = plugins.smartq.defer(); let execChildProcess = plugins.shelljs.exec(importPath(commandStringArg), { async: true, silent: silentArg }, (code, stdout, stderr) => { childProcessEnded.resolve({ exitCode: code, stdout: stdout }); }); return { childProcess: execChildProcess, finalPromise: childProcessEnded.promise }; }; exports.execStreamingSilent = (commandStringArg) => { return exports.execStreaming(commandStringArg, true); }; /** * executes a command and returns promise that will be fullfilled once an putput line matches RegexArg * @param commandStringArg * @param regexArg */ exports.execAndWaitForLine = (commandStringArg, regexArg, silentArg = false) => { let done = plugins.smartq.defer(); let execStreamingResult = exports.execStreaming(commandStringArg, silentArg); execStreamingResult.childProcess.stdout.on('data', (stdOutChunk) => { if (regexArg.test(stdOutChunk)) { done.resolve(); } }); return done.promise; }; exports.execAndWaitForLineSilent = (commandStringArg, regexArg) => { exports.execAndWaitForLine(commandStringArg, regexArg, true); }; /** * get a path */ exports.which = (cmd) => { let done = plugins.smartq.defer(); plugins.which(cmd, (err, path) => { if (err) { done.reject(err); } done.resolve(path); }); return done.promise; }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzaGVsbC53cmFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsZ0RBQStDO0FBc0IvQzs7R0FFRztBQUNILElBQUksVUFBVSxHQUFHLENBQUMsU0FBUztJQUN6QixFQUFFLENBQUMsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQyxDQUFDLENBQUM7UUFDaEMsSUFBSSxhQUFhLEdBQUcsUUFBUSxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsT0FBTyxTQUFTLEVBQUUsQ0FBQTtRQUN6RSw2QkFBNkI7UUFDN0IsTUFBTSxDQUFDLGFBQWEsQ0FBQTtJQUN0QixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDTixNQUFNLENBQUMsU0FBUyxDQUFBO0lBQ2xCLENBQUM7QUFDSCxDQUFDLENBQUE7QUFFRDs7O0dBR0c7QUFDUSxRQUFBLElBQUksR0FBRyxDQUFDLGdCQUF3QjtJQUN6QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxnQkFBZ0IsQ0FBQyxFQUFFLEVBQUUsS0FBSyxFQUFFLElBQUksRUFBRSxFQUFFLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxNQUFNO1FBQ3ZGLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7WUFDWCxPQUFPLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQyxDQUFBO1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