Skip to content

Instantly share code, notes, and snippets.

@riston
Created September 26, 2016 07:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riston/f9d8cfc4522cc1e6118d8b1908abbfca to your computer and use it in GitHub Desktop.
Save riston/f9d8cfc4522cc1e6118d8b1908abbfca to your computer and use it in GitHub Desktop.
Heroku NODE_CONFIG change
#!/bin/bash
#
# .config.sh application-name change the NODE_CONFIG value
set -euo pipefail
cd "$(dirname "$0")/.."
APPLICATION="${1:-}"
TMPFILE="$(mktemp /tmp/config.XXXX.json)"
# Check for application name
if [ "${APPLICATION}" == "" ]; then
echo "Make sure to set the heroku application argument!"
exit 1
fi
if hash -v json &>/dev/null -eq 1; then
echo "Make sure the json tool is installed."
exit 1
fi
if hash -v heroku &>/dev/null -eq 1; then
echo "Make sure the Heroku toolbelt is installed."
exit 1
fi
echo "-> Edit app config ${APPLICATION}, create tmp file ${TMPFILE}"
heroku config:get NODE_CONFIG -a "${APPLICATION}" > "${TMPFILE}"
echo "-> Format the JSON input"
json -f "${TMPFILE}" --in-place
echo "-> Trigger editor with current config"
subl3 --wait "${TMPFILE}"
echo "-> Validate config"
cat "${TMPFILE}" | json --validate
CONFIG=$(cat "${TMPFILE}")
echo "-> Set new Heorku config value '${CONFIG}'"
heroku config:set NODE_CONFIG="${CONFIG}" -a "${APPLICATION}"
# Delete file after delete, if you want the file to remain after edit don't
# delete this
# rm "${TMPFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment