middleman/bin/mm-server

60 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
2009-11-11 00:53:43 +01:00
# Non-blocking site rebuilding
trap("TSTP") do
fork do
require "open3"
first_run = true
Open3.popen3(%Q{cd "#{Dir.pwd}" && #{File.join(File.dirname(__FILE__), "mm-build")} | grep FORCED}) do |stdin, stdout, stderr|
2009-11-11 00:53:43 +01:00
puts "\n== Building the site..."
stdout.readlines.each do |l|
puts "== Updated:" if first_run
puts " " + l.split("[FORCED]").last.chomp
first_run = false
end
puts "== Build complete"
end
end
end
require 'optparse'
# Require Middleman
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
env = ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development'
options = { :Port => 4567, :AccessLog => [] }
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("--debug", "Debug mode") {
::Middleman::Base.set :logging, true
}
opts.parse! ARGV
}
ENV['RACK_ENV'] = env
class Middleman::Base
set :root, Dir.pwd
end
require 'shotgun'
config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
app = Shotgun.new(config, lambda { |inner_app| Middleman::Base })
require 'thin'
Thin::Logging.silent = true
Rack::Handler::Thin.run app, options do |inst|
puts "== The Middleman is standing watch on port #{options[:Port]}"
end