get all the tests working with the new binary

This commit is contained in:
Thomas Reynolds 2011-07-26 23:19:43 -07:00
parent 4569d597f5
commit 2634c4156f
9 changed files with 46 additions and 27 deletions

10
bin/mm
View file

@ -1,3 +1,9 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'middleman/cli'
Middleman::CLI.start require "rubygems"
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
require 'middleman'
Middleman::CLI.start

View file

@ -1,15 +1,16 @@
require 'fileutils' require 'fileutils'
require 'middleman/cli'
Given /^a built test app$/ do Given /^a built test app$/ do
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-build")) build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm build"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd}` `cd #{target} && #{build_cmd}`
end end
Given /^a built test app with flags "([^"]*)"$/ do |flags| Given /^a built test app with flags "([^"]*)"$/ do |flags|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-build")) build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm build"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd} #{flags}` `cd #{target} && #{build_cmd} #{flags}`
end end
Given /^cleanup built test app$/ do Given /^cleanup built test app$/ do

View file

@ -2,7 +2,7 @@ require 'fileutils'
Given /^generated directory at "([^\"]*)"$/ do |dirname| Given /^generated directory at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname) target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-init")) init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm init"))
`cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}` `cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}`
end end

View file

@ -1,4 +1,3 @@
root_path = File.dirname(File.dirname(File.dirname(__FILE__))) root_path = File.dirname(File.dirname(File.dirname(__FILE__)))
ENV["MM_DIR"] = File.join(root_path, "fixtures", "test-app")
require File.join(root_path, 'lib', 'middleman') require File.join(root_path, 'lib', 'middleman')
require "rack/test" require "rack/test"

View file

@ -8,10 +8,10 @@
# #
# To accomplish its goals, Middleman supports provides access to: # To accomplish its goals, Middleman supports provides access to:
# #
#### Command-line tools: #### Command-line tool:
# * **mm-init**: A tool for creating to new static sites. # * **mm init**: A tool for creating to new static sites.
# * **mm-server**: A tool for rapidly developing your static site. # * **mm server**: A tool for rapidly developing your static site.
# * **mm-build**: A tool for exporting your site into optimized HTML, CSS & JS. # * **mm build**: A tool for exporting your site into optimized HTML, CSS & JS.
# #
#### Tons of templating languages including: #### Tons of templating languages including:
# * ERB (.erb) # * ERB (.erb)
@ -63,6 +63,8 @@ module Middleman
# Auto-load modules on-demand # Auto-load modules on-demand
autoload :Base, "middleman/base" autoload :Base, "middleman/base"
autoload :Builder, "middleman/builder" autoload :Builder, "middleman/builder"
autoload :CLI, "middleman/cli"
autoload :Templates, "middleman/templates"
autoload :Guard, "middleman/guard" autoload :Guard, "middleman/guard"
# Custom Renderers # Custom Renderers

View file

@ -6,7 +6,7 @@ module Middleman::Base
# Basic Sinatra config # Basic Sinatra config
app.set :app_file, __FILE__ app.set :app_file, __FILE__
app.set :root, ENV["MM_DIR"] || Dir.pwd app.set :root, Dir.pwd
app.set :sessions, false app.set :sessions, false
app.set :logging, false app.set :logging, false
app.set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development app.set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development

View file

@ -3,6 +3,7 @@ require "thor/group"
require 'rack/test' require 'rack/test'
SHARED_SERVER = Middleman.server SHARED_SERVER = Middleman.server
SHARED_SERVER.set :environment, :build
module Middleman module Middleman
module ThorActions module ThorActions

View file

@ -1,6 +1,4 @@
require 'thor' require 'thor'
require 'middleman'
require "middleman/templates"
module Middleman module Middleman
class CLI < Thor class CLI < Thor
@ -11,8 +9,7 @@ module Middleman
class_option "help", :type => :boolean, :default => false, :aliases => "-h" class_option "help", :type => :boolean, :default => false, :aliases => "-h"
def initialize(*) def initialize(*)
super super
config_check help_check if options[:help]
help_check
end end
desc "init NAME", "Create new Middleman project directory NAME" desc "init NAME", "Create new Middleman project directory NAME"
@ -23,31 +20,42 @@ module Middleman
method_option "images_dir", :default => "images", :desc => 'The path to the image files' method_option "images_dir", :default => "images", :desc => 'The path to the image files'
def init(name) def init(name)
key = options[:template].to_sym key = options[:template].to_sym
key = :default unless Middleman::Templates.registered_templates.has_key?(key) unless Middleman::Templates.registered_templates.has_key?(key)
key = :default
Middleman::Templates.registered_templates[key].start end
thor_group = Middleman::Templates.registered_templates[key]
thor_group.new([name], options).invoke_all
end end
desc "server [-p 4567] [-e development]", "Starts the Middleman preview server" desc "server [-p 4567] [-e development]", "Starts the Middleman preview server"
method_option "environment", :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development', :desc => "The environment Middleman will run under" method_option "environment", :aliases => "-e", :default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development', :desc => "The environment Middleman will run under"
method_option "port", :aliases => "-p", :default => "4567", :desc => "The port Middleman will listen on" method_option "port", :aliases => "-p", :default => "4567", :desc => "The port Middleman will listen on"
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not" method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
def server def server
ENV['RACK_ENV'] = options[:environment] config_check
livereload_options = {:port => options["livereload-port"]} if options["livereload"] if options["livereload"]
Middleman::Guard.start({:port => options[:port]}, livereload_options) 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" desc "build", "Builds the static site for deployment"
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls' method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
def build def build
ENV['MM_ENV'] = "build" config_check
Middleman::Builder.start thor_group = Middleman::Builder.new([], options).invoke_all
end end
desc "migrate", "Migrates an older Middleman project to the 2.0 structure" desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
def migrate def migrate
config_check
return if File.exists?("source")
`mv public source` `mv public source`
`cp -R views/* source/` `cp -R views/* source/`
`rm -rf views` `rm -rf views`

View file

@ -61,7 +61,9 @@ module Guard
# :Logger => ::WEBrick::Log.new('/dev/null') # :Logger => ::WEBrick::Log.new('/dev/null')
} }
@server_job = fork do @server_job = fork do
@server_options[:app] = ::Middleman.server.new app = ::Middleman.server
app.set :environment, @options[:environment]
@server_options[:app] = app.new
@server_options[:server] = 'thin' @server_options[:server] = 'thin'
::Rack::Server.new(@server_options).start ::Rack::Server.new(@server_options).start
end end