middleman/bin/mm-server

46 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
2011-07-15 06:08:30 +02:00
require "rubygems"
2011-07-14 03:58:22 +02:00
require "thor"
require "thor/group"
# Require Middleman
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
2011-07-14 03:58:22 +02:00
module Middleman
class GuardServer < ::Thor::Group
include Thor::Actions
class_option :environment, :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
class_option :port, :aliases => "-p", :default => "4567"
class_option :"livereload-port", :default => "35729"
class_option :"livereload", :default => false, :type => :boolean
2011-07-14 03:58:22 +02:00
def start_guard
if !File.exists?("config.rb")
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
return
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."
return
end
ENV['RACK_ENV'] = options[:environment]
livereload_options = {
:port => options[:"livereload-port"]
}
livereload_options = nil unless options[:"livereload"]
::Middleman::Guard.start({
:port => options[:port],
}, livereload_options)
end
end
end
2011-07-14 03:58:22 +02:00
Middleman::GuardServer.start