Skip to content

Commit

Permalink
Fallback to npx react-native if binary_path not provided (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
hisaac authored Dec 9, 2022
1 parent c45edae commit 7d2c645
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
20 changes: 9 additions & 11 deletions bitrise.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
format_version: 1.3.1
format_version: "11"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

app:
envs:
- STEP_VERSION: 1.0.4

- SAMPLE_APP_PATH: $SAMPLE_APP_PATH
- SAMPLE_APP_URL: https://github.com/bitrise-samples/react-native-sample.git

Expand All @@ -15,7 +14,7 @@ workflows:
steps:
- change-workdir:
title: Switch working dir
run_if: true
run_if: "true"
inputs:
- path: $SAMPLE_APP_PATH
- path::./:
Expand All @@ -34,7 +33,7 @@ workflows:
rm -rf ./_tmp
- change-workdir:
title: Switch working dir to test / _tmp dir
run_if: true
run_if: "true"
inputs:
- path: ./_tmp
- is_create_path: true
Expand All @@ -46,9 +45,9 @@ workflows:
set -v
git clone $SAMPLE_APP_URL .
- install-react-native@0.1.0:
- install-react-native:
run_if: .IsCI
- npm@0.1.1:
- npm:
inputs:
- command: install
- path::./:
Expand All @@ -63,7 +62,6 @@ workflows:
- RELEASE_VERSION: $STEP_VERSION
steps:
- script:
title:
inputs:
- content: |
#!/bin/bash
Expand All @@ -86,10 +84,10 @@ workflows:
share-this-step:
envs:
# if you want to share this step into a StepLib
- MY_STEPLIB_REPO_FORK_GIT_URL: $MY_STEPLIB_REPO_FORK_GIT_URL
- STEP_ID_IN_STEPLIB: react-native-bundle
- STEP_GIT_VERION_TAG_TO_SHARE: $STEP_VERSION
- STEP_GIT_CLONE_URL: https://github.com/bitrise-steplib/steps-react-native-bundle.git
- MY_STEPLIB_REPO_FORK_GIT_URL: $MY_STEPLIB_REPO_FORK_GIT_URL
- STEP_ID_IN_STEPLIB: react-native-bundle
- STEP_GIT_VERION_TAG_TO_SHARE: $STEP_VERSION
- STEP_GIT_CLONE_URL: https://github.com/bitrise-steplib/steps-react-native-bundle.git
description: |-
If this is the first time you try to share a Step you should
first call: $ bitrise share
Expand Down
32 changes: 24 additions & 8 deletions step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,31 @@ echo_info "Deprecated Configs:"
echo_details "* root: $root"
echo_details "* url: $url"

echo_info "react-native version:"

REACT_NATIVE_BIN="react-native"
if [ ! -z "${binary_path}" ] ; then
REACT_NATIVE_BIN="${binary_path}/react-native"
echo_info "\`react-native\` info:"

# Find path to the react-native CLI
declare REACT_NATIVE_BIN
if [[ -n "${binary_path}" ]]; then
# If binary_path is specified, use that
REACT_NATIVE_BIN="${binary_path}/react-native"
echo_details "* Using binary specified in binary_path"
elif output=$(npx --yes which react-native 2>/dev/null); then
# If npx version is available, use that
REACT_NATIVE_BIN=${output}
echo_details "* Using binary via \`npx\`"
else
# Otherwise, use the react-native CLI in the current PATH
REACT_NATIVE_BIN="react-native"
echo_details "* Using react-native CLI in PATH"
fi

if ! $REACT_NATIVE_BIN --version 2>/dev/null ; then
$REACT_NATIVE_BIN -v
echo_details "* Location: ${REACT_NATIVE_BIN}"

if output=$("${REACT_NATIVE_BIN}" --version 2>/dev/null); then
echo_details "* Version: ${output}"
elif output=$("${REACT_NATIVE_BIN}" -v 2>/dev/null); then
echo_details "* Version: ${output}"
else
echo_warn "* Failed to get \`react-native\` version"
fi

echo
Expand Down

0 comments on commit 7d2c645

Please sign in to comment.