mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
try to plug into Bundler if gemfile exists
This commit is contained in:
parent
c9f02e22ba
commit
1110d434bb
2 changed files with 58 additions and 14 deletions
|
@ -1,8 +1,60 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require "rubygems"
|
|
||||||
|
|
||||||
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
||||||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
require 'middleman'
|
require 'pathname'
|
||||||
Middleman::CLI.start
|
require 'rubygems'
|
||||||
|
|
||||||
|
module Middleman
|
||||||
|
module ProjectLocator
|
||||||
|
def self.locate_middleman_root!
|
||||||
|
cwd = Dir.pwd
|
||||||
|
|
||||||
|
if !in_middleman_project? && !in_middleman_project_subdirectory?
|
||||||
|
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if in_middleman_project?
|
||||||
|
did_locate_middleman_project(cwd)
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.chdir("..") do
|
||||||
|
# Recurse in a chdir block: if the search fails we want to be sure
|
||||||
|
# the application is generated in the original working directory.
|
||||||
|
locate_middleman_root! unless cwd == Dir.pwd
|
||||||
|
end
|
||||||
|
rescue SystemCallError
|
||||||
|
# could not chdir, no problem just return
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.in_middleman_project?
|
||||||
|
File.exists?('config.rb')
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.in_middleman_project_subdirectory?(path = Pathname.new(Dir.pwd))
|
||||||
|
File.exists?(File.join(path, 'config.rb')) || !path.root? && in_middleman_project_subdirectory?(path.parent)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.did_locate_middleman_project(path)
|
||||||
|
# Set up gems listed in the Gemfile.
|
||||||
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', path)
|
||||||
|
|
||||||
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
|
|
||||||
|
start_cli!
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.start_cli!
|
||||||
|
require 'middleman'
|
||||||
|
Middleman::CLI.start
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if ARGV.length < 1 || %w(server build migrate).include?(ARGV.first)
|
||||||
|
Middleman::ProjectLocator.locate_middleman_root!
|
||||||
|
else
|
||||||
|
Middleman::ProjectLocator.start_cli!
|
||||||
|
end
|
|
@ -34,7 +34,7 @@ module Middleman
|
||||||
method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
|
method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
|
||||||
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
|
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
|
||||||
def server
|
def server
|
||||||
config_check && v1_check
|
v1_check
|
||||||
if options["livereload"]
|
if options["livereload"]
|
||||||
livereload_options = {:port => options["livereload-port"]}
|
livereload_options = {:port => options["livereload-port"]}
|
||||||
end
|
end
|
||||||
|
@ -48,13 +48,12 @@ module Middleman
|
||||||
desc "build", "Builds the static site for deployment"
|
desc "build", "Builds the static site for deployment"
|
||||||
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
||||||
def build
|
def build
|
||||||
config_check && v1_check
|
v1_check
|
||||||
thor_group = Middleman::Builder.new([], options).invoke_all
|
thor_group = Middleman::Builder.new([], options).invoke_all
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
|
desc "migrate", "Migrates an older Middleman project to the 2.0 structure"
|
||||||
def migrate
|
def migrate
|
||||||
config_check
|
|
||||||
return if File.exists?("source")
|
return if File.exists?("source")
|
||||||
`mv public source`
|
`mv public source`
|
||||||
`cp -R views/* source/`
|
`cp -R views/* source/`
|
||||||
|
@ -69,16 +68,9 @@ module Middleman
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def config_check
|
|
||||||
if !File.exists?("config.rb")
|
|
||||||
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def v1_check
|
def v1_check
|
||||||
if File.exists?("views") || File.exists?("public")
|
if File.exists?("views") || File.exists?("public")
|
||||||
$stderr.puts "== Error: The views and public folders are have been combined. Create a new 'source' folder, add the contents of views and public to it and then remove the empty views and public folders."
|
$stderr.puts "== Error: The views and public folders are have been combined. Use the 'middleman migrate' command to merge your folders automatically."
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue