#!/usr/bin/env ruby

require "rubygems"
require "bundler/setup"

debug = ARGV.any? { |arg| arg == "--debug" }
params = !debug ? " > /dev/null 2>&1" : ""

# FIXME use the webpack build
commands = [
  "bundle exec jbundle server #{params}",
  "rake jasmine"
]

pids = commands.map { |cmd|
  spawn(cmd)
}

begin
  Process.waitall
rescue Interrupt => e
  pids.each { |pid| Process.kill("INT", pid) }
  Process.waitall
end
