@nx/expo
Version:
72 lines (71 loc) • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = prebuildExecutor;
exports.prebuildAsync = prebuildAsync;
const devkit_1 = require("@nx/devkit");
const internal_1 = require("@nx/devkit/internal");
const child_process_1 = require("child_process");
const path_1 = require("path");
const pod_install_task_1 = require("../../utils/pod-install-task");
let childProcess;
async function* prebuildExecutor(options, context) {
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
try {
await prebuildAsync(context.root, projectRoot, options);
if (options.install) {
const { installAsync, } = require('@expo/cli/build/src/install/installAsync');
await installAsync([], {});
if (options.platform === 'ios') {
(0, pod_install_task_1.podInstall)((0, path_1.join)(context.root, projectRoot, 'ios'));
}
}
yield {
success: true,
};
}
finally {
if (childProcess) {
childProcess.kill();
}
}
}
function prebuildAsync(workspaceRoot, projectRoot, options) {
return new Promise((resolve, reject) => {
childProcess = (0, child_process_1.fork)(require.resolve('@expo/cli/build/bin/cli'), ['prebuild', ...createPrebuildOptions(options), '--no-install'], { cwd: (0, path_1.join)(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);
}
});
});
}
const nxOptions = ['install', 'interactive']; // interactive is passed in by e2e tests
// options from https://github.com/expo/expo/blob/main/packages/%40expo/cli/src/prebuild/index.ts
function createPrebuildOptions(options) {
return Object.keys(options).reduce((acc, k) => {
if (!nxOptions.includes(k)) {
const v = options[k];
if (typeof v === 'boolean') {
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;
}, []);
}