82 lines
5.5 KiB
JavaScript
82 lines
5.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./smartshell.plugins");
|
|
/**
|
|
* executes a given command async
|
|
* @param commandStringArg
|
|
*/
|
|
exports.exec = (commandStringArg) => {
|
|
let done = plugins.smartq.defer();
|
|
plugins.shelljs.exec(commandStringArg, { async: true }, (code, stdout, stderr) => {
|
|
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(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => {
|
|
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(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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzaGVsbC53cmFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsZ0RBQStDO0FBc0IvQzs7O0dBR0c7QUFDUSxRQUFBLElBQUksR0FBRyxDQUFDLGdCQUF3QjtJQUN6QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFFLEVBQUUsS0FBSyxFQUFFLElBQUksRUFBRSxFQUFFLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxNQUFNO1FBQzNFLElBQUksQ0FBQyxPQUFPLENBQUM7WUFDWCxRQUFRLEVBQUUsSUFBSTtZQUNkLE1BQU0sRUFBRSxNQUFNO1NBQ2YsQ0FBQyxDQUFBO0lBQ0osQ0FBQyxDQUFDLENBQUE7SUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUE7QUFFRDs7O0dBR0c7QUFDUSxRQUFBLFVBQVUsR0FBRyxDQUFDLGdCQUF3QjtJQUMvQyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxD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