зеркало из https://github.com/microsoft/rnx-kit.git
feat(cli): enable `build` and `run` commands (#3326)
This commit is contained in:
Родитель
718c31f98d
Коммит
a05bdf1bb7
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@rnx-kit/cli": patch
|
||||
---
|
||||
|
||||
`build` and `run` commands are now available for public use
|
|
@ -104,6 +104,10 @@ jobs:
|
|||
if [[ "$(yarn show-affected --base origin/${{ github.base_ref }})" = *"@rnx-kit/test-app"* ]]; then
|
||||
echo 'android=true' >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: Build @rnx-kit/cli
|
||||
if: ${{ steps.affected-projects.outputs.android != '' }}
|
||||
run: |
|
||||
yarn nx build @rnx-kit/cli
|
||||
- name: Build Android app
|
||||
if: ${{ steps.affected-projects.outputs.android != '' }}
|
||||
run: |
|
||||
|
@ -131,6 +135,10 @@ jobs:
|
|||
if [[ "$(yarn show-affected --base origin/${{ github.base_ref }})" = *"@rnx-kit/test-app"* ]]; then
|
||||
echo 'ios=true' >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: Build @rnx-kit/cli
|
||||
if: ${{ steps.affected-projects.outputs.ios != '' }}
|
||||
run: |
|
||||
yarn nx build @rnx-kit/cli
|
||||
- name: Install Pods
|
||||
uses: microsoft/react-native-test-app/.github/actions/cocoapods@trunk
|
||||
if: ${{ steps.affected-projects.outputs.ios != '' }}
|
||||
|
|
|
@ -73,7 +73,7 @@ export const rnxBuildCommand = {
|
|||
func: rnxBuild,
|
||||
options: [
|
||||
{
|
||||
name: "--platform <string>",
|
||||
name: "-p, --platform <string>",
|
||||
description: "Target platform",
|
||||
parse: asSupportedPlatform,
|
||||
},
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import type { Command } from "@react-native-community/cli-types";
|
||||
import { rnxAlignDepsCommand } from "./align-deps";
|
||||
import { rnxBuildCommand } from "./build";
|
||||
import { rnxBundleCommand } from "./bundle";
|
||||
import { rnxCleanCommand } from "./clean";
|
||||
import { rnxCopyAssetsCommand } from "./copy-assets";
|
||||
import { rnxRamBundleCommand } from "./ram-bundle";
|
||||
import { rnxRunCommand } from "./run";
|
||||
import { rnxStartCommand } from "./start";
|
||||
import { rnxTestCommand } from "./test";
|
||||
import { rnxWriteThirdPartyNoticesCommand } from "./write-third-party-notices";
|
||||
|
@ -13,6 +15,8 @@ export const reactNativeConfig = {
|
|||
rnxBundleCommand,
|
||||
rnxRamBundleCommand,
|
||||
rnxStartCommand,
|
||||
rnxBuildCommand,
|
||||
rnxRunCommand,
|
||||
rnxCopyAssetsCommand,
|
||||
rnxAlignDepsCommand,
|
||||
rnxTestCommand,
|
||||
|
|
|
@ -31,7 +31,7 @@ export const rnxRunCommand = {
|
|||
options: [
|
||||
...rnxBuildCommand.options,
|
||||
{
|
||||
name: "--device <string>",
|
||||
name: "-d, --device <string>",
|
||||
description: "The name of the device to launch the app in",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
"scripts": {
|
||||
"android": "rnx run-android --no-packager --appId com.msft.identity.client.sample.local",
|
||||
"build": "rnx align-deps && rnx-kit-scripts build",
|
||||
"build:android": "rnx-kit-scripts build-android clean build",
|
||||
"build:ios": "rnx-kit-scripts build-ios -w SampleCrossApp -s ReactTestApp",
|
||||
"build:android": "rnx build --platform android",
|
||||
"build:ios": "rnx build --platform ios",
|
||||
"bundle": "rnx bundle",
|
||||
"bundle+esbuild": "rnx bundle --id esbuild",
|
||||
"bundle:android": "rnx bundle --platform android",
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
// @ts-check
|
||||
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { spawn } from "../process.js";
|
||||
|
||||
/** @type {import("../process.js").Command} */
|
||||
export async function buildAndroid(_args, rawArgs = []) {
|
||||
const wrapper = os.platform() === "win32" ? "gradlew.bat" : "gradlew";
|
||||
const gradlew = path.resolve("android", wrapper);
|
||||
await spawn(gradlew, rawArgs, { cwd: path.dirname(gradlew) });
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
// @ts-check
|
||||
|
||||
import { URL } from "node:url";
|
||||
import { execute } from "../process.js";
|
||||
|
||||
/** @type {import("../process.js").Command} */
|
||||
export async function buildIOS(_args, rawArgs = []) {
|
||||
const buildScript = new URL("build-ios.sh", import.meta.url);
|
||||
await execute(buildScript.pathname, ...rawArgs);
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
build_actions=(build)
|
||||
|
||||
usage() {
|
||||
echo "Build an iOS project stored in the 'ios' directory of a package."
|
||||
echo "This must be run from the package directory."
|
||||
echo ""
|
||||
echo "USAGE: build-ios <options>"
|
||||
echo ""
|
||||
echo "OPTIONS:"
|
||||
echo " --clean Optional. Clean up intermediate files before building."
|
||||
echo " -s, --scheme <name> Required. Name of the Xcode scheme to build"
|
||||
echo " -w, --workspace <name> Required. Name of the Xcode workspace file (without extension)."
|
||||
echo " This file must exist under the 'ios' directory."
|
||||
echo " Example: 'MyApp' --> ios/MyApp.xcworkspace"
|
||||
echo ""
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--clean )
|
||||
build_actions=("clean" "${build_actions[@]}")
|
||||
shift
|
||||
;;
|
||||
-s|--scheme )
|
||||
scheme="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-w|--workspace )
|
||||
workspace="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-[?]|-h|--help )
|
||||
usage
|
||||
;;
|
||||
* )
|
||||
echo ""
|
||||
echo "ERROR: unknown option: $1"
|
||||
echo ""
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$workspace" ]]; then
|
||||
echo ""
|
||||
echo "ERROR: missing required option: -w, --workspace"
|
||||
echo ""
|
||||
usage
|
||||
fi
|
||||
|
||||
if [[ -z "$scheme" ]]; then
|
||||
echo ""
|
||||
echo "ERROR: missing required option: -s, --scheme"
|
||||
echo ""
|
||||
usage
|
||||
fi
|
||||
|
||||
if [[ ! -d "ios/${workspace}.xcworkspace" ]]; then
|
||||
package=$(basename $(pwd))
|
||||
echo ""
|
||||
echo "ERROR: Xcode workspace 'ios/${workspace}.xcworkspace' not found in package '${package}'."
|
||||
echo " Maybe you need to run 'pod install --project-directory=ios'?"
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$CCACHE_DISABLE" != "1" ]]; then
|
||||
if ! command -v ccache 1> /dev/null; then
|
||||
brew install ccache
|
||||
fi
|
||||
|
||||
CCACHE_HOME=$(dirname $(dirname $(which ccache)))/opt/ccache
|
||||
|
||||
export CCACHE_DIR="$(git rev-parse --show-toplevel)/.ccache"
|
||||
|
||||
export CC="${CCACHE_HOME}/libexec/clang"
|
||||
export CXX="${CCACHE_HOME}/libexec/clang++"
|
||||
export CMAKE_C_COMPILER_LAUNCHER=$(which ccache)
|
||||
export CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache)
|
||||
|
||||
ccache --zero-stats 1> /dev/null
|
||||
fi
|
||||
if ! command -v xcbeautify 1> /dev/null; then
|
||||
brew install xcbeautify
|
||||
fi
|
||||
|
||||
cd ios
|
||||
export RCT_NO_LAUNCH_PACKAGER=1
|
||||
|
||||
xcodebuild \
|
||||
-workspace "${workspace}.xcworkspace" \
|
||||
-scheme "${scheme}" \
|
||||
-destination "generic/platform=iOS Simulator" \
|
||||
CODE_SIGNING_ALLOWED=NO \
|
||||
COMPILER_INDEX_STORE_ENABLE=NO \
|
||||
"${build_actions[@]}" \
|
||||
| xcbeautify
|
||||
|
||||
if [[ "$CCACHE_DISABLE" != "1" ]]; then
|
||||
ccache --show-stats --verbose
|
||||
fi
|
|
@ -2,8 +2,6 @@
|
|||
// @ts-check
|
||||
|
||||
import yargs from "yargs";
|
||||
import { buildAndroid } from "./commands/build-android.js";
|
||||
import { buildIOS } from "./commands/build-ios.js";
|
||||
import { build } from "./commands/build.js";
|
||||
import { bundle } from "./commands/bundle.js";
|
||||
import { clean } from "./commands/clean.js";
|
||||
|
@ -40,14 +38,6 @@ init({
|
|||
description: "Builds the current package",
|
||||
command: build,
|
||||
},
|
||||
"build-ios": {
|
||||
description: "Builds an iOS app within the current package",
|
||||
command: buildIOS,
|
||||
},
|
||||
"build-android": {
|
||||
description: "Builds an Android app within the current package",
|
||||
command: buildAndroid,
|
||||
},
|
||||
bundle: {
|
||||
description: "Bundles the current package",
|
||||
command: bundle,
|
||||
|
|
Загрузка…
Ссылка в новой задаче