diff --git a/packages/react-native/local-cli/localCommands.js b/packages/react-native/local-cli/localCommands.js new file mode 100644 index 00000000000000..4f4deb815c39b9 --- /dev/null +++ b/packages/react-native/local-cli/localCommands.js @@ -0,0 +1,45 @@ +const { + createBuild, + createLog, + createRun, + getRunOptions, + getLogOptions, + getBuildOptions, + } = require('@react-native-community/cli-platform-apple'); + +const platformName = 'macos'; + +const run = { +name: 'run-macos', +description: 'builds your app and starts it on visionOS simulator', +func: createRun({platformName}), +examples: [ + { + desc: 'Run on a specific simulator', + cmd: 'npx react-native-macos run-macos', + }, +], +options: getRunOptions({platformName}), +}; + +const log = { +name: 'log-macos', +description: 'starts macOS syslog tail', +func: createLog({platformName: 'macos'}), +options: getLogOptions({platformName}), +}; + +const build = { +name: 'build-macos', +description: 'builds your app for visionOS platform', +func: createBuild({platformName}), +examples: [ + { + desc: 'Build the app for all visionOS devices in Release mode', + cmd: 'npx react-native-macos build-macos --mode "Release"', + }, +], +options: getBuildOptions({platformName}), +}; + +module.exports = [run, log, build]; diff --git a/packages/react-native/package.json b/packages/react-native/package.json index d4b6f2976f79f3..1c726f968e4c0b 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -112,6 +112,7 @@ "@jest/create-cache-key-function": "^29.6.3", "@react-native-community/cli": "14.0.0-alpha.2", "@react-native-community/cli-platform-android": "14.0.0-alpha.2", + "@react-native-community/cli-platform-apple": "^14.0.0", "@react-native-community/cli-platform-ios": "14.0.0-alpha.2", "@react-native-mac/virtualized-lists": "0.75.0-main", "@react-native/assets-registry": "0.75.0-main", diff --git a/packages/react-native/react-native.config.js b/packages/react-native/react-native.config.js index ed8873c3b716a3..89f09e0c6cdf79 100644 --- a/packages/react-native/react-native.config.js +++ b/packages/react-native/react-native.config.js @@ -42,6 +42,20 @@ try { } } +// [macOS +let apple; +try { + apple = require('@react-native-community/cli-platform-apple'); +} catch { + if (verbose) { + console.warn( + '@react-native-community/cli-platform-apple not found, the react-native.config.js may be unusable.', + ); + } +} +// macOS] + +const localCommands = require('./local-cli/localCommands'); // [macOS] const { bundleCommand, startCommand, @@ -96,41 +110,13 @@ if (android != null) { } // [macOS -// const macosCommands = [require('./local-cli/runMacOS/runMacOS')]; -// config.commands.push(...macosCommands); -config.platforms.macos = { - linkConfig: () => { - return { - isInstalled: ( - _projectConfig /*ProjectConfig*/, - _package /*string*/, - _dependencyConfig /*DependencyConfig*/, - ) => false /*boolean*/, - register: ( - _package /*string*/, - _dependencyConfig /*DependencyConfig*/, - _obj /*Object*/, - _projectConfig /*ProjectConfig*/, - ) => {}, - unregister: ( - _package /*string*/, - _dependencyConfig /*DependencyConfig*/, - _projectConfig /*ProjectConfig*/, - _dependencyConfigs /*Array*/, - ) => {}, - copyAssets: ( - _assets /*string[]*/, - _projectConfig /*ProjectConfig*/, - ) => {}, - unlinkAssets: ( - _assets /*string[]*/, - _projectConfig /*ProjectConfig*/, - ) => {}, - }; - }, - projectConfig: () => null, - dependencyConfig: () => null, - npmPackageName: 'react-native-macos', +if (apple != null) { + config.commands.push(...localCommands); + config.platforms.macos = { + npmPackageName: 'react-native-macos', + projectConfig: apple.getProjectConfig({platformName: 'macos'}), + dependencyConfig: apple.getDependencyConfig({platformName: 'macos'}), + }; } // macOS] diff --git a/yarn.lock b/yarn.lock index 30e1cf4f3b0227..4705cddeb124a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3796,6 +3796,20 @@ __metadata: languageName: node linkType: hard +"@react-native-community/cli-platform-apple@npm:^14.0.0": + version: 14.0.0 + resolution: "@react-native-community/cli-platform-apple@npm:14.0.0" + dependencies: + "@react-native-community/cli-tools": "npm:14.0.0" + chalk: "npm:^4.1.2" + execa: "npm:^5.0.0" + fast-glob: "npm:^3.3.2" + fast-xml-parser: "npm:^4.2.4" + ora: "npm:^5.4.1" + checksum: 10c0/057e3f4d366fc8e93895f6ac5f5790b8304bb38cbc340b44bd275a14e9e262f5c91b3c72cfb67b9509ac597759f7ba6bca69a9452a343035cbc9c02d5702696d + languageName: node + linkType: hard + "@react-native-community/cli-platform-ios@npm:13.5.1": version: 13.5.1 resolution: "@react-native-community/cli-platform-ios@npm:13.5.1" @@ -3946,6 +3960,24 @@ __metadata: languageName: node linkType: hard +"@react-native-community/cli-tools@npm:14.0.0": + version: 14.0.0 + resolution: "@react-native-community/cli-tools@npm:14.0.0" + dependencies: + appdirsjs: "npm:^1.2.4" + chalk: "npm:^4.1.2" + execa: "npm:^5.0.0" + find-up: "npm:^5.0.0" + mime: "npm:^2.4.1" + open: "npm:^6.2.0" + ora: "npm:^5.4.1" + semver: "npm:^7.5.2" + shell-quote: "npm:^1.7.3" + sudo-prompt: "npm:^9.0.0" + checksum: 10c0/7940b4af353b0b4e520c39fc98a438505fd2850931d2d5ec9395ec3deb7bbb5eb33c3817c5364b0eefa2525be069a4301b0b5073b4bae5867e0253d31f2d5f13 + languageName: node + linkType: hard + "@react-native-community/cli-tools@npm:14.0.0-alpha.2": version: 14.0.0-alpha.2 resolution: "@react-native-community/cli-tools@npm:14.0.0-alpha.2" @@ -14272,6 +14304,7 @@ __metadata: "@jest/create-cache-key-function": "npm:^29.6.3" "@react-native-community/cli": "npm:14.0.0-alpha.2" "@react-native-community/cli-platform-android": "npm:14.0.0-alpha.2" + "@react-native-community/cli-platform-apple": "npm:^14.0.0" "@react-native-community/cli-platform-ios": "npm:14.0.0-alpha.2" "@react-native-mac/virtualized-lists": "npm:0.75.0-main" "@react-native/assets-registry": "npm:0.75.0-main"