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.

78 lines (77 loc) 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = startExecutor; const pc = require("picocolors"); const devkit_1 = require("@nx/devkit"); const child_process_1 = require("child_process"); const path_1 = require("path"); let childProcess; async function* startExecutor(options, context) { const projectRoot = context.projectsConfigurations.projects[context.projectName].root; try { const baseUrl = `http://localhost:${options.port}`; devkit_1.logger.info(pc.cyan(`Packager is ready at ${baseUrl}`)); await startAsync(context.root, projectRoot, options); yield { baseUrl, success: true, }; } finally { if (childProcess) { childProcess.kill(); } } } function startAsync(workspaceRoot, projectRoot, options) { return new Promise((resolve, reject) => { childProcess = (0, child_process_1.fork)(require.resolve('@expo/cli/build/bin/cli'), ['start', ...createStartOptions(options)], { cwd: (0, path_1.resolve)(workspaceRoot, projectRoot), env: { RCT_METRO_PORT: options.port.toString(), ...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) => { if (code === 0) { resolve(code); } else { reject(code); } }); }); } // options from https://github.com/expo/expo/blob/main/packages/%40expo/cli/src/start/index.ts const nxOptions = ['sync']; function createStartOptions(options) { return Object.keys(options).reduce((acc, k) => { if (nxOptions.includes(k)) { return acc; } const v = options[k]; if (k === 'dev') { if (v === false) { acc.push(`--no-dev`); // only no-dev flag is supported } } else { 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; }, []); }