2017-03-10 19:14:40 +00:00
|
|
|
"use strict";
|
2017-07-19 12:56:33 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2017-03-10 19:14:40 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const plugins = require("./smartshell.plugins");
|
2017-07-18 13:17:05 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
};
|
2017-03-10 19:14:40 +00:00
|
|
|
/**
|
|
|
|
* executes a given command async
|
|
|
|
* @param commandStringArg
|
|
|
|
*/
|
2017-07-19 12:56:33 +00:00
|
|
|
exports.exec = (commandStringArg, silentArg = false, strictArg = false) => {
|
2017-03-10 19:14:40 +00:00
|
|
|
let done = plugins.smartq.defer();
|
2017-07-19 12:56:33 +00:00
|
|
|
plugins.shelljs.exec(importPath(commandStringArg), { async: true, silent: silentArg }, (code, stdout, stderr) => {
|
2017-09-09 11:20:24 +00:00
|
|
|
if (stderr
|
|
|
|
&& (stderr !== '')
|
|
|
|
&& (!silentArg || strictArg)
|
|
|
|
&& (process.env.DEBUG === 'true')) {
|
|
|
|
console.log('StdErr found.');
|
2017-07-18 13:17:05 +00:00
|
|
|
console.log(stderr);
|
2017-07-19 12:56:33 +00:00
|
|
|
}
|
|
|
|
if (strictArg) {
|
|
|
|
done.reject(new Error(stderr));
|
2017-07-18 13:17:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-10 19:14:40 +00:00
|
|
|
done.resolve({
|
|
|
|
exitCode: code,
|
|
|
|
stdout: stdout
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* executes a given command async and silent
|
|
|
|
* @param commandStringArg
|
|
|
|
*/
|
2017-07-19 12:56:33 +00:00
|
|
|
exports.execSilent = (commandStringArg) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return yield exports.exec(commandStringArg, true);
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* executes strict, meaning it rejects the promise if something happens
|
|
|
|
*/
|
|
|
|
exports.execStrict = (commandStringArg) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return yield exports.exec(commandStringArg, true, true);
|
|
|
|
});
|
2017-03-10 19:14:40 +00:00
|
|
|
/**
|
|
|
|
* executes a command and allws you to stream output
|
|
|
|
*/
|
2017-06-27 09:18:37 +00:00
|
|
|
exports.execStreaming = (commandStringArg, silentArg = false) => {
|
2017-03-10 19:14:40 +00:00
|
|
|
let childProcessEnded = plugins.smartq.defer();
|
2017-07-18 13:17:05 +00:00
|
|
|
let execChildProcess = plugins.shelljs.exec(importPath(commandStringArg), { async: true, silent: silentArg }, (code, stdout, stderr) => {
|
2017-03-10 19:14:40 +00:00
|
|
|
childProcessEnded.resolve({
|
|
|
|
exitCode: code,
|
|
|
|
stdout: stdout
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
childProcess: execChildProcess,
|
|
|
|
finalPromise: childProcessEnded.promise
|
|
|
|
};
|
|
|
|
};
|
2017-06-27 09:18:37 +00:00
|
|
|
exports.execStreamingSilent = (commandStringArg) => {
|
|
|
|
return exports.execStreaming(commandStringArg, true);
|
|
|
|
};
|
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
|
|
|
|
*/
|
2017-06-27 09:18:37 +00:00
|
|
|
exports.execAndWaitForLine = (commandStringArg, regexArg, silentArg = false) => {
|
2017-06-22 16:17:45 +00:00
|
|
|
let done = plugins.smartq.defer();
|
2017-06-27 09:18:37 +00:00
|
|
|
let execStreamingResult = exports.execStreaming(commandStringArg, silentArg);
|
2017-06-27 08:28:11 +00:00
|
|
|
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk) => {
|
2017-06-22 16:17:45 +00:00
|
|
|
if (regexArg.test(stdOutChunk)) {
|
|
|
|
done.resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2017-06-27 09:18:37 +00:00
|
|
|
exports.execAndWaitForLineSilent = (commandStringArg, regexArg) => {
|
|
|
|
exports.execAndWaitForLine(commandStringArg, regexArg, true);
|
|
|
|
};
|
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-09-09 11:20:24 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzaGVsbC53cmFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxnREFBK0M7QUFzQi9DOztHQUVHO0F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