smartshell/dist/smartshell.wrap.js

113 lines
7.9 KiB
JavaScript
Raw Normal View History

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-10-30 19:46:08 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21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