2011-07-27 06:06:24 +02:00
|
|
|
#!/usr/bin/env ruby
|
2011-07-27 08:19:43 +02:00
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# Add our lib/ directory to the path
|
2011-12-24 20:30:41 +01:00
|
|
|
libdir = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "lib"))
|
|
|
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
2011-08-04 02:10:16 +02:00
|
|
|
|
2012-05-24 20:03:58 +02: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-04 02:10:16 +02:00
|
|
|
|
2012-05-25 01:51:36 +02: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-02 04:05:32 +02:00
|
|
|
return cwd.to_s if (cwd + 'config.rb').exist?
|
2012-05-25 01:51:36 +02:00
|
|
|
return false if cwd.root?
|
|
|
|
locate_root(cwd.parent)
|
|
|
|
end
|
2011-08-04 02:10:16 +02:00
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# Only look for config.rb if MM_ROOT isn't set
|
2012-05-25 01:51:36 +02:00
|
|
|
if !ENV["MM_ROOT"] && found_path = locate_root
|
2011-12-29 00:29:19 +01:00
|
|
|
ENV["MM_ROOT"] = found_path
|
2011-12-24 20:30:41 +01:00
|
|
|
end
|
2011-08-04 02:10:16 +02:00
|
|
|
|
2012-06-14 05:33:50 +02:00
|
|
|
is_bundler_setup = false
|
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# If we've found the root, try to setup Bundler
|
2011-12-29 00:29:19 +01:00
|
|
|
if ENV["MM_ROOT"]
|
2011-12-29 07:52:51 +01:00
|
|
|
|
2012-05-26 23:15:36 +02: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-14 05:33:50 +02:00
|
|
|
if File.exists?(ENV['BUNDLE_GEMFILE'])
|
|
|
|
is_bundler_setup = true
|
|
|
|
require 'bundler/setup'
|
|
|
|
end
|
2011-08-04 02:10:16 +02:00
|
|
|
end
|
|
|
|
|
2012-05-24 20:03:58 +02:00
|
|
|
# Automatically discover extensions in RubyGems
|
|
|
|
require "middleman-core/extensions"
|
2012-06-14 05:33:50 +02:00
|
|
|
|
|
|
|
if is_bundler_setup
|
|
|
|
Bundler.require
|
|
|
|
else
|
|
|
|
::Middleman.load_extensions_in_path
|
|
|
|
end
|
2012-05-24 20:03:58 +02:00
|
|
|
|
2012-05-26 23:15:36 +02:00
|
|
|
require "middleman-core/cli"
|
|
|
|
|
2012-06-05 20:48:34 +02:00
|
|
|
# Change flag to a module
|
|
|
|
ARGV.unshift("help") if ARGV.delete("--help")
|
|
|
|
|
2011-12-29 07:52:51 +01:00
|
|
|
# Default command is server
|
2012-06-05 20:48:34 +02:00
|
|
|
if ARGV[0] != "help" && (ARGV.length < 1 || ARGV.first.include?("-"))
|
|
|
|
ARGV.unshift("server")
|
|
|
|
end
|
2011-12-29 07:52:51 +01:00
|
|
|
|
2012-05-24 20:03:58 +02:00
|
|
|
# Start the CLI
|
|
|
|
if ENV["MM_ROOT"]
|
|
|
|
# Change directory to the root
|
2012-07-14 14:46:46 +02:00
|
|
|
Dir.chdir(ENV["MM_ROOT"])
|
|
|
|
Middleman::Cli::Base.start
|
2012-05-24 20:03:58 +02:00
|
|
|
else
|
2011-12-24 20:30:41 +01:00
|
|
|
Middleman::Cli::Base.start
|
2012-07-14 14:46:46 +02:00
|
|
|
end
|