Skip to content

Instantly share code, notes, and snippets.

@akaramires
Last active September 26, 2019 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaramires/4808e5c606cb4abe8f64e86285c913b3 to your computer and use it in GitHub Desktop.
Save akaramires/4808e5c606cb4abe8f64e86285c913b3 to your computer and use it in GitHub Desktop.
Zapier CLI - Staging / Dev / Local

Bash script works with:

  • apps
  • validate
  • push
  • versions
  • logs

Bash script supports:

  • local app
  • dev app
  • staging app

Bash script:

  • copies .zapierapprc-$app into .zapierapprc
  • creates env.json with URL. Just include it inside your Zapier App

Demo

Zapier Bash Script

{
"id": 12345,
"key": "App12345"
}
{
"id": 12345,
"key": "App12345"
}
{
"id": 12345,
"key": "App12345"
}
#!/bin/bash
# https://en.wikipedia.org/wiki/ANSI_escape_code
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
printf "\n${GREEN}SELECT COMMAND${NC}\n"
COMMANDS=("apps" "validate" "push" "versions" "logs")
APPS=("local" "dev" "staging")
select command in "${COMMANDS[@]}"
do
if [ -z "$command" ]
then
printf "${RED}Invalid command${NC}\n"
exit 1
else
break
fi
done
printf "\n${GREEN}SELECT APP:${NC}\n"
select app in "${APPS[@]}"
do
if [ -z "$app" ]
then
printf "${RED}Invalid app${NC}\n"
exit 1
else
case $app in
"local")
if [ "$command" = "push" ]; then
PREV_BASE_URL=`node -p "require('./env.json').BASE_URL"`
printf "\n${GREEN}USE PREVIOUS URL${NC} ${YELLOW}$PREV_BASE_URL${NC} ${GREEN}(y/n)?${NC} "
read choice
case "$choice" in
y|Y )
BASE_URL=$PREV_BASE_URL
;;
* )
printf "\n${GREEN}NGROK URL (ex:${NC} ${YELLOW}http://123456.eu.ngrok.io${NC}${GREEN}):${NC} "
read BASE_URL
;;
esac
else
BASE_URL="http://website.dev"
fi
;;
"dev")
BASE_URL="https://dev.website.com"
;;
"staging")
BASE_URL="https://staging.website.com"
;;
esac
break
fi
done
printf "\n****************************************************************\n"
printf "Command\t\t: ${GREEN}\$ zapier $command${NC}\n"
printf "App\t\t: ${GREEN}$app${NC}\n"
printf "URL\t\t: ${GREEN}$BASE_URL${NC}\n"
printf "Config file\t: ${GREEN}.zapierapprc-$app${NC}\n"
printf "Config\t\t: ${GREEN}$(tr -d '\n ' < .zapierapprc-${app})${NC}"
printf "\n****************************************************************\n"
printf "\n${GREEN}IS EVERYTHING CORRECT (y/n)?${NC} "
read choice
case "$choice" in
y|Y )
printf "\n\n"
cp ".zapierapprc-$app" ".zapierapprc"
echo "{\"BASE_URL\":\"$BASE_URL\"}" > env.json
zapier $command
;;
* )
exit 1;
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment