2009-10-23 02:25:15 +02:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2009-11-11 00:53:43 +01:00
|
|
|
# Non-blocking site rebuilding
|
2011-02-21 16:19:18 +01:00
|
|
|
trap("TSTP") do
|
2009-11-11 00:53:43 +01:00
|
|
|
fork do
|
|
|
|
require "open3"
|
|
|
|
first_run = true
|
2009-11-11 23:10:07 +01:00
|
|
|
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
|
2011-05-19 19:36:46 +02:00
|
|
|
end if Signal.list.has_key? "TSTP"
|
2009-11-11 00:53:43 +01:00
|
|
|
|
2009-10-23 02:25:15 +02:00
|
|
|
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") {
|
2010-09-06 04:28:38 +02:00
|
|
|
::Middleman::Server.set :logging, true
|
2009-10-23 02:25:15 +02:00
|
|
|
}
|
2011-02-21 16:19:18 +01:00
|
|
|
|
2009-10-23 02:25:15 +02:00
|
|
|
opts.parse! ARGV
|
|
|
|
}
|
|
|
|
|
|
|
|
ENV['RACK_ENV'] = env
|
|
|
|
|
2011-04-11 00:27:18 +02:00
|
|
|
@current_path = Dir.pwd
|
|
|
|
@path_parts = @current_path.split("/")
|
|
|
|
@found_root = false
|
|
|
|
|
|
|
|
while (!@found_root && (@path_parts.length > 0))
|
|
|
|
@current_path = File.join(*@path_parts)
|
|
|
|
|
|
|
|
public_folder = File.join(@current_path, "public")
|
|
|
|
views_folder = File.join(@current_path, "views")
|
|
|
|
|
|
|
|
if File.exists?(public_folder) && File.exists?(views_folder)
|
|
|
|
@found_root = true
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
@path_parts.pop
|
|
|
|
end
|
|
|
|
|
|
|
|
if !@found_root
|
|
|
|
$stderr.puts "== Error: Could not find a Middleman project structure, perhaps you are in the wrong folder?"
|
|
|
|
exit
|
2009-10-23 02:25:15 +02:00
|
|
|
end
|
|
|
|
|
2011-04-11 00:27:18 +02:00
|
|
|
# If the old init.rb exists, use it, but issue warning
|
|
|
|
old_config = File.join(@current_path, "init.rb")
|
|
|
|
if File.exists? old_config
|
|
|
|
$stderr.puts "== Error: The init.rb file (deprecated) needs to be be renamed to config.rb"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-02-06 19:57:28 +01:00
|
|
|
# require 'shotgun'
|
|
|
|
# config = File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'config.ru')
|
|
|
|
# app = Shotgun.new(config, &lambda { |inner_app| Middleman::Server })
|
2011-04-11 00:27:18 +02:00
|
|
|
Middleman::Server.root = @current_path
|
2011-02-06 19:57:28 +01:00
|
|
|
app = Middleman::Server.new
|
2009-10-23 02:25:15 +02:00
|
|
|
|
2009-11-18 00:33:46 +01:00
|
|
|
require 'rubygems'
|
2009-10-23 02:25:15 +02:00
|
|
|
|
2011-02-21 16:19:18 +01:00
|
|
|
unless defined?(JRUBY_VERSION)
|
|
|
|
require 'thin'
|
|
|
|
handler = Rack::Handler::Thin
|
|
|
|
else
|
|
|
|
require 'kirk'
|
|
|
|
require 'rack/handler/kirk'
|
|
|
|
handler = Rack::Handler::Kirk
|
|
|
|
end
|
|
|
|
|
|
|
|
handler.run app, options do |inst|
|
2009-10-23 02:25:15 +02:00
|
|
|
puts "== The Middleman is standing watch on port #{options[:Port]}"
|
2011-02-21 16:19:18 +01:00
|
|
|
end
|