Skip to content

Commit 5ec3fcf

Browse files
Simekthymikee
andauthored
feat: adjust run instruction based on the user platform (#1285)
* chore: adjust run instruction based on the user platform * chore: adjust whitespaces in run instructions * Update packages/cli/src/commands/init/printRunInstructions.ts * fix 'undefined' printed in instructions on Windows * use short URLs * fix black font in PS by changing Windows instructions header color Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 7238b20 commit 5ec3fcf

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

packages/cli/src/commands/init/printRunInstructions.ts

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,63 @@
99

1010
import path from 'path';
1111
import fs from 'fs';
12+
import process from 'process';
1213
import chalk from 'chalk';
1314
import {logger} from '@react-native-community/cli-tools';
1415

1516
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 = '';
1919

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);
2627

27-
logger.log(`
28+
const relativeXcodeProjectPath = path.relative(
29+
'..',
30+
isUsingPods
31+
? iosPodsFile
32+
: path.resolve(iosProjectDir, `${projectName}.xcodeproj`),
33+
);
34+
35+
iosInstructions = `
2836
${chalk.cyan(`Run instructions for ${chalk.bold('iOS')}`)}:
2937
• cd "${projectDir}" && npx react-native run-ios
3038
${chalk.dim('- or -')}
3139
• Open ${relativeXcodeProjectPath} in Xcode or run "xed -b ios"
3240
• 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+
}
3350

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 = `
3461
${chalk.green(`Run instructions for ${chalk.bold('Android')}`)}:
3562
• Have an Android emulator running (quickest way to get started), or a device connected.
3663
• cd "${projectDir}" && npx react-native run-android
64+
`;
3765

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+
`);
4569
}
4670

4771
export default printRunInstructions;

0 commit comments

Comments
 (0)