2011-07-27 00:06:24 -04:00
|
|
|
#!/usr/bin/env ruby
|
2011-07-27 02:19:43 -04:00
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Add our lib/ directory to the path
|
2011-12-24 14:30:41 -05: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 20:10:16 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
moredir = File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more"))
|
|
|
|
$LOAD_PATH.unshift(moredir) unless $LOAD_PATH.include?(moredir)
|
2011-08-03 20:10:16 -04:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
require "middleman-core/cli"
|
2011-08-03 20:10:16 -04:00
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Only look for config.rb if MM_ROOT isn't set
|
2012-05-24 14:03:58 -04:00
|
|
|
if !ENV["MM_ROOT"] && found_path = ::Middleman.locate_root
|
2011-12-28 18:29:19 -05:00
|
|
|
ENV["MM_ROOT"] = found_path
|
2011-12-24 14:30:41 -05:00
|
|
|
end
|
2011-08-03 20:10:16 -04:00
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# If we've found the root, try to setup Bundler
|
2011-12-28 18:29:19 -05:00
|
|
|
if ENV["MM_ROOT"]
|
2011-12-29 01:52:51 -05:00
|
|
|
|
2011-12-24 14:30:41 -05:00
|
|
|
# Set up gems listed in the Gemfile.
|
2011-12-28 18:29:19 -05:00
|
|
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV["MM_ROOT"])
|
2011-12-24 14:30:41 -05:00
|
|
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
2011-08-03 20:10:16 -04:00
|
|
|
end
|
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
# Automatically discover extensions in RubyGems
|
|
|
|
require "middleman-core/extensions"
|
|
|
|
::Middleman.load_extensions_in_path
|
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Default command is server
|
2012-01-02 17:22:24 -05:00
|
|
|
ARGV.unshift("server") if ARGV.length < 1 || ARGV.first.include?("-")
|
2011-12-29 01:52:51 -05:00
|
|
|
|
2012-05-24 14:03:58 -04:00
|
|
|
# Start the CLI
|
|
|
|
if ENV["MM_ROOT"]
|
|
|
|
# Change directory to the root
|
|
|
|
Dir.chdir(ENV["MM_ROOT"]) do
|
|
|
|
Middleman::Cli::Base.start
|
2012-01-02 13:45:52 -05:00
|
|
|
end
|
2012-05-24 14:03:58 -04:00
|
|
|
else
|
2011-12-24 14:30:41 -05:00
|
|
|
Middleman::Cli::Base.start
|
2012-05-24 14:03:58 -04:00
|
|
|
end
|