UNPKG

@nx/expo

Version:

The Expo Plugin for Nx contains executors and generators for managing and developing an expo application within your workspace. For example, you can directly build for different target platforms as well as generate projects and publish your code.

100 lines (99 loc) 3.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = runExecutor; const devkit_1 = require("@nx/devkit"); const internal_1 = require("@nx/devkit/internal"); const child_process_1 = require("child_process"); const node_fs_1 = require("node:fs"); const os_1 = require("os"); const path_1 = require("path"); const prebuild_impl_1 = require("../prebuild/prebuild.impl"); const pod_install_task_1 = require("../../utils/pod-install-task"); let childProcess; async function* runExecutor(options, context) { if ((0, os_1.platform)() !== 'darwin' && options.platform === 'ios') { throw new Error(`The run-ios build requires Mac to run`); } const projectRoot = context.projectsConfigurations.projects[context.projectName].root; if (!(0, node_fs_1.existsSync)((0, path_1.join)(context.root, projectRoot, options.platform))) { await (0, prebuild_impl_1.prebuildAsync)(context.root, projectRoot, { install: options.install, platform: options.platform, clean: options.clean, }); } 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')); } } try { await runCliRun(context.root, projectRoot, options); yield { success: true }; } finally { if (childProcess) { childProcess.kill(); } } } function runCliRun(workspaceRoot, projectRoot, options) { return new Promise((resolve, reject) => { childProcess = (0, child_process_1.fork)(require.resolve('@expo/cli/build/bin/cli'), ['run:' + options.platform, ...createRunOptions(options), '--no-install'], // pass in no-install to prevent node_modules install { 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); } }); }); } const nxOptions = ['platform', 'clean']; const iOSOptions = ['xcodeConfiguration', 'schema']; const androidOptions = ['variant']; /* * run options: * ios: https://github.com/expo/expo/blob/main/packages/@expo/cli/src/run/ios/index.ts * android: https://github.com/expo/expo/blob/main/packages/@expo/cli/src/run/android/index.ts */ function createRunOptions(options) { return Object.keys(options).reduce((acc, k) => { if (nxOptions.includes(k) || (options.platform === 'ios' && androidOptions.includes(k)) || (options.platform === 'android' && iOSOptions.includes(k))) { return acc; } const v = options[k]; { if (k === 'xcodeConfiguration') { acc.push('--configuration', v); } else if (typeof v === 'boolean') { // no need to pass in the flag when it is true, pass the --no-<flag> when it is false. e.g. --no-build-cache, --no-bundler if (v === false) { acc.push(`--no-${(0, devkit_1.names)(k).fileName}`); } } else { acc.push(`--${(0, devkit_1.names)(k).fileName}`, v); } } return acc; }, []); }