# Only do things if there are files in the tmp directory
if [ `find tmp/* -maxdepth 1 -type d 2>/dev/null | tr -d '\n'` ]; then
  mkdir dist 2>/dev/null
  mkdir dist/cardinal 2>/dev/null

  printf "\n* Concatenating JS to dist...\n"
  # For each directory, contact and copy files to dist
  while IFS=  read -r -d $'\0'; do
    tmp_directory=$REPLY
    directory_name=`echo $tmp_directory | cut -d '/' -f 2`
    dist_directory=dist/cardinal/$directory_name

    mkdir $dist_directory 2>/dev/null
    cat $tmp_directory/main.js $tmp_directory/runtime.js $tmp_directory/vendor.js $tmp_directory/styles.js > $dist_directory/$directory_name.js
  done < <(find tmp/* -maxdepth 1 -type d -print0)
fi
