1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/middleman-core/bin/middleman

71 lines
1.8 KiB
Text
Raw Normal View History

#!/usr/bin/env ruby
2011-12-29 01:52:51 -05:00
# Add our lib/ directory to the path
libdir = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "lib"))
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
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)
# 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?
return false if cwd.root?
locate_root(cwd.parent)
end
2011-12-29 01:52:51 -05:00
# Only look for config.rb if MM_ROOT isn't set
if !ENV["MM_ROOT"] && found_path = locate_root
2011-12-28 18:29:19 -05:00
ENV["MM_ROOT"] = found_path
end
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
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
if File.exists?(ENV['BUNDLE_GEMFILE'])
is_bundler_setup = true
require 'bundler/setup'
end
end
# Automatically discover extensions in RubyGems
require "middleman-core/extensions"
if is_bundler_setup
Bundler.require
else
::Middleman.load_extensions_in_path
end
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
# Start the CLI
if ENV["MM_ROOT"]
# Change directory to the root
Dir.chdir(ENV["MM_ROOT"])
Middleman::Cli::Base.start
else
Middleman::Cli::Base.start
end