diff --git a/.env b/.env deleted file mode 100644 index 4783255f..00000000 --- a/.env +++ /dev/null @@ -1,3 +0,0 @@ -ENVIRONMENT=production -ANDROID_FIREBASE_CONFIG=ewogICJwcm9qZWN0X2luZm8iOiB7CiAgICAicHJvamVjdF9udW1iZXIiOiAiMzYzNTM0MTMzMDk1IiwKICAgICJwcm9qZWN0X2lkIjogInNjaG9vbHBpbG90LWRldmVsb3BtZW50IiwKICAgICJzdG9yYWdlX2J1Y2tldCI6ICJzY2hvb2xwaWxvdC1kZXZlbG9wbWVudC5hcHBzcG90LmNvbSIKICB9LAogICJjbGllbnQiOiBbCiAgICB7CiAgICAgICJjbGllbnRfaW5mbyI6IHsKICAgICAgICAibW9iaWxlc2RrX2FwcF9pZCI6ICIxOjM2MzUzNDEzMzA5NTphbmRyb2lkOjUzYTYwODI2NjZkMzc4MmM5MzMxYzIiLAogICAgICAgICJhbmRyb2lkX2NsaWVudF9pbmZvIjogewogICAgICAgICAgInBhY2thZ2VfbmFtZSI6ICJvbmxpbmUuYmluYXJhcHBzIgogICAgICAgIH0KICAgICAgfSwKICAgICAgIm9hdXRoX2NsaWVudCI6IFsKICAgICAgICB7CiAgICAgICAgICAiY2xpZW50X2lkIjogIjM2MzUzNDEzMzA5NS0zZGdvMmRnNnI0bzNmdDkyMHA0dTRtaGIwdG1vM25sbS5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsCiAgICAgICAgICAiY2xpZW50X3R5cGUiOiAzCiAgICAgICAgfQogICAgICBdLAogICAgICAiYXBpX2tleSI6IFsKICAgICAgICB7CiAgICAgICAgICAiY3VycmVudF9rZXkiOiAiQUl6YVN5QUFjM2VvUTF4Z1RxSHNfZmdTSHZzSGlYeG5QdndoNVg4IgogICAgICAgIH0KICAgICAgXSwKICAgICAgInNlcnZpY2VzIjogewogICAgICAgICJhcHBpbnZpdGVfc2VydmljZSI6IHsKICAgICAgICAgICJvdGhlcl9wbGF0Zm9ybV9vYXV0aF9jbGllbnQiOiBbCi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end of file diff --git a/.env.production b/.env.production deleted file mode 100644 index 5c603b70..00000000 --- a/.env.production +++ /dev/null @@ -1 +0,0 @@ -ENVIRONMENT=production \ No newline at end of file diff --git a/.env.qa b/.env.qa deleted file mode 100644 index e57e1e3d..00000000 --- a/.env.qa +++ /dev/null @@ -1 +0,0 @@ -ENVIRONMENT=qa \ No newline at end of file diff --git a/.env.staging b/.env.staging deleted file mode 100644 index 6673ee28..00000000 --- a/.env.staging +++ /dev/null @@ -1 +0,0 @@ -ENVIRONMENT=staging \ No newline at end of file diff --git a/.gitignore b/.gitignore index dba154c6..c49f35d8 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,8 @@ dist/ /ios google-services.json -GoogleService-Info.plist \ No newline at end of file +GoogleService-Info.plist + +scripts/doppler_variables.sh +.env +env.json \ No newline at end of file diff --git a/README.md b/README.md index e0d92039..94fadbe3 100644 --- a/README.md +++ b/README.md @@ -172,11 +172,23 @@ Start the expo server yarn start ``` -## Adding jotai as state management tool +Environment variables instruction: -This starter doesn't go with any state management tool, but we have created separate branch with jotai setup, maybe in the future we will add more tools support. +1. Create empty file `scripts/doppler_variables.sh` and add this script to new created file. -To use jotai with this starter you can check docs: **[Jotai docs](./documentation/docs/tutorials/JOTAI.md)** +- run `yarn prepare:env_file` - this will copy template and plase it in `scripts/doppler_variables.sh` + +2. Add correct values to variables (ask one of the developers for that), example: + +```bash +export DOPPLER_TOKEN_DEVELOPMENT=dp.st.alpha.XXXXxxxxXXXXxxxxXXXXxxxx +``` + +Start the expo server + +```bash + yarn start +``` ## License diff --git a/package.json b/package.json index de2acbde..e636b4da 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,7 @@ "author": "BinarApps", "license": "MIT", "scripts": { - "eas-build-pre-install": "base64 --help && echo $ANDROID_FIREBASE_CONFIG | base64 --decode > google-services.json && cat google-services.json && echo $IOS_FIREBASE_CONFIG | base64 --decode > GoogleService-Info.plist && cat GoogleService-Info.plist", "android:dev-client": "IS_DEV=1 npx expo run:android", - "android": "expo run:android", "bootstrap:new_app": "yarn && node ./scripts/bootstrap.js", "build:production:android": "yarn prepare:production && eas build --platform android --profile production", "build:production:ios": "yarn prepare:production && eas build --platform ios --profile production", @@ -45,30 +43,29 @@ "deploy:staging:android": "yarn prepare:staging && eas build --platform android --profile staging --auto-submit --non-interactive", "deploy:staging:ios": "yarn prepare:staging && eas build --platform ios --profile staging --auto-submit --non-interactive", "deploy:staging": "yarn prepare:staging && eas build --platform all --profile staging --auto-submit --non-interactive", - "eject": "expo eject", - "generate:query": "yarn orval --config ./orval.config.ts", + "eas-build-pre-install": "base64 --help && echo $ANDROID_FIREBASE_CONFIG | base64 --decode > google-services.json && cat google-services.json && echo $IOS_FIREBASE_CONFIG | base64 --decode > GoogleService-Info.plist && cat GoogleService-Info.plist", "generate:component": "node ./scripts/create_new_component.js && yarn eslint src --fix && yarn tsc", "generate:env:production": "scripts/generate_dotenv.sh production", "generate:env:qa": "scripts/generate_dotenv.sh qa", "generate:env:staging": "scripts/generate_dotenv.sh staging", - "generate:icon:types": "node ./scripts/generate_icon_types.js", "generate:google-services-config": "./scripts/generate_firebase_config.sh", + "generate:icon:types": "node ./scripts/generate_icon_types.js", + "generate:query": "yarn orval --config ./orval.config.ts", "generate:screen": "node ./scripts/create_new_screen.js && yarn eslint src --fix && yarn tsc", - "ios": "expo run:ios", - "lint": "eslint src && yarn tsc", "lint:fix": "eslint src --fix", - "login": "expo login", - "logout": "expo logout", + "lint": "eslint src && yarn tsc", "postinstall": "patch-package", "prebuild:android": "IS_DEV=1 npx expo prebuild --clean -p android", - "prepare:production": "yarn generate:env:production && BASH_ENV=./.env scripts/upload_env.sh", - "prepare:qa": "yarn generate:env:qa && BASH_ENV=./.env scripts/upload_env.sh", - "prepare:staging": "yarn generate:env:staging && BASH_ENV=./.env scripts/upload_env.sh", + "prebuild:ios": "IS_DEV=1 npx expo prebuild --clean -p ios", + "prepare:env_file": "cp ./templates/doppler_variables_template.sh ./scripts/doppler_variables.sh", + "prepare:production": "yarn && yarn generate:env:production && yarn generate:google-services-config", + "prepare:qa": "yarn && yarn generate:env:qa && yarn generate:google-services-config", + "prepare:staging": "yarn && yarn generate:env:staging && yarn generate:google-services-config", "prepare": "husky install", "prettier:write": "prettier --write ./src", - "register": "expo register", - "start:fast": "EXPO_USE_EXOTIC=1 expo start --clear", - "start": "cross-env IS_DEV=1 expo start -c -g", + "start:prod": "yarn generate:env:production && IS_DEV=1 IS_EXPO_GO=1 expo start -c -g", + "start:staging": "yarn generate:env:staging && IS_DEV=1 IS_EXPO_GO=1 expo start -c -g", + "start": "yarn generate:env:qa && cross-env IS_DEV=1 IS_EXPO_GO=1 expo start -c -g", "test:debug": "jest -o --watch --coverage=false", "test:final": "jest", "test": "jest --watch --coverage=false --changedSince=origin/main", diff --git a/scripts/generate_dotenv.sh b/scripts/generate_dotenv.sh index cb9293e2..e365ec4f 100755 --- a/scripts/generate_dotenv.sh +++ b/scripts/generate_dotenv.sh @@ -1,5 +1,58 @@ #!/usr/bin/env bash -ENVIRONMENT=$1 -echo $ENVIRONMENT +source ./scripts/doppler_variables.sh -cp .env.$ENVIRONMENT .env +# Global colors +normal=$'\e[0m' # (works better sometimes) +bold=$(tput bold) # make colors bold/bright +red="$bold$(tput setaf 1)" # bright red text +green=$(tput setaf 2) # dim green text +fawn=$(tput setaf 3); beige="$fawn" # dark yellow text +darkblue=$(tput setaf 4) # dim blue text +blue="$bold$darkblue" # bright blue text +purple=$(tput setaf 5); magenta="$purple" # magenta text +pink="$bold$purple" # bright magenta text +darkcyan=$(tput setaf 6) # dim cyan text +gray=$(tput setaf 7) # dim white text +darkgray="$bold"$(tput setaf 0) # bold black = dark gray text + + +# Global variables +ENVIRONMENT_NAME=$1 +function install_doppler { + (curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sh || echo "${pink}There was some problem with installing doppler, and it's needed to get environment varialbes, please download it manually - https://docs.doppler.com/docs/cli" + # When using this on windows try this commands + # scoop bucket add doppler https://github.com/DopplerHQ/scoop-doppler.git + # scoop install doppler +} + +if command -v doppler >/dev/null 2>&1 ; +then echo "${green}[START WORK] Setting Doppler token for Baca App | ${red}$ENVIRONMENT_NAME ${normal}" + echo Now setting token and printing env for env: $ENVIRONMENT_NAME + if [ $ENVIRONMENT_NAME = "qa" ]; then + doppler setup --config=qa --token=$DOPPLER_TOKEN_DEVELOPMENT --no-interactive + doppler secrets download --config=qa --token=$DOPPLER_TOKEN_DEVELOPMENT --no-file --format=env-no-quotes > .env + doppler secrets download --config=qa --token=$DOPPLER_TOKEN_DEVELOPMENT --no-file > env.json + fi + if [ $ENVIRONMENT_NAME = "staging" ]; then + doppler setup --config=stg --token=$DOPPLER_TOKEN_STAGING --no-interactive + doppler secrets download --config=stg --token=$DOPPLER_TOKEN_STAGING --no-file --format=env-no-quotes > .env + doppler secrets download --config=stg --token=$DOPPLER_TOKEN_STAGING --no-file > env.json + fi + if [ $ENVIRONMENT_NAME = "production" ]; then + doppler setup --config=prd --token=$DOPPLER_TOKEN_PROD --no-interactive + doppler secrets download --config=prd --token=$DOPPLER_TOKEN_PROD --no-file --format=env-no-quotes > .env + doppler secrets download --config=prd --token=$DOPPLER_TOKEN_PROD --no-file > env.json + fi + echo Created envs for env: $ENVIRONMENT_NAME +else + read -p "${green}We require Doppler CLI, but it's not installed. Do you wish to install it? (y/n)${normal} " answer + case ${answer:0:1} in + y|Y ) + install_doppler + ./scripts/generate_dotenv.sh $ENVIRONMENT_NAME + ;; + * ) + echo "We need doppler to set environement variables, you can download it manually - https://docs.doppler.com/docs/cli" + ;; + esac +fi \ No newline at end of file diff --git a/src/constants/env.ts b/src/constants/env.ts index 54865bdb..d8fb3610 100644 --- a/src/constants/env.ts +++ b/src/constants/env.ts @@ -1,6 +1,6 @@ import Constants from 'expo-constants' export const ENV = { - API_URL: 'https://api.binarapps.online/', // TODO: create env for dev/staging/prod and keep it there + API_URL: Constants?.expoConfig?.extra?.API_URL, ENVIRONMENT: Constants?.expoConfig?.extra?.ENVIRONMENT, } diff --git a/templates/doppler_variables_template.sh b/templates/doppler_variables_template.sh new file mode 100644 index 00000000..3571769d --- /dev/null +++ b/templates/doppler_variables_template.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# --- Define doppler variables --- +export DOPPLER_TOKEN_DEVELOPMENT= +export DOPPLER_TOKEN_STAGING= +export DOPPLER_TOKEN_PROD= +# --- End Definitions Section --- + +# check if we are being sourced by another script or shell +[[ "${#BASH_SOURCE[@]}" -gt "1" ]] && { return 0; } + +# --- Begin Code Execution Section --- +echo $DOPPLER_TOKEN_DEVELOPMENT +echo $DOPPLER_TOKEN_STAGING +echo $DOPPLER_TOKEN_PROD