middleman/bin/middleman
2011-12-24 12:26:14 -08:00

30 lines
No EOL
815 B
Ruby
Executable file

#!/usr/bin/env ruby
require "rubygems"
require "pathname"
libdir = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "lib"))
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
ARGV << "server" if ARGV.length < 1
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
if !ENV['MM_ROOT'] && found_path = locate_middleman_root!
ENV['MM_ROOT'] = found_path
end
if ENV['MM_ROOT']
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV['MM_ROOT'])
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
end
require 'middleman'
Dir.chdir(ENV['MM_ROOT'] || Dir.pwd) do
Middleman::Cli::Base.start
end