#!/bin/bash

SERVER_URL=http://kroki:8000

FILE=${1}
extension="${FILE##*.}"
filename="${FILE%.*}"

EXPORT_PATH=./export/

mkdir ${EXPORT_PATH} || true

echo "Converting to PNG: ${filename}"

curl -s ${SERVER_URL}/structurizr/png/`cat ${FILE} | compresssedBase64` > ${EXPORT_PATH}${filename}.png

echo "Converting to SVG: ${filename}"

curl -s ${SERVER_URL}/structurizr/svg/`cat ${FILE} | compresssedBase64` > ${EXPORT_PATH}${filename}.svg

docker run -it --rm -v $PWD:/usr/local/structurizr structurizr/cli export -w ${FILE} -o ${EXPORT_PATH} -f plantuml

for puml in ${EXPORT_PATH}*.puml; do
    echo ${puml}
    plantUml.sh -tsvg ${puml} 
    plantUml.sh -tpng ${puml}
done;

exit