@elinzy/e-core
Version:
e core implementation module
77 lines (73 loc) • 5.21 kB
JavaScript
;
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.cjs');
var execa = require('execa');
var c = require('ansis');
function exec(cmd, args, opts) {
if (opts !== null && opts !== void 0 && opts.logger || opts !== null && opts !== void 0 && opts.dryRun) console.log(c.green("> ".concat([cmd].concat(_rollupPluginBabelHelpers.toConsumableArray(args)).join(" "))));
if (opts !== null && opts !== void 0 && opts.dryRun) return Promise.resolve(void 0);
return execa.execa(cmd, args, opts).then(function (spawned) {
return opts !== null && opts !== void 0 && opts.abbrev ? spawned === null || spawned === void 0 ? void 0 : spawned.stdout : spawned;
})["catch"](function (e) {
var _opts$throwOnError;
if ((_opts$throwOnError = opts === null || opts === void 0 ? void 0 : opts.throwOnError) !== null && _opts$throwOnError !== void 0 ? _opts$throwOnError : true) throw new Error(c.red("Running ".concat(c.bold([cmd].concat(_rollupPluginBabelHelpers.toConsumableArray(args)).join(" ")), " in ").concat(c.underline((opts === null || opts === void 0 ? void 0 : opts.cwd) || (e === null || e === void 0 ? void 0 : e.cwd) || process.cwd()), ":")) + (e.stderr || e.stack || e.message));
return Promise.resolve(void 0);
});
}
function execSync(cmd, args, opts) {
if (opts !== null && opts !== void 0 && opts.logger || opts !== null && opts !== void 0 && opts.dryRun) console.log(c.green("> ".concat([cmd].concat(_rollupPluginBabelHelpers.toConsumableArray(args)).join(" "))));
if (opts !== null && opts !== void 0 && opts.dryRun) return void 0;
try {
var spawned = execa.execaSync(cmd, args, opts);
return opts !== null && opts !== void 0 && opts.abbrev ? spawned === null || spawned === void 0 ? void 0 : spawned.stdout : spawned;
} catch (e) {
var _opts$throwOnError2;
if ((_opts$throwOnError2 = opts === null || opts === void 0 ? void 0 : opts.throwOnError) !== null && _opts$throwOnError2 !== void 0 ? _opts$throwOnError2 : true) throw new Error(c.red("Running ".concat(c.bold([cmd].concat(_rollupPluginBabelHelpers.toConsumableArray(args)).join(" ")), " in ").concat(c.underline((opts === null || opts === void 0 ? void 0 : opts.cwd) || (e === null || e === void 0 ? void 0 : e.cwd) || process.cwd()), ":")) + (e.stderr || e.stack || e.message));
return void 0;
}
}
function execCommand(_x, _x2) {
return _execCommand.apply(this, arguments);
}
function _execCommand() {
_execCommand = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regeneratorRuntime().mark(function _callee(cmd, opts) {
return _rollupPluginBabelHelpers.regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (opts !== null && opts !== void 0 && opts.logger || opts !== null && opts !== void 0 && opts.dryRun) console.log(c.green("> ".concat([cmd].join(" "))));
if (!(opts !== null && opts !== void 0 && opts.dryRun)) {
_context.next = 3;
break;
}
return _context.abrupt("return", Promise.resolve(void 0));
case 3:
return _context.abrupt("return", execa.execaCommand(cmd, opts).then(function (spawned) {
return opts !== null && opts !== void 0 && opts.abbrev ? spawned === null || spawned === void 0 ? void 0 : spawned.stdout : spawned;
})["catch"](function (e) {
var _opts$throwOnError4;
if ((_opts$throwOnError4 = opts === null || opts === void 0 ? void 0 : opts.throwOnError) !== null && _opts$throwOnError4 !== void 0 ? _opts$throwOnError4 : true) throw new Error(c.red("Running ".concat(c.bold([cmd].join(" ")), " in ").concat(c.underline((opts === null || opts === void 0 ? void 0 : opts.cwd) || (e === null || e === void 0 ? void 0 : e.cwd) || process.cwd()), ":")) + (e.stderr || e.stack || e.message));
return Promise.resolve(void 0);
}));
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return _execCommand.apply(this, arguments);
}
function execCommandSync(cmd, opts) {
if (opts !== null && opts !== void 0 && opts.logger || opts !== null && opts !== void 0 && opts.dryRun) console.log(c.green("> ".concat([cmd].join(" "))));
if (opts !== null && opts !== void 0 && opts.dryRun) return void 0;
try {
var spawned = execa.execaCommandSync(cmd, opts);
return opts !== null && opts !== void 0 && opts.abbrev ? spawned === null || spawned === void 0 ? void 0 : spawned.stdout : spawned;
} catch (e) {
var _opts$throwOnError3;
if ((_opts$throwOnError3 = opts === null || opts === void 0 ? void 0 : opts.throwOnError) !== null && _opts$throwOnError3 !== void 0 ? _opts$throwOnError3 : true) throw new Error(c.red("Running ".concat(c.bold([cmd].join(" ")), " in ").concat(c.underline((opts === null || opts === void 0 ? void 0 : opts.cwd) || (e === null || e === void 0 ? void 0 : e.cwd) || process.cwd()), ":")) + (e.stderr || e.stack || e.message));
return void 0;
}
}
exports.exec = exec;
exports.execCommand = execCommand;
exports.execCommandSync = execCommandSync;
exports.execSync = execSync;