#!/bin/bash

if [ -z "$1" ]; then
    set -- "BACKEND_HOST"
fi

HOST=$(grep "$1" .env 2>/dev/null | cut -d '=' -f 2 | tr -d '"')
echo $1
echo $HOST
cmd="npx openapi-typescript $HOST/api/schema/ -o src/data/types.tmp.ts"
if eval $cmd
then
    echo $cmd
    mv src/data/types.tmp.ts src/data/types.ts
fi
chmod go+rw src/data/types.ts
