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

91 lines (90 loc) 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reactNativeInitGenerator = reactNativeInitGenerator; exports.reactNativeInitGeneratorInternal = reactNativeInitGeneratorInternal; exports.updateDependencies = updateDependencies; const devkit_1 = require("@nx/devkit"); const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin"); const plugin_1 = require("../../../plugins/plugin"); const versions_1 = require("../../utils/versions"); const add_git_ignore_entry_1 = require("./lib/add-git-ignore-entry"); function reactNativeInitGenerator(host, schema) { return reactNativeInitGeneratorInternal(host, { addPlugin: false, ...schema, }); } async function reactNativeInitGeneratorInternal(host, schema) { (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host); const nxJson = (0, devkit_1.readNxJson)(host); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false; schema.addPlugin ??= addPluginDefault; if (schema.addPlugin) { await (0, add_plugin_1.addPluginV1)(host, await (0, devkit_1.createProjectGraphAsync)(), '@nx/react-native/plugin', plugin_1.createNodes, { startTargetName: ['start', 'react-native:start', 'react-native-start'], upgradeTargetName: [ 'update', 'react-native:update', 'react-native-update', ], bundleTargetName: [ 'bundle', 'react-native:bundle', 'react-native-bundle', ], podInstallTargetName: [ 'pod-install', 'react-native:pod-install', 'react-native-pod-install', ], runIosTargetName: [ 'run-ios', 'react-native:run-ios', 'react-native-run-ios', ], runAndroidTargetName: [ 'run-android', 'react-native:run-android', 'react-native-run-android', ], buildIosTargetName: [ 'build-ios', 'react-native:build-ios', 'react-native-build-ios', ], buildAndroidTargetName: [ 'build-android', 'react-native:build-android', 'react-native-build-android', ], syncDepsTargetName: [ 'sync-deps', 'react-native:sync-deps', 'react-native-sync-deps', ], }, schema.updatePackageScripts); } const tasks = []; if (!schema.skipPackageJson) { tasks.push(moveDependency(host)); tasks.push(updateDependencies(host, schema)); } if (!schema.skipFormat) { await (0, devkit_1.formatFiles)(host); } return (0, devkit_1.runTasksInSerial)(...tasks); } function updateDependencies(host, schema) { return (0, devkit_1.addDependenciesToPackageJson)(host, { react: versions_1.reactVersion, 'react-dom': versions_1.reactDomVersion, 'react-native': versions_1.reactNativeVersion, }, { '@nx/react-native': versions_1.nxVersion, }, undefined, schema.keepExistingVersions); } function moveDependency(host) { return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react-native'], []); } exports.default = reactNativeInitGenerator;