@nx/react-native
Version:
67 lines (66 loc) • 2.69 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = runAndroidExecutor;
const path_1 = require("path");
const child_process_1 = require("child_process");
const start_impl_1 = require("../start/start.impl");
const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files");
const get_cli_options_1 = require("../../utils/get-cli-options");
let childProcess;
async function* runAndroidExecutor(options, context) {
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
(0, chmod_android_gradle_files_1.chmodAndroidGradlewFiles)((0, path_1.join)(context.root, projectRoot, 'android'));
const tasks = [runCliRunAndroid(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 runCliRunAndroid(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
*/
childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['run-android', ...createRunAndroidOptions(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 createRunAndroidOptions(options) {
return (0, get_cli_options_1.getCliOptions)(options, startOptions, [
'appId',
'appIdSuffix',
'deviceId',
]);
}
;