middleman/bin/mm-server
2011-07-13 18:30:18 -07:00

39 lines
1.1 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require 'optparse'
# Require Middleman
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
options = {}
# TODO: Switch to Thor
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|
options[:port] = port
}
opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
env = e
}
opts.parse! ARGV
}
ENV['RACK_ENV'] = env
if !File.exists?("config.rb")
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
exit
end
# If the old directories exists, use it, but issue warning
if File.exists?("views") || File.exists?("public")
$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
Middleman::Guard.start(options)