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 19:51:36 -04:00
|
|
|
# Core Pathname library used for traversal
|
|
|
|
require "pathname"
|
|
|
|
|
|
|
|
# Recursive method to find config.rb
|
|
|
|
def locate_root(cwd = Pathname.new(Dir.pwd))
|
2012-06-01 22:05:32 -04:00
|
|
|
return cwd.to_s if (cwd + 'config.rb').exist?
|
2012-05-24 19:51:36 -04:00
|
|
|
return false if cwd.root?
|
|
|
|
locate_root(cwd.parent)
|
|
|
|
end
|
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 19:51:36 -04:00
|
|
|
if !ENV["MM_ROOT"] && found_path = 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
|
|
|
|
2012-06-13 23:33:50 -04:00
|
|
|
is_bundler_setup = false
|
|
|
|
|
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
|
|
|
|
2012-05-26 17:15:36 -04:00
|
|
|
root_gemfile = File.expand_path('Gemfile', ENV["MM_ROOT"])
|
|
|
|
ENV['BUNDLE_GEMFILE'] ||= root_gemfile
|
|
|
|
|
|
|
|
if !File.exists?(ENV['BUNDLE_GEMFILE'])
|
|
|
|
git_gemfile = Pathname.new(__FILE__).expand_path.parent.parent.parent + "Gemfile"
|
|
|
|
ENV['BUNDLE_GEMFILE'] = git_gemfile.to_s
|
|
|
|
end
|
|
|
|
|
2012-06-13 23:33:50 -04:00
|
|
|
if File.exists?(ENV['BUNDLE_GEMFILE'])
|
|
|
|
is_bundler_setup = true
|
|
|
|
require 'bundler/setup'
|
|
|
|
end
|
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"
|
2012-06-13 23:33:50 -04:00
|
|
|
|
|
|
|
if is_bundler_setup
|
|
|
|
Bundler.require
|
|
|
|
else
|
|
|
|
::Middleman.load_extensions_in_path
|
|
|
|
end
|
2012-05-24 14:03:58 -04:00
|
|
|
|
2012-05-26 17:15:36 -04:00
|
|
|
require "middleman-core/cli"
|
|
|
|
|
2012-06-05 14:48:34 -04:00
|
|
|
# Change flag to a module
|
|
|
|
ARGV.unshift("help") if ARGV.delete("--help")
|
|
|
|
|
2011-12-29 01:52:51 -05:00
|
|
|
# Default command is server
|
2012-06-05 14:48:34 -04:00
|
|
|
if ARGV[0] != "help" && (ARGV.length < 1 || ARGV.first.include?("-"))
|
|
|
|
ARGV.unshift("server")
|
|
|
|
end
|
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
|
2012-07-14 08:46:46 -04:00
|
|
|
Dir.chdir(ENV["MM_ROOT"])
|
|
|
|
Middleman::Cli::Base.start
|
2012-05-24 14:03:58 -04:00
|
|
|
else
|
2011-12-24 14:30:41 -05:00
|
|
|
Middleman::Cli::Base.start
|
2012-07-14 08:46:46 -04:00
|
|
|
end
|