Merge pull request #1194 from bhollis/gemfile

Require Bundler (a Gemfile) for all set up Middleman projects
This commit is contained in:
Thomas Reynolds 2014-03-08 16:05:34 -08:00
commit 8b20b39b31
5 changed files with 29 additions and 69 deletions

View file

@ -1,6 +1,9 @@
master
===
* Remove 'upgrade' and 'install' CLI commands.
* Gemfile may be in a parent directory of your Middleman project root (where 'config.rb' is).
* All dependencies for your Middleman project must be expressed in `Gemfile` - Bundler is no longer optional.
* Asciidoc information now available with the `asciidoc` local, which is a normal hash.
* Remove `page` template local. Use `current_resource` instead.
* Dropped support for providing a block to `page` & `proxy`.

View file

@ -24,7 +24,6 @@ platforms :ruby do
gem 'therubyracer'
gem 'redcarpet', '~> 3.1'
gem 'pry', :require => false, :group => :development
gem 'pry-debugger', :require => false, :group => :development
end
platforms :jruby do

View file

@ -88,7 +88,6 @@ end
# Include the core CLI items
require 'middleman-cli/init'
require 'middleman-cli/bundler'
require 'middleman-cli/extension'
require 'middleman-cli/server'
require 'middleman-cli/build'

View file

@ -1,40 +0,0 @@
# CLI Module
module Middleman::Cli
# A initializing Bundler
class Bundle < Thor
include Thor::Actions
check_unknown_options!
namespace :bundle
desc 'bundle', 'Setup initial bundle', :hide => true
# The setup task
def bundle
run('bundle install')#, :capture => true)
end
end
# A upgrading Bundler
class Upgrade < Thor
include Thor::Actions
check_unknown_options!
namespace :upgrade
desc 'upgrade', 'Upgrade installed bundle'
# The upgrade task
def upgrade
inside(ENV['MM_ROOT']) do
run('bundle update')#, :capture => true)
end
end
end
# Map "u" to "upgrade"
Base.map({
'u' => 'upgrade'
})
end

View file

@ -8,35 +8,16 @@ module Middleman
@_is_setup ||= begin
# Only look for config.rb if MM_ROOT isn't set
if !ENV['MM_ROOT'] && found_path = locate_root
if !ENV['MM_ROOT'] && (found_path = findup('config.rb'))
ENV['MM_ROOT'] = found_path
end
is_bundler_setup = false
# If we've found the root, try to setup Bundler
if ENV['MM_ROOT']
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
setup_bundler
else
# Automatically discover extensions in RubyGems
require 'middleman-core/extensions'
::Middleman.load_extensions_in_path
end
@ -44,11 +25,29 @@ module Middleman
end
end
# Recursive method to find config.rb
def locate_root(cwd = Pathname.new(Dir.pwd))
return cwd.to_s if (cwd + 'config.rb').exist?
private
# Set BUNDLE_GEMFILE and run Bundler setup. Raises an exception if there is no Gemfile
def setup_bundler
ENV['BUNDLE_GEMFILE'] ||= findup('Gemfile', ENV['MM_ROOT'])
if !File.exists?(ENV['BUNDLE_GEMFILE'])
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
end
if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup'
Bundler.require
else
raise "Couldn't find your Gemfile. Middleman projects require a Gemfile for specifying dependencies."
end
end
# Recursive method to find a file in parent directories
def findup(filename, cwd = Pathname.new(Dir.pwd))
return cwd.to_s if (cwd + filename).exist?
return false if cwd.root?
locate_root(cwd.parent)
findup(filename, cwd.parent)
end
end