diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c428c072..e549c01de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Add support for xCode 16. ([#1370](https://github.com/Instabug/Instabug-React-Native/pull/1370)) +- Added more search capabilities to the find-token.sh script. e.g., searching in .env file for react config. [#1366](https://github.com/Instabug/Instabug-React-Native/pull/1366) + ## [14.3.0](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...14.3.0) ### Added diff --git a/scripts/find-token.sh b/scripts/find-token.sh index 3b162def9..ded75b85f 100644 --- a/scripts/find-token.sh +++ b/scripts/find-token.sh @@ -1,14 +1,27 @@ #!/bin/sh # Searches for app token within source files. +JSON_APP_TOKEN=$( + grep "app_token" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=instabug.json ./ | + sed 's/[[:space:]]//g' | + grep -o ":[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d ":" -f 2 | + cut -d "\"" -f 2 | + cut -d "'" -f 2 +) + +if [ ! -z "${JSON_APP_TOKEN}" ]; then + echo $JSON_APP_TOKEN + exit 0 +fi INIT_APP_TOKEN=$( grep "Instabug.init({" -r -A 6 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.{js,ts,jsx,tsx} ./ | - grep "token:[[:space:]]*[\"\'][0-9a-zA-Z]*[\"\']" | + grep "token[[:space:]]*:[[:space:]]*[\"\'][0-9a-zA-Z]*[\"\']" | grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2 -) +) if [ ! -z "${INIT_APP_TOKEN}" ]; then echo $INIT_APP_TOKEN @@ -20,12 +33,38 @@ START_APP_TOKEN=$( grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2 -) +) if [ ! -z "${START_APP_TOKEN}" ]; then echo $START_APP_TOKEN exit 0 fi +ENV_APP_TOKEN=$( + grep "INSTABUG_APP_TOKEN" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.env ./ | + sed 's/[[:space:]]//g' | + grep -o "INSTABUG_APP_TOKEN=.*" | + cut -d "=" -f 2 +) + +if [ ! -z "${ENV_APP_TOKEN}" ]; then + echo $ENV_APP_TOKEN + exit 0 +fi + +CONSTANTS_APP_TOKEN=$( + grep "INSTABUG_APP_TOKEN" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.{js,ts,jsx,tsx} ./ | + sed 's/[[:space:]]//g' | + grep -o "=[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d "=" -f 2 | + cut -d "\"" -f 2 | + cut -d "'" -f 2 +) + +if [ ! -z "${CONSTANTS_APP_TOKEN}" ]; then + echo $CONSTANTS_APP_TOKEN + exit 0 +fi + echo "Couldn't find Instabug's app token" exit 1