|  | 
|  | 1 | +import assert from 'node:assert'; | 
|  | 2 | +import path from 'path'; | 
|  | 3 | +import fs from 'fs-extra'; | 
|  | 4 | +import type { ExampleApp } from '../input'; | 
|  | 5 | + | 
|  | 6 | +export async function getDependencyVersionsFromExampleApp( | 
|  | 7 | + folder: string, | 
|  | 8 | + exampleAppType: ExampleApp | 
|  | 9 | +) { | 
|  | 10 | + const examplePackageJson = await fs.readJSON( | 
|  | 11 | + path.join(folder, 'example', 'package.json') | 
|  | 12 | + ); | 
|  | 13 | + | 
|  | 14 | + const react: string = examplePackageJson.dependencies?.react; | 
|  | 15 | + assert( | 
|  | 16 | + react !== undefined, | 
|  | 17 | + "The generated example app doesn't have React installed." | 
|  | 18 | + ); | 
|  | 19 | + const reactNative: string = examplePackageJson.dependencies?.['react-native']; | 
|  | 20 | + assert( | 
|  | 21 | + reactNative !== undefined, | 
|  | 22 | + "The generated example app doesn't have React Native installed." | 
|  | 23 | + ); | 
|  | 24 | + | 
|  | 25 | + const devDependencies: Record<string, string> = { | 
|  | 26 | + react, | 
|  | 27 | + 'react-native': reactNative, | 
|  | 28 | + }; | 
|  | 29 | + | 
|  | 30 | + if (exampleAppType === 'vanilla') { | 
|  | 31 | + // React Native doesn't provide the community CLI as a dependency. | 
|  | 32 | + // We have to get read the version from the example app and put to the root package json | 
|  | 33 | + const exampleCommunityCLIVersion = | 
|  | 34 | + examplePackageJson.devDependencies['@react-native-community/cli']; | 
|  | 35 | + assert( | 
|  | 36 | + exampleCommunityCLIVersion !== undefined, | 
|  | 37 | + "The generated example app doesn't have community CLI installed" | 
|  | 38 | + ); | 
|  | 39 | + | 
|  | 40 | + devDependencies['@react-native-community/cli'] = exampleCommunityCLIVersion; | 
|  | 41 | + } | 
|  | 42 | + | 
|  | 43 | + return { | 
|  | 44 | + devDependencies, | 
|  | 45 | + }; | 
|  | 46 | +} | 
0 commit comments