UNPKG

@nx/react-native

Version:

The Nx Plugin for React Native contains generators for managing React Native applications and libraries within an Nx workspace. It provides: -Integration with libraries such as Jest, Detox, and Storybook. -Scaffolding for creating buildable libraries th

57 lines (56 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = bundleExecutor; const fileutils_1 = require("@nx/workspace/src/utilities/fileutils"); const devkit_1 = require("@nx/devkit"); const path_1 = require("path"); const child_process_1 = require("child_process"); async function* bundleExecutor(options, context) { const projectRoot = context.projectsConfigurations.projects[context.projectName].root; options.bundleOutput = (0, path_1.join)(context.root, options.bundleOutput); (0, fileutils_1.createDirectory)((0, path_1.dirname)(options.bundleOutput)); await runCliBuild(context.root, projectRoot, options); yield { success: true }; } function runCliBuild(workspaceRoot, projectRoot, options) { return new Promise((resolve, reject) => { const cliOptions = createBundleOptions(options); const childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['bundle', ...cliOptions], { stdio: 'inherit', cwd: (0, path_1.resolve)(workspaceRoot, projectRoot), env: process.env, }); /** * 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); } }); }); } function createBundleOptions(options) { return Object.keys(options).reduce((acc, _k) => { const v = options[_k]; const k = (0, devkit_1.names)(_k).fileName; if (v === undefined) return acc; acc.push(`--${k}`, v); return acc; }, []); }