#!/bin/bash

FOLDER=~/Dev/Semantic-UI-React/src
OUTPUT=./src/components

handleFile() {
    el=${1%/}
    echo -e "\tFile ${el}"
    echo -e "import { $el as Default$el } from \"semantic-ui-react\";\n\nexport default Default$el;" > ${OUTPUT}/$2/$el.tsx
    echo -e "export { default as $el } from \"./$el\";" >> ${OUTPUT}/$2/index.ts
}

handleFolder(){
    if [ $1 = "lib/" ]; then
        echo "Skipping $1"
    else
        type=${1%/}
        echo -e "Folder $type"
        rm -r ${OUTPUT}/$type || true
        mkdir -p ${OUTPUT}/$type
        touch ${OUTPUT}/$type/index.ts
        for i in $(ls -F ${FOLDER}/$type | grep /); do handleFile $i $type;done
    fi
}


for i in $(ls -F ${FOLDER} | grep /); do handleFolder $i;done