2011-07-26 21:06:24 -07:00
|
|
|
#!/usr/bin/env ruby
|
2011-07-26 23:19:43 -07:00
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# Add our lib/ directory to the path
|
2011-12-24 11:30:41 -08:00
|
|
|
libdir = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "lib"))
|
|
|
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
2011-08-03 17:10:16 -07:00
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# Setup RubyGems
|
|
|
|
require "rubygems"
|
2011-08-03 17:10:16 -07:00
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# Core Pathname library used for traversal
|
|
|
|
require "pathname"
|
|
|
|
|
|
|
|
# Recursive method to find config.rb
|
2011-12-24 11:30:41 -08:00
|
|
|
def locate_middleman_root!(cwd = Pathname.new(Dir.pwd))
|
|
|
|
return cwd.to_s if File.exists?(File.join(cwd, 'config.rb'))
|
|
|
|
return false if cwd.root?
|
|
|
|
locate_middleman_root!(cwd.parent)
|
|
|
|
end
|
2011-08-03 17:10:16 -07:00
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# Only look for config.rb if MM_ROOT isn't set
|
2011-12-28 15:29:19 -08:00
|
|
|
if !ENV["MM_ROOT"] && found_path = locate_middleman_root!
|
|
|
|
ENV["MM_ROOT"] = found_path
|
2011-12-24 11:30:41 -08:00
|
|
|
end
|
2011-08-03 17:10:16 -07:00
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# If we've found the root, try to setup Bundler
|
2011-12-28 15:29:19 -08:00
|
|
|
if ENV["MM_ROOT"]
|
2011-12-28 22:52:51 -08:00
|
|
|
|
2011-12-24 11:30:41 -08:00
|
|
|
# Set up gems listed in the Gemfile.
|
2011-12-28 15:29:19 -08:00
|
|
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV["MM_ROOT"])
|
2011-12-24 11:30:41 -08:00
|
|
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
2011-08-03 17:10:16 -07:00
|
|
|
end
|
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# Default command is server
|
2012-01-02 14:22:24 -08:00
|
|
|
ARGV.unshift("server") if ARGV.length < 1 || ARGV.first.include?("-")
|
2011-12-28 22:52:51 -08:00
|
|
|
|
2011-12-29 19:04:39 -08:00
|
|
|
begin
|
2012-02-05 11:43:19 -08:00
|
|
|
# Local
|
|
|
|
require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more"))
|
2011-12-29 19:04:39 -08:00
|
|
|
rescue LoadError
|
2012-01-02 10:45:52 -08:00
|
|
|
begin
|
2012-02-05 11:43:19 -08:00
|
|
|
# Rubygems
|
|
|
|
require "middleman-more"
|
2012-01-02 10:45:52 -08:00
|
|
|
rescue LoadError
|
2012-02-05 11:43:19 -08:00
|
|
|
# Require Middleman
|
|
|
|
require 'middleman-core'
|
2012-01-02 10:45:52 -08:00
|
|
|
end
|
2011-12-29 19:04:39 -08:00
|
|
|
end
|
|
|
|
|
2011-12-28 22:52:51 -08:00
|
|
|
# Change directory to the root
|
2011-12-28 15:29:19 -08:00
|
|
|
Dir.chdir(ENV["MM_ROOT"] || Dir.pwd) do
|
2011-12-28 22:52:51 -08:00
|
|
|
|
|
|
|
# Start the CLI
|
2011-12-24 11:30:41 -08:00
|
|
|
Middleman::Cli::Base.start
|
2011-08-03 17:10:16 -07:00
|
|
|
end
|