|
16 | 16 |
|
17 | 17 | set -euo pipefail
|
18 | 18 |
|
19 |
| -# Uncomment the line below to use a custom Data Connect Emulator binary |
20 |
| -#export DATACONNECT_EMULATOR_BINARY_PATH='...' |
| 19 | +readonly SCRIPT_DIR="$(dirname "$0")" |
| 20 | +readonly SELF_EXECUTABLE="$0" |
| 21 | +readonly LOG_PREFIX="[$0] " |
| 22 | +readonly DEFAULT_POSTGRESQL_STRING='postgresql://postgres:postgres@localhost:5432?sslmode=disable' |
21 | 23 |
|
22 |
| -export FIREBASE_DATACONNECT_POSTGRESQL_STRING='postgresql://postgres:postgres@localhost:5432?sslmode=disable' |
23 |
| -echo "[$0] export FIREBASE_DATACONNECT_POSTGRESQL_STRING='$FIREBASE_DATACONNECT_POSTGRESQL_STRING'" |
| 24 | +function main { |
| 25 | + parse_args "$@" |
| 26 | + log "FIREBASE_DATACONNECT_POSTGRESQL_STRING=${FIREBASE_DATACONNECT_POSTGRESQL_STRING}" |
| 27 | + log "DATACONNECT_EMULATOR_BINARY_PATH=${DATACONNECT_EMULATOR_BINARY_PATH}" |
| 28 | + log "DATA_CONNECT_PREVIEW=${DATA_CONNECT_PREVIEW}" |
| 29 | + run_command firebase --debug emulators:start --only auth,dataconnect |
| 30 | +} |
24 | 31 |
|
25 |
| -readonly FIREBASE_ARGS=( |
26 |
| - firebase |
27 |
| - --debug |
28 |
| - emulators:start |
29 |
| - --only auth,dataconnect |
30 |
| -) |
| 32 | +function parse_args { |
| 33 | + local emulator_binary='' |
| 34 | + local postgresql_string="${DEFAULT_POSTGRESQL_STRING}" |
| 35 | + local preview_flags='' |
| 36 | + local wipe_and_restart_postgres_pod=0 |
31 | 37 |
|
32 |
| -echo "[$0] Running command: ${FIREBASE_ARGS[*]}" |
33 |
| -exec "${FIREBASE_ARGS[@]}" |
| 38 | + local OPTIND=1 |
| 39 | + local OPTERR=0 |
| 40 | + while getopts ":c:p:v:hw" arg ; do |
| 41 | + case "$arg" in |
| 42 | + c) emulator_binary="${OPTARG}" ;; |
| 43 | + p) postgresql_string="${OPTARG}" ;; |
| 44 | + v) preview_flags="${OPTARG}" ;; |
| 45 | + w) wipe_and_restart_postgres_pod=1 ;; |
| 46 | + h) |
| 47 | + print_help |
| 48 | + exit 0 |
| 49 | + ;; |
| 50 | + :) |
| 51 | + echo "ERROR: missing value after option: -${OPTARG}" >&2 |
| 52 | + echo "Run with -h for help" >&2 |
| 53 | + exit 2 |
| 54 | + ;; |
| 55 | + ?) |
| 56 | + echo "ERROR: unrecognized option: -${OPTARG}" >&2 |
| 57 | + echo "Run with -h for help" >&2 |
| 58 | + exit 2 |
| 59 | + ;; |
| 60 | + *) |
| 61 | + echo "INTERNAL ERROR: unknown argument: $arg" >&2 |
| 62 | + exit 1 |
| 63 | + ;; |
| 64 | + esac |
| 65 | + done |
| 66 | + |
| 67 | + export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}" |
| 68 | + export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}" |
| 69 | + export DATA_CONNECT_PREVIEW="${preview_flags}" |
| 70 | + |
| 71 | + if [[ $wipe_and_restart_postgres_pod == "1" ]] ; then |
| 72 | + run_command "${SCRIPT_DIR}/wipe_postgres_db.sh" |
| 73 | + run_command "${SCRIPT_DIR}/start_postgres_pod.sh" |
| 74 | + fi |
| 75 | +} |
| 76 | + |
| 77 | +function run_command { |
| 78 | + log "Running command: $*" |
| 79 | + "$@" |
| 80 | +} |
| 81 | + |
| 82 | +function print_help { |
| 83 | + echo "Firebase Data Connect Emulator Launcher Helper" |
| 84 | + echo |
| 85 | + echo "This script provides a convenient way to launch the Firebase Data Connect" |
| 86 | + echo "and Firebase Authentication emulators in a way that is amenable for running" |
| 87 | + echo "the integration tests." |
| 88 | + echo |
| 89 | + echo "Syntax: ${SELF_EXECUTABLE} [options]" |
| 90 | + echo |
| 91 | + echo "Options:" |
| 92 | + echo " -c <data_connect_emulator_binary_path>" |
| 93 | + echo " Uses the Data Connect Emulator binary at the given path. If not specified, " |
| 94 | + echo " or if specified as the empty string, then the emulator binary is downloaded." |
| 95 | + echo |
| 96 | + echo " -p <postgresql_connection_string>" |
| 97 | + echo " Uses the given string to connect to the PostgreSQL server. If not specified " |
| 98 | + echo " the the default value of \"${DEFAULT_POSTGRESQL_STRING}\" is used." |
| 99 | + echo " If specified as the empty string then an ephemeral PGLite server is used." |
| 100 | + echo |
| 101 | + echo " -v <data_connect_preview_flags>" |
| 102 | + echo " Uses the given Data Connect preview flags when launching the emulator." |
| 103 | + echo " If not specified then an empty string is used, meaning that no preview flags" |
| 104 | + echo " are in effect." |
| 105 | + echo |
| 106 | + echo " -w" |
| 107 | + echo " If specified, then a local PostgreSQL container is wiped and restarted" |
| 108 | + echo " before launching the emulators. This is accomplished by running the scripts" |
| 109 | + echo " ./wipe_postgres_db.sh followed by ./start_postgres_pod.sh." |
| 110 | + echo |
| 111 | + echo " -h" |
| 112 | + echo " Print this help screen and exit, as if successful." |
| 113 | +} |
| 114 | + |
| 115 | +function log { |
| 116 | + echo "${LOG_PREFIX}$*" |
| 117 | +} |
| 118 | + |
| 119 | +main "$@" |
0 commit comments