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

107 lines (106 loc) 5.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reactNativeApplicationGenerator = reactNativeApplicationGenerator; exports.reactNativeApplicationGeneratorInternal = reactNativeApplicationGeneratorInternal; const devkit_1 = require("@nx/devkit"); const js_1 = require("@nx/js"); const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command"); const add_linting_1 = require("../../utils/add-linting"); const add_jest_1 = require("../../utils/add-jest"); const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files"); const pod_install_task_1 = require("../../utils/pod-install-task"); const web_configuration_1 = require("../web-configuration/web-configuration"); const normalize_options_1 = require("./lib/normalize-options"); const init_1 = require("../init/init"); const add_project_1 = require("./lib/add-project"); const create_application_files_1 = require("./lib/create-application-files"); const add_e2e_1 = require("./lib/add-e2e"); const ensure_dependencies_1 = require("../../utils/ensure-dependencies"); const sync_deps_impl_1 = require("../../executors/sync-deps/sync-deps.impl"); const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup"); const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields"); async function reactNativeApplicationGenerator(host, schema) { return await reactNativeApplicationGeneratorInternal(host, { addPlugin: false, useProjectJson: true, ...schema, }); } async function reactNativeApplicationGeneratorInternal(host, schema) { const tasks = []; const jsInitTask = await (0, js_1.initGenerator)(host, { ...schema, skipFormat: true, addTsPlugin: schema.useTsSolution, formatter: schema.formatter, platform: 'web', }); tasks.push(jsInitTask); const options = await (0, normalize_options_1.normalizeOptions)(host, schema); const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true }); tasks.push(initTask); if (!options.skipPackageJson) { tasks.push((0, ensure_dependencies_1.ensureDependencies)(host)); } await (0, create_application_files_1.createApplicationFiles)(host, options); (0, add_project_1.addProject)(host, options); // If we are using the new TS solution // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project if (options.isTsSolutionSetup) { await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot); } const lintTask = await (0, add_linting_1.addLinting)(host, { ...options, projectRoot: options.appProjectRoot, tsConfigPaths: [ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'), ], }); tasks.push(lintTask); const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson, options.addPlugin, 'tsconfig.app.json'); tasks.push(jestTask); const webTask = await (0, web_configuration_1.webConfigurationGenerator)(host, { ...options, project: options.projectName, skipFormat: true, }); tasks.push(webTask); const e2eTask = await (0, add_e2e_1.addE2e)(host, options); tasks.push(e2eTask); const chmodTaskGradlewTask = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot)); tasks.push(chmodTaskGradlewTask); const podInstallTask = (0, pod_install_task_1.runPodInstall)((0, devkit_1.joinPathFragments)(host.root, options.iosProjectRoot)); if (options.install) { const projectPackageJsonPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'); const workspacePackageJson = (0, devkit_1.readJson)(host, 'package.json'); const projectPackageJson = (0, devkit_1.readJson)(host, projectPackageJsonPath); await (0, sync_deps_impl_1.syncDeps)(options.name, projectPackageJson, projectPackageJsonPath, workspacePackageJson); tasks.push(podInstallTask); } else { devkit_1.output.log({ title: 'Skip `pod install`', bodyLines: [ `run 'nx run ${options.name}:pod-install' to install native modules before running iOS app`, ], }); } (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.appProjectRoot, 'tsconfig.app.json', { jsx: 'react-jsx', module: 'esnext', moduleResolution: 'bundler', noUnusedLocals: false, lib: ['dom'], }, options.linter === 'eslint' ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs'] : undefined); (0, sort_fields_1.sortPackageJsonFields)(host, options.appProjectRoot); if (!options.skipFormat) { await (0, devkit_1.formatFiles)(host); } tasks.push(() => { (0, log_show_project_command_1.logShowProjectCommand)(options.projectName); }); return (0, devkit_1.runTasksInSerial)(...tasks); } exports.default = reactNativeApplicationGenerator;