smartshell/dist/smartshell.wrap.js

76 lines
4.9 KiB
JavaScript
Raw Normal View History

2017-03-10 19:14:40 +00:00
"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) => {
let childProcessEnded = plugins.smartq.defer();
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
};
};
2017-06-22 16:17:45 +00:00
/**
* executes a command and returns promise that will be fullfilled once an putput line matches RegexArg
* @param commandStringArg
* @param regexArg
*/
exports.execAndWaitForLine = (commandStringArg, regexArg) => {
let done = plugins.smartq.defer();
let execStreamingResult = exports.execStreaming(commandStringArg);
execStreamingResult.childProcess.on('data', (stdOutChunk) => {
if (regexArg.test(stdOutChunk)) {
done.resolve();
}
});
return done.promise;
};
2017-03-11 12:46:08 +00:00
/**
* 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;
};
2017-06-22 16:17:45 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc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