@nx/expo
Version:
74 lines (73 loc) • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = submitExecutor;
const devkit_1 = require("@nx/devkit");
const internal_1 = require("@nx/devkit/internal");
const path_1 = require("path");
const child_process_1 = require("child_process");
const resolve_eas_1 = require("../../utils/resolve-eas");
let childProcess;
async function* submitExecutor(options, context) {
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
try {
await runCliSubmit(context.root, projectRoot, options);
yield { success: true };
}
finally {
if (childProcess) {
childProcess.kill();
}
}
}
function runCliSubmit(workspaceRoot, projectRoot, options) {
return new Promise((resolve, reject) => {
childProcess = (0, child_process_1.fork)((0, resolve_eas_1.resolveEas)(workspaceRoot), ['submit', ...createSubmitOptions(options)], {
cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
env: process.env,
});
// Ensure the child process is killed when the parent exits
process.on('exit', () => childProcess.kill());
process.on('SIGTERM', () => childProcess.kill());
childProcess.on('error', (err) => {
reject(err);
});
childProcess.on('exit', (code, signal) => {
if (code === null)
code = (0, internal_1.signalToCode)(signal);
if (code === 0) {
resolve(code);
}
else {
reject(code);
}
});
});
}
function createSubmitOptions(options) {
return Object.keys(options).reduce((acc, k) => {
const v = options[k];
if (typeof v === 'boolean') {
if (k === 'interactive') {
if (v === false) {
acc.push('--non-interactive'); // when is false, the flag is --non-interactive
}
}
else if (k === 'wait') {
if (v === false) {
acc.push('--no-wait'); // when is false, the flag is --no-wait
}
else {
acc.push('--wait');
}
}
else if (v === true) {
// when true, does not need to pass the value true, just need to pass the flag in kebob case
acc.push(`--${(0, devkit_1.names)(k).fileName}`);
}
}
else {
acc.push(`--${(0, devkit_1.names)(k).fileName}`, v);
}
return acc;
}, []);
}