@nx/react-native
Version:
66 lines (65 loc) • 2.55 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = runIosExecutor;
const path_1 = require("path");
const child_process_1 = require("child_process");
const os_1 = require("os");
const start_impl_1 = require("../start/start.impl");
const get_cli_options_1 = require("../../utils/get-cli-options");
async function* runIosExecutor(options, context) {
if ((0, os_1.platform)() !== 'darwin') {
throw new Error(`The run-ios build requires Mac to run`);
}
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
const tasks = [runCliRunIOS(context.root, projectRoot, options)];
if (options.mode !== 'Release') {
tasks.push((0, start_impl_1.runCliStart)(context.root, projectRoot, {
port: options.port,
resetCache: options.resetCache,
interactive: true,
}));
}
await Promise.all(tasks);
yield { success: true };
}
function runCliRunIOS(workspaceRoot, projectRoot, options) {
return new Promise((resolve, reject) => {
/**
* Call the react native cli with option `--no-packager`
* Not passing '--packager' due to cli will launch start command from the project root
*/
const childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['run-ios', ...createRunIOSOptions(options), '--no-packager'], {
stdio: 'inherit',
cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
});
/**
* Ensure the child process is killed when the parent exits
*/
const processExitListener = (signal) => () => {
childProcess.kill(signal);
process.exit();
};
process.once('exit', (signal) => childProcess.kill(signal));
process.once('SIGTERM', processExitListener);
process.once('SIGINT', processExitListener);
process.once('SIGQUIT', processExitListener);
childProcess.on('error', (err) => {
reject(err);
});
childProcess.on('exit', (code) => {
if (code === 0) {
resolve(childProcess);
}
else {
reject(code);
}
});
});
}
const startOptions = ['port', 'resetCache'];
function createRunIOSOptions(options) {
return (0, get_cli_options_1.getCliOptions)(options, startOptions, [
'buildFolder',
]);
}
;