bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
64 lines (50 loc) • 1.44 kB
JavaScript
function _bluebird() {
const data = require("bluebird");
_bluebird = function () {
return data;
};
return data;
}
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable global-require */
/* eslint-disable no-console */
/* eslint-disable import/no-dynamic-require */
function handleError(error) {
process && process.send ? process.send({
error
}) : console.error(error);
process.exit(1);
}
const pathToTask = process.argv.find(function (value, index, arr) {
if (!index) {
return false;
}
return __filename.endsWith(arr[index - 1]);
});
let userTask;
try {
userTask = require(pathToTask);
} catch (e) {
handleError(new Error('script-container can not find user task'));
}
const toExecute = userTask.default || userTask;
if (typeof toExecute === 'function') {
const getPromisedResult = () => {
const executed = toExecute();
return executed && executed.then ? executed : Promise.resolve(executed);
};
getPromisedResult().then(userTaskResult => {
process.on('beforeExit', /*#__PURE__*/function () {
var _ref = (0, _bluebird().coroutine)(function* (code) {
const toSend = userTaskResult || {
exitCode: code
};
process.send ? process.send(toSend) : Promise.resolve();
});
return function (_x) {
return _ref.apply(this, arguments);
};
}());
}).catch(handleError);
}
;