46 lines
1.4 KiB
Ruby
Executable file
46 lines
1.4 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
|
|
require "rubygems"
|
|
require "thor"
|
|
require "thor/group"
|
|
|
|
# Require Middleman
|
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
|
|
|
|
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 => true, :type => :boolean
|
|
|
|
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
|
|
|
|
Middleman::GuardServer.start |