Skip to content

Commit 6196f60

Browse files
authored
Add react-native run-macos command (#300)
* Update scripts to publish react-native-macos-init * Clean up merge markers * Start of run-macos cli * run-macos working * Add JSDoc * Fix script to only pass argument when installed * Fixed var name * Added run-macs CI step * Log success or failure
1 parent f9df0ae commit 6196f60

File tree

7 files changed

+380
-13
lines changed

7 files changed

+380
-13
lines changed

.ado/templates/react-native-macos-init.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ steps:
8787
- task: CmdLine@2
8888
displayName: Init new project
8989
inputs:
90-
script: react-native init testcli
90+
script: npx react-native init testcli
9191
workingDirectory: $(Agent.BuildDirectory)
9292

9393
- task: CmdLine@2
@@ -96,4 +96,8 @@ steps:
9696
script: npx react-native-macos-init --version latest --overwrite --prerelease
9797
workingDirectory: $(Agent.BuildDirectory)/testcli
9898

99-
# TODO: react-native run-macos and test when implemented
99+
- task: CmdLine@2
100+
displayName: Run macos
101+
inputs:
102+
script: npx react-native run-macos
103+
workingDirectory: $(Agent.BuildDirectory)/testcli

local-cli/generator-macos/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ function copyProjectTemplateAndReplace(
5959
{ from: path.join(srcRootPath, 'metro.config.macos.js'), to: 'metro.config.macos.js' },
6060
].forEach((mapping) => copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite));
6161

62-
console.log(chalk.white.bold('To run your app on macOS:'));
63-
console.log(chalk.white(` open ${macOSDir}/${xcodeProjName}`));
64-
console.log(chalk.white(' yarn start:macos'));
65-
console.log(chalk.white.bold(`In Xcode switch to the ${projectNameMacOS} scheme then click Run.`));
62+
console.log(`
63+
${chalk.blue(`Run instructions for ${chalk.bold('macOS')}`)}:
64+
• npx react-native run-macos
65+
${chalk.dim('- or -')}
66+
• Open ${macOSDir}/${xcodeProjName} in Xcode or run "xed -b ${macOSDir}"
67+
• yarn start:macos
68+
• Hit the Run button
69+
`);
6670
}
6771

6872
function installDependencies(options) {

local-cli/generator-macos/templates/macos/HelloWorld.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@
12991299
"-ObjC",
13001300
"-lc++",
13011301
);
1302-
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.HelloWorld.$(PRODUCT_NAME:rfc1034identifier)";
1302+
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.$(PRODUCT_NAME:rfc1034identifier)";
13031303
PRODUCT_NAME = HelloWorld;
13041304
VERSIONING_SYSTEM = "apple-generic";
13051305
};
@@ -1317,7 +1317,7 @@
13171317
"-ObjC",
13181318
"-lc++",
13191319
);
1320-
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.HelloWorld.$(PRODUCT_NAME:rfc1034identifier)";
1320+
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.$(PRODUCT_NAME:rfc1034identifier)";
13211321
PRODUCT_NAME = HelloWorld;
13221322
VERSIONING_SYSTEM = "apple-generic";
13231323
};
@@ -1337,7 +1337,7 @@
13371337
"-ObjC",
13381338
"-lc++",
13391339
);
1340-
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.HelloWorld.$(PRODUCT_NAME:rfc1034identifier)";
1340+
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.$(PRODUCT_NAME:rfc1034identifier)";
13411341
PRODUCT_NAME = HelloWorld;
13421342
SDKROOT = macosx;
13431343
TARGETED_DEVICE_FAMILY = 1;
@@ -1358,7 +1358,7 @@
13581358
"-ObjC",
13591359
"-lc++",
13601360
);
1361-
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.HelloWorld.$(PRODUCT_NAME:rfc1034identifier)";
1361+
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.$(PRODUCT_NAME:rfc1034identifier)";
13621362
PRODUCT_NAME = HelloWorld;
13631363
SDKROOT = macosx;
13641364
TARGETED_DEVICE_FAMILY = 1;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
* @format
5+
* @ts-check
6+
*/
7+
'use strict';
8+
9+
const path = require('path');
10+
11+
/**
12+
* @param {string[]} files
13+
*/
14+
function findXcodeProject(files) {
15+
const sortedFiles = files.sort();
16+
for (let i = sortedFiles.length - 1; i >= 0; i--) {
17+
const fileName = files[i];
18+
const ext = path.extname(fileName);
19+
20+
if (ext === '.xcworkspace') {
21+
return {
22+
name: fileName,
23+
isWorkspace: true,
24+
};
25+
}
26+
if (ext === '.xcodeproj') {
27+
return {
28+
name: fileName,
29+
isWorkspace: false,
30+
};
31+
}
32+
}
33+
34+
return null;
35+
}
36+
37+
module.exports = findXcodeProject;

0 commit comments

Comments
 (0)