Skip to content

Instantly share code, notes, and snippets.

@cunneen
Last active October 19, 2021 13:49
Show Gist options
  • Save cunneen/6dc836565f9d831db134ca90bd6d1e22 to your computer and use it in GitHub Desktop.
Save cunneen/6dc836565f9d831db134ca90bd6d1e22 to your computer and use it in GitHub Desktop.
Create a new react native app, specifying app name and package name
#!/usr/bin/env bash
# get the full path for the current dir
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
###### prompt for values
# get the new app name
read -p "Enter your new app name [Foo App]: " NEW_APP_NAME
NEW_APP_NAME=${NEW_APP_NAME:-"Foo App"}
echo ...using ${NEW_APP_NAME} as new app name
# get the new folder name
NEW_FOLDER_NAME=$(echo -n "$NEW_APP_NAME" | sed 's/^ *//' | sed 's/ *$//' | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]') # Trim special chars, leading and trailing whitespace.
echo ...using ${NEW_FOLDER_NAME} as new folder name
# get the new package name
read -p "Enter your new package name [org.newpackage.app]: " NEW_PACKAGE_NAME
NEW_PACKAGE_NAME=${NEW_PACKAGE_NAME:-"org.newpackage.app"}
echo ...using ${NEW_PACKAGE_NAME} as new package name
OLD_PACKAGE_NAME=org.reactjs.native.example
######### test for prerequisites
command -v npx >/dev/null 2>&1 || {
echo -e "I require npx but it's not installed.\n\nAborting.\n" >&2;
exit 1;
}
command -v pod >/dev/null 2>&1 || {
echo -e "I require cocoapods but it's not installed.\n\nAborting.\n" >&2;
exit 1;
}
######### run commands
npx react-native init "${NEW_FOLDER_NAME}" && \
cd "${NEW_FOLDER_NAME}" && \
npx react-native-rename "${NEW_APP_NAME}" -b ${NEW_PACKAGE_NAME} && \
rm -rf ios/Pods && \
pod install --project-directory=./iOS && \
grep -rl ${OLD_PACKAGE_NAME} * | \
xargs sed -i '.bak' "s/${OLD_PACKAGE_NAME}/${NEW_PACKAGE_NAME}/g"
#########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment