113 lines
7.9 KiB
JavaScript
113 lines
7.9 KiB
JavaScript
"use strict";
|
|
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());
|
|
});
|
|
};
|
|
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, silentArg = false, strictArg = false) => {
|
|
let done = plugins.smartq.defer();
|
|
plugins.shelljs.exec(importPath(commandStringArg), { async: true, silent: silentArg }, (code, stdout, stderr) => {
|
|
if (stderr
|
|
&& (stderr !== '')
|
|
&& (!silentArg || strictArg)
|
|
&& (process.env.DEBUG === 'true')) {
|
|
console.log('StdErr found.');
|
|
console.log(stderr);
|
|
}
|
|
if (strictArg) {
|
|
done.reject(new Error(stderr));
|
|
return;
|
|
}
|
|
done.resolve({
|
|
exitCode: code,
|
|
stdout: stdout
|
|
});
|
|
});
|
|
return done.promise;
|
|
};
|
|
/**
|
|
* executes a given command async and silent
|
|
* @param commandStringArg
|
|
*/
|
|
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);
|
|
});
|
|
/**
|
|
* 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzaGVsbC53cmFwL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