middleman/bin/mm-server

43 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/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 = {}
2011-07-14 03:45:15 +02:00
livereload_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|
2011-07-14 03:29:59 +02:00
options[:port] = port
}
opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
env = e
}
2011-07-14 03:45:15 +02:00
opts.on("--livereload_port PORT", "use PORT (default: 35729)") { |port|
livereload_options[:port] = port
}
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?"
exit
end
# 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")
$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-07-14 03:45:15 +02:00
Middleman::Guard.start(options, livereload_options)