mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Use Thor for mm-server
This commit is contained in:
parent
e81ba33b0d
commit
81a7557459
2 changed files with 51 additions and 45 deletions
|
@ -1,43 +1,45 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'optparse'
|
require "thor"
|
||||||
|
require "thor/group"
|
||||||
|
|
||||||
# Require Middleman
|
# Require Middleman
|
||||||
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
|
||||||
|
|
||||||
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
|
module Middleman
|
||||||
options = {}
|
class GuardServer < ::Thor::Group
|
||||||
livereload_options = {}
|
include Thor::Actions
|
||||||
|
|
||||||
# TODO: Switch to Thor
|
class_option :environment, :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
|
||||||
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.on("--livereload_port PORT", "use PORT (default: 35729)") { |port|
|
|
||||||
livereload_options[:port] = port
|
|
||||||
}
|
|
||||||
|
|
||||||
opts.parse! ARGV
|
class_option :port, :aliases => "-p", :default => "4567"
|
||||||
}
|
class_option :"livereload-port", :default => "35729"
|
||||||
|
class_option :"livereload", :default => true, :type => :boolean
|
||||||
|
|
||||||
ENV['RACK_ENV'] = env
|
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 !File.exists?("config.rb")
|
# If the old directories exists, use it, but issue warning
|
||||||
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
if File.exists?("views") || File.exists?("public")
|
||||||
exit
|
$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
|
end
|
||||||
|
|
||||||
# If the old directories exists, use it, but issue warning
|
Middleman::GuardServer.start
|
||||||
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, livereload_options)
|
|
|
@ -9,22 +9,26 @@ module Middleman::Guard
|
||||||
options_hash << ", :#{k} => '#{v}'"
|
options_hash << ", :#{k} => '#{v}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
livereload_options_hash = ""
|
guardfile_contents = %Q{
|
||||||
livereload.each do |k,v|
|
guard 'middleman'#{options_hash} do
|
||||||
livereload_options_hash << ", :#{k} => '#{v}'"
|
watch("config.rb")
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
::Guard.start({
|
if livereload
|
||||||
:guardfile_contents => %Q{
|
livereload_options_hash = ""
|
||||||
guard 'middleman'#{options_hash} do
|
livereload.each do |k,v|
|
||||||
watch("config.rb")
|
livereload_options_hash << ", :#{k} => '#{v}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guardfile_contents << %Q{
|
||||||
guard 'livereload'#{livereload_options_hash} do
|
guard 'livereload'#{livereload_options_hash} do
|
||||||
watch(%r{^source/(.*)$})
|
watch(%r{^source/(.*)$})
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
})
|
end
|
||||||
|
|
||||||
|
::Guard.start({ :guardfile_contents => guardfile_contents })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue