#!/bin/sh
# Autocompiles when saving changes

cleanup() {
    trap - EXIT # Clear EXIT trap
    rm -rf ./tmp # Delete transpiled code
    clear # Clear screen
    kill -- -$$ # Exit
}

trap cleanup EXIT # Execute cleanup on exit

tsc --watch & # Transpiling
sleep 5 # Wait for transpiling to start in watch mode
watchify ./tmp/* -o ./www/main.js > /dev/null # Browserify silently

trap - EXIT # Just to be sure
