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
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 'middleman/cli'
Given /^a built test app$/ do
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"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd}`
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm build"))
`cd #{target} && #{build_cmd}`
end
Given /^a built test app with flags "([^"]*)"$/ do |flags|
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"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd} #{flags}`
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm build"))
`cd #{target} && #{build_cmd} #{flags}`
end
Given /^cleanup built test app$/ do

View file

@ -2,7 +2,7 @@ require 'fileutils'
Given /^generated directory at "([^\"]*)"$/ do |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)}`
end

View file

@ -1,4 +1,3 @@
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 "rack/test"

View file

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

View file

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

View file

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

View file

@ -1,6 +1,4 @@
require 'thor'
require 'middleman'
require "middleman/templates"
module Middleman
class CLI < Thor
@ -11,8 +9,7 @@ module Middleman
class_option "help", :type => :boolean, :default => false, :aliases => "-h"
def initialize(*)
super
config_check
help_check
help_check if options[:help]
end
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'
def init(name)
key = options[:template].to_sym
key = :default unless Middleman::Templates.registered_templates.has_key?(key)
Middleman::Templates.registered_templates[key].start
unless Middleman::Templates.registered_templates.has_key?(key)
key = :default
end
thor_group = Middleman::Templates.registered_templates[key]
thor_group.new([name], options).invoke_all
end
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 "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-port", :default => "35729", :desc => "The port Livereload will listen on"
def server
ENV['RACK_ENV'] = options[:environment]
livereload_options = {:port => options["livereload-port"]} if options["livereload"]
Middleman::Guard.start({:port => options[:port]}, livereload_options)
config_check
if options["livereload"]
livereload_options = {:port => options["livereload-port"]}
end
Middleman::Guard.start({
:port => options[:port],
:environment => options[:environment]
}, livereload_options)
end
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'
def build
ENV['MM_ENV'] = "build"
Middleman::Builder.start
config_check
thor_group = Middleman::Builder.new([], options).invoke_all
end
desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
def migrate
config_check
return if File.exists?("source")
`mv public source`
`cp -R views/* source/`
`rm -rf views`

View file

@ -61,7 +61,9 @@ module Guard
# :Logger => ::WEBrick::Log.new('/dev/null')
}
@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'
::Rack::Server.new(@server_options).start
end