middleman/middleman-core/bin/middleman

60 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
2011-12-29 07:52:51 +01: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)
2011-12-29 07:52:51 +01:00
# Setup RubyGems
require "rubygems"
2011-12-29 07:52:51 +01:00
# Core Pathname library used for traversal
require "pathname"
# Recursive method to find config.rb
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
2011-12-29 07:52:51 +01:00
# Only look for config.rb if MM_ROOT isn't set
2011-12-29 00:29:19 +01:00
if !ENV["MM_ROOT"] && found_path = locate_middleman_root!
ENV["MM_ROOT"] = found_path
end
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
# Set up gems listed in the Gemfile.
2011-12-29 00:29:19 +01:00
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENV["MM_ROOT"])
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
end
2011-12-29 07:52:51 +01:00
# Default command is server
2012-01-02 23:22:24 +01:00
ARGV.unshift("server") if ARGV.length < 1 || ARGV.first.include?("-")
2011-12-29 07:52:51 +01:00
begin
# Local
require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more"))
rescue LoadError
2012-01-02 19:45:52 +01:00
begin
# Rubygems
require "middleman-more"
2012-01-02 19:45:52 +01:00
rescue LoadError
# Require Middleman
require 'middleman-core'
2012-01-02 19:45:52 +01:00
end
end
# Automatically discover extensions in RubyGems
Middleman.load_extensions_in_path
require "middleman-core/cli"
2011-12-29 07:52:51 +01:00
# Change directory to the root
2011-12-29 00:29:19 +01:00
Dir.chdir(ENV["MM_ROOT"] || Dir.pwd) do
2011-12-29 07:52:51 +01:00
# Start the CLI
Middleman::Cli::Base.start
end