#!/bin/bash
MY_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
MY_DIR="$(dirname $MY_PATH)"
cd $MY_DIR/..

SRC_FILE=$1
DEST_FILE=$2
echo "|    File copy ${SRC_FILE} to ${DEST_FILE}..."

DEST_DIR=$(dirname "${DEST_FILE}")

mkdir -p ${DEST_DIR}


function writeComment {
    STR=$(echo "$1" | awk '{printf("%-100s\n", $0)}')
    echo "/*** $STR ***/" >> ${DEST_FILE}
}

> ${DEST_FILE}

if [[ ${SRC_FILE} == *.js ]]; then
    # echo "    Javascript Source"
    writeComment "UNDER NO CIRCUMSTANCES DO NOT EDIT THIS FILE. THIS FILE IS COPIED" 
    writeComment "FROM OSS UI. ANY CHANGES TO BE MADE IN KUBEVIOUS OSS UI." 
    writeComment "SOURCE: ${SRC_FILE}" 
    echo "" >> ${DEST_FILE}
elif [[ ${SRC_FILE} == *css ]]; then
    # echo "    CSS Source"
    writeComment "UNDER NO CIRCUMSTANCES DO NOT EDIT THIS FILE. THIS FILE IS COPIED" 
    writeComment "FROM OSS UI. ANY CHANGES TO BE MADE IN KUBEVIOUS OSS UI." 
    writeComment "SOURCE: ${SRC_FILE}" 
    echo "" >> ${DEST_FILE}
elif [[ ${SRC_FILE} == *.ts ]]; then
    # echo "    TS Source"
    writeComment "UNDER NO CIRCUMSTANCES DO NOT EDIT THIS FILE. THIS FILE IS COPIED" 
    writeComment "FROM OSS UI. ANY CHANGES TO BE MADE IN KUBEVIOUS OSS UI." 
    writeComment "SOURCE: ${SRC_FILE}" 
    echo "" >> ${DEST_FILE}
elif [[ ${SRC_FILE} == *tsx ]]; then
    # echo "    TSX Source"
    writeComment "UNDER NO CIRCUMSTANCES DO NOT EDIT THIS FILE. THIS FILE IS COPIED" 
    writeComment "FROM OSS UI. ANY CHANGES TO BE MADE IN KUBEVIOUS OSS UI." 
    writeComment "SOURCE: ${SRC_FILE}" 
    echo "" >> ${DEST_FILE}
fi

cat ${SRC_FILE} >> ${DEST_FILE}

