Skip to content

Commit

Permalink
[WIP] Implement local-cli using '@react-native-community/cli-platform…
Browse files Browse the repository at this point in the history
…-apple'
  • Loading branch information
Saadnajmi committed Aug 19, 2024
1 parent 3b5f59f commit 990e603
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 35 deletions.
45 changes: 45 additions & 0 deletions packages/react-native/local-cli/localCommands.js
Original file line number Diff line number Diff line change
@@ -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];
1 change: 1 addition & 0 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 21 additions & 35 deletions packages/react-native/react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<DependencyConfig>*/,
) => {},
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]

Expand Down
33 changes: 33 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 990e603

Please sign in to comment.