Skip to content

Instantly share code, notes, and snippets.

@gretzky
Created March 22, 2021 17:06
Show Gist options
  • Save gretzky/5eca7ca86bec10e2505215d506dce666 to your computer and use it in GitHub Desktop.
Save gretzky/5eca7ca86bec10e2505215d506dce666 to your computer and use it in GitHub Desktop.
This script will setup your environment for developing React Native applications
#!/bin/bash
## NOTE: be sure to replace the following instances in this script before running
# - replace APP_NAME with the name of your application (as a single word, PascalCase. ex. "MyApp")
# - replace 'zshrc' with your preferred shell config. if you don't know what this is (or you prefer zsh) you can leave this as is
# install xcode command line tools if not already installed
if ! xcode-select --print-path &> /dev/null; then
xcode-select --install &> /dev/null
until xcode-select -switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license
fi
# install homebrew if not already installed
if ! command -v "brew" &> /dev/null; then
printf "Homebrew not found, installing."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
sudo chown -R $(whoami) /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/Homebrew
fi
# install prerequisites for iOS
brew install gawk gpg watchman applesimutils 2>/dev/null
# install openjdk - required for react native
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8 2>/dev/null
# install android studio if not yet installed
if ! open -Ra "Android Studio"; then
brew install --cask android-studio 2>/dev/null
fi
# install node via asdf if not already installed
if ! command -v node; then
asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git
fi
# set node to latest stable release. you should always use node latest stable release when starting any new JS/TS project, this ensures some longevity
asdf install nodejs latest
# install yarn if not already installed
if ! command -v yarn; then
brew install yarn
fi
# install detox for e2e testing
yarn global add detox-cli 2>/dev/null
# install cocoapods for ios and fastlane for deployment
sudo gem install cocoapods fastlane 2>/dev/null
# add the gitignore command line tool
echo "function gi() { curl -sLw "\n" https://www.toptal.com/developers/gitignore/api/\$@ ;}" >> \
~/.zshrc && source ~/.zshrc
# add exports for android studio to your profile - be sure to put the correct bash config if not using zshrc
echo 'export ANDROID_HOME=$HOME/Library/Android/sdk' >> .zshrc
echo 'export PATH=$PATH=$ANDROID_HOME/emulator' >> .zshrc
echo 'export PATH=$PATH=$ANDROID_HOME/tools' >> .zshrc
echo 'export PATH=$PATH=$ANDROID_HOME/tools/bin' >> .zshrc
echo 'export PATH=$PATH=$ANDROID_HOME/platform-tools' >> .zshrc
# create iOS simulator with latest iOS version and device
xcrun simctl create "APP_NAME" "iPhone 12" iOS14.4 2>/dev/null
# create android emulator on latest API version
cd ~/Library/Android/sdk
./bin/avdmanager create avd -n APP_NAME -k "system-images;android-30;google_apis;x86_64"
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment