#!/bin/bash
sessionName="leaf"

#tmux has-session -t $sessionName
tmux ls -F "#{session_name}" | grep -Fx $sessionName >/dev/null
hasSession=$?

if [ "$hasSession" = "0" ];then
    tmux attach -t $sessionName
    exit 0
fi
echo "waiting for initial build..."
./util/build

tmux new-session -d -s $sessionName -n "compile" "trap '' 2;. util/env;node_modules/.bin/tsc -p ./ --watch;bash"
tmux split-window -t $sessionName:"compile" "trap '' 2;cd cli;tsc -w -p ./;bash"
tmux split-window -t $sessionName:"compile" "trap '' 2;cd test;http-server;bash"
tmux new-window -a -t $sessionName:"compile" -n "bash" "trap '' 2;. util/env;bash"
tmux attach -t $sessionName
