From d2cbfc432f8ec3479dd454aaa49e630481c87455 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 9 Aug 2011 14:37:55 -0700 Subject: [PATCH] avoid guard on Windows for now --- lib/middleman.rb | 13 +++++++++++++ lib/middleman/cli.rb | 21 ++++++++++++++------- lib/middleman/guard.rb | 16 ++-------------- middleman.gemspec | 12 ++++++++++-- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/lib/middleman.rb b/lib/middleman.rb index c0aad995..e3a6f925 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -160,6 +160,19 @@ module Middleman sandbox.class_eval(&block) if block_given? sandbox end + + def self.start_server(options={}) + opts = { + :Port => options[:port], + :AccessLog => [] + } + + app = ::Middleman.server + app.set :environment, options[:environment].to_sym + opts[:app] = app.new + opts[:server] = 'thin' + ::Rack::Server.new(opts).start + end end require "middleman/version" diff --git a/lib/middleman/cli.rb b/lib/middleman/cli.rb index 82ba8f8e..709208b3 100644 --- a/lib/middleman/cli.rb +++ b/lib/middleman/cli.rb @@ -1,4 +1,5 @@ require 'thor' +require 'rbconfig' module Middleman class CLI < Thor @@ -37,14 +38,20 @@ module Middleman method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on" def server v1_check - if options["livereload"] - livereload_options = {:port => options["livereload-port"]} - end - Middleman::Guard.start({ - :port => options[:port], - :environment => options[:environment] - }, livereload_options) + if Config::CONFIG['host_os'].downcase =~ %r{mswin|mingw} + ::Middleman.start_server(options) + puts "== The Middleman is standing watch on port #{options[:port]}" + else + if options["livereload"] + livereload_options = {:port => options["livereload-port"]} + end + + Middleman::Guard.start({ + :port => options[:port], + :environment => options[:environment] + }, livereload_options) + end end desc "build", "Builds the static site for deployment" diff --git a/lib/middleman/guard.rb b/lib/middleman/guard.rb index 5e2e9216..e159eb02 100644 --- a/lib/middleman/guard.rb +++ b/lib/middleman/guard.rb @@ -38,9 +38,7 @@ module Guard class Middleman < Guard def initialize(watchers = [], options = {}) super - @options = { - :port => '4567' - }.update(options) + @options = options end def start @@ -54,18 +52,8 @@ module Guard private def server_start - @server_options = { - :Port => @options[:port], - :AccessLog => [] - # :AccessLog => ::WEBrick::Log.new('/dev/null'), - # :Logger => ::WEBrick::Log.new('/dev/null') - } @server_job = fork do - app = ::Middleman.server - app.set :environment, @options[:environment].to_sym - @server_options[:app] = app.new - @server_options[:server] = 'thin' - ::Rack::Server.new(@server_options).start + ::Middleman.start_server(@options) end puts "== The Middleman is standing watch on port #{@options[:port]}" diff --git a/middleman.gemspec b/middleman.gemspec index 7b73117f..59c1b4fc 100644 --- a/middleman.gemspec +++ b/middleman.gemspec @@ -1,4 +1,6 @@ # -*- encoding: utf-8 -*- +require "rbconfig" + $:.push File.expand_path("../lib", __FILE__) require "middleman/version" @@ -51,8 +53,14 @@ eos s.add_runtime_dependency("coffee-script", ["~> 2.2.0"]) s.add_runtime_dependency("sprockets", ["2.0.0.beta.13"]) s.add_runtime_dependency("httparty", ["~> 0.7.8"]) - s.add_runtime_dependency("guard", ["~> 0.5.1"]) - s.add_runtime_dependency("guard-livereload", ["~> 0.2.1"]) + + case Config::CONFIG['host_os'].downcase + when %r{mswin|mingw} + else + s.add_runtime_dependency("guard", ["~> 0.5.1"]) + s.add_runtime_dependency("guard-livereload", ["~> 0.3.0"]) + end + s.add_development_dependency("coffee-filter", ["~> 0.1.1"]) s.add_development_dependency("cucumber", ["~> 1.0.2"]) s.add_development_dependency("rake", ["0.8.7"])