2011-12-29 07:52:51 +01:00
|
|
|
# CLI Module
|
2011-12-21 21:13:28 +01:00
|
|
|
module Middleman::Cli
|
2011-12-29 07:52:51 +01:00
|
|
|
|
|
|
|
# Server thor task
|
2011-12-21 21:13:28 +01:00
|
|
|
class Server < Thor
|
2011-12-21 20:03:45 +01:00
|
|
|
check_unknown_options!
|
2011-12-21 21:13:28 +01:00
|
|
|
|
|
|
|
namespace :server
|
|
|
|
|
|
|
|
desc "server [options]", "Start the preview server"
|
2012-01-02 22:48:07 +01:00
|
|
|
method_option :environment,
|
2011-12-21 20:03:45 +01:00
|
|
|
:aliases => "-e",
|
|
|
|
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
|
|
|
:desc => "The environment Middleman will run under"
|
2011-12-21 21:13:28 +01:00
|
|
|
method_option :host,
|
2012-01-02 23:22:24 +01:00
|
|
|
:type => :string,
|
2011-12-21 20:03:45 +01:00
|
|
|
:aliases => "-h",
|
|
|
|
:default => "0.0.0.0",
|
2012-01-02 23:22:24 +01:00
|
|
|
:desc => "Bind to HOST address"
|
2012-01-02 22:48:07 +01:00
|
|
|
method_option :port,
|
2011-12-21 20:03:45 +01:00
|
|
|
:aliases => "-p",
|
|
|
|
:default => "4567",
|
|
|
|
:desc => "The port Middleman will listen on"
|
2012-01-02 22:48:07 +01:00
|
|
|
method_option :verbose,
|
2011-12-21 20:03:45 +01:00
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Print debug messages'
|
2012-07-15 20:04:45 +02:00
|
|
|
method_option :instrument,
|
|
|
|
:type => :string,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Print instrument messages'
|
2012-01-02 22:48:07 +01:00
|
|
|
method_option "disable-watcher",
|
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Disable the file change and delete watcher process'
|
2012-07-19 07:10:02 +02:00
|
|
|
method_option :profile,
|
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
|
|
|
:desc => 'Generate profiling report for server startup'
|
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# Start the server
|
2011-12-21 20:03:45 +01:00
|
|
|
def server
|
2012-05-24 20:03:58 +02:00
|
|
|
require "middleman-core"
|
|
|
|
require "middleman-core/preview_server"
|
|
|
|
|
2011-12-24 20:30:41 +01:00
|
|
|
if !ENV["MM_ROOT"]
|
2012-01-02 22:48:07 +01:00
|
|
|
puts "== Could not find a Middleman project config.rb"
|
2011-12-29 00:29:19 +01:00
|
|
|
puts "== Treating directory as a static site to be served"
|
|
|
|
ENV["MM_ROOT"] = Dir.pwd
|
|
|
|
ENV["MM_SOURCE"] = ""
|
2011-12-24 20:30:41 +01:00
|
|
|
end
|
|
|
|
|
2011-12-21 20:03:45 +01:00
|
|
|
params = {
|
2012-01-02 22:48:07 +01:00
|
|
|
:port => options["port"],
|
|
|
|
:host => options["host"],
|
|
|
|
:environment => options["environment"],
|
|
|
|
:debug => options["verbose"],
|
2012-07-15 20:04:45 +02:00
|
|
|
:instrumenting => options["instrument"],
|
2012-01-02 22:48:07 +01:00
|
|
|
:"disable-watcher" => options["disable-watcher"]
|
2011-12-21 20:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
puts "== The Middleman is loading"
|
2012-05-24 20:03:58 +02:00
|
|
|
::Middleman::PreviewServer.start(params)
|
2011-12-21 20:03:45 +01:00
|
|
|
end
|
|
|
|
end
|
2012-03-19 00:30:25 +01:00
|
|
|
|
|
|
|
def self.exit_on_failure?
|
|
|
|
true
|
|
|
|
end
|
2011-12-21 20:03:45 +01:00
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# Map "s" to "server"
|
2011-12-21 20:03:45 +01:00
|
|
|
Base.map({ "s" => "server" })
|
2012-03-19 00:30:25 +01:00
|
|
|
end
|