|
9 | 9 |
|
10 | 10 | import path from 'path';
|
11 | 11 | import fs from 'fs';
|
| 12 | +import process from 'process'; |
12 | 13 | import chalk from 'chalk';
|
13 | 14 | import {logger} from '@react-native-community/cli-tools';
|
14 | 15 |
|
15 | 16 | function printRunInstructions(projectDir: string, projectName: string) {
|
16 |
| - const iosProjectDir = path.resolve(projectDir, 'ios'); |
17 |
| - const iosPodsFile = path.resolve(iosProjectDir, `${projectName}.xcworkspace`); |
18 |
| - const isUsingPods = fs.existsSync(iosPodsFile); |
| 17 | + let iosInstructions = ''; |
| 18 | + let desktopInstructions = ''; |
19 | 19 |
|
20 |
| - const relativeXcodeProjectPath = path.relative( |
21 |
| - '..', |
22 |
| - isUsingPods |
23 |
| - ? iosPodsFile |
24 |
| - : path.resolve(iosProjectDir, `${projectName}.xcodeproj`), |
25 |
| - ); |
| 20 | + if (process.platform === 'darwin') { |
| 21 | + const iosProjectDir = path.resolve(projectDir, 'ios'); |
| 22 | + const iosPodsFile = path.resolve( |
| 23 | + iosProjectDir, |
| 24 | + `${projectName}.xcworkspace`, |
| 25 | + ); |
| 26 | + const isUsingPods = fs.existsSync(iosPodsFile); |
26 | 27 |
|
27 |
| - logger.log(` |
| 28 | + const relativeXcodeProjectPath = path.relative( |
| 29 | + '..', |
| 30 | + isUsingPods |
| 31 | + ? iosPodsFile |
| 32 | + : path.resolve(iosProjectDir, `${projectName}.xcodeproj`), |
| 33 | + ); |
| 34 | + |
| 35 | + iosInstructions = ` |
28 | 36 | ${chalk.cyan(`Run instructions for ${chalk.bold('iOS')}`)}:
|
29 | 37 | • cd "${projectDir}" && npx react-native run-ios
|
30 | 38 | ${chalk.dim('- or -')}
|
31 | 39 | • Open ${relativeXcodeProjectPath} in Xcode or run "xed -b ios"
|
32 | 40 | • Hit the Run button
|
| 41 | + `; |
| 42 | + |
| 43 | + desktopInstructions = ` |
| 44 | + ${chalk.magenta(`Run instructions for ${chalk.bold('macOS')}`)}: |
| 45 | + • See ${chalk.underline( |
| 46 | + 'https://aka.ms/ReactNativeGuideMacOS', |
| 47 | + )} for the latest up-to-date instructions. |
| 48 | + `; |
| 49 | + } |
33 | 50 |
|
| 51 | + if (process.platform === 'win32') { |
| 52 | + desktopInstructions = ` |
| 53 | + ${chalk.cyan(`Run instructions for ${chalk.bold('Windows')}`)}: |
| 54 | + • See ${chalk.underline( |
| 55 | + 'https://aka.ms/ReactNativeGuideWindows', |
| 56 | + )} for the latest up-to-date instructions. |
| 57 | + `; |
| 58 | + } |
| 59 | + |
| 60 | + const androidInstructions = ` |
34 | 61 | ${chalk.green(`Run instructions for ${chalk.bold('Android')}`)}:
|
35 | 62 | • Have an Android emulator running (quickest way to get started), or a device connected.
|
36 | 63 | • cd "${projectDir}" && npx react-native run-android
|
| 64 | + `; |
37 | 65 |
|
38 |
| - ${chalk.magenta( |
39 |
| - `Run instructions for ${chalk.bold('Windows')} and ${chalk.bold('macOS')}`, |
40 |
| - )}: |
41 |
| - • See ${chalk.underline( |
42 |
| - 'https://aka.ms/ReactNative', |
43 |
| - )} for the latest up-to-date instructions. |
44 |
| -`); |
| 66 | + logger.log(` |
| 67 | + ${androidInstructions}${iosInstructions}${desktopInstructions} |
| 68 | + `); |
45 | 69 | }
|
46 | 70 |
|
47 | 71 | export default printRunInstructions;
|
0 commit comments