#!/bin/bash
# I imagine we could easily run this script
# via Github Actions once it is enabled to update
# docs after every merge to master.

API_SPEC_PATH="jobs_collector/api/api.yml"
TEMP_API_HTML="api.html"
API_HOST="s3://zoox-web/data-team/c2d/jobs-collector/api.html"
API_URL="http://data-team.web.zooxlabs.com/c2d/jobs-collector/api.html"

# Node is installed with driving setup script.
# So running npx should work fine I think.
echo -e "\nGenerating docs ..."
npx redoc-cli bundle \
    -o $TEMP_API_HTML \
    $API_SPEC_PATH \
    --options.hideDownloadButton

# Hopefuly the right AWS creds are set
# by whoever is running this script :P
echo -e "\nUploading docs ..."
aws s3 cp $TEMP_API_HTML $API_HOST

# Remove the spec in html format.
rm $TEMP_API_HTML

echo -e "\nUpload successful!"
echo $API_URL
