2009-10-23 02:25:15 +02:00
#!/usr/bin/env ruby
require 'optparse'
# Require Middleman
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
2011-07-14 03:29:59 +02:00
options = {}
2009-10-23 02:25:15 +02:00
2011-05-31 07:33:11 +02:00
# TODO: Switch to Thor
2009-10-23 02:25:15 +02:00
OptionParser.new { |opts|
opts.banner = "Usage: mm-server [rack options]"
opts.separator ""
opts.separator "Rack options:"
opts.on("-p", "--port PORT", "use PORT (default: 4567)") { |port|
2011-07-14 03:29:59 +02:00
options[:port] = port
2009-10-23 02:25:15 +02:00
}
opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
env = e
}
2011-02-21 16:19:18 +01:00
2009-10-23 02:25:15 +02:00
opts.parse! ARGV
}
ENV['RACK_ENV'] = env
2011-07-14 03:29:59 +02:00
if !File.exists?("config.rb")
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
2011-04-11 00:27:18 +02:00
exit
end
2011-05-31 07:33:11 +02:00
# If the old directories exists, use it, but issue warning
2011-07-14 03:29:59 +02:00
if File.exists?("views") || File.exists?("public")
2011-05-31 07:33:11 +02:00
$stderr.puts "== Error: The views and public folders are have been combined. Create a new 'source' folder, add the contents of views and public to it and then remove the empty views and public folders."
exit
end
2011-04-11 00:27:18 +02:00
2011-07-14 03:29:59 +02:00
Middleman::Guard.start(options)