#!/usr/bin/env ruby # Rbenv shims and the bundler/inline feature don't work quite well, at least in Ruby 2.5.0. # # The reasons is that Wagon rbenv shim activates all the gems of the Wagon gem. # When activating them, it might load versions of the gems different from # the ones specified by the gemfile statement. # # Hopefully, it just activates meaning it doesn't load them. # So the solution is simple: reset both the Gem loaded specs and the $LOAD_PATH variable. def reset_gem_specs! return unless Gem.loaded_specs.keys.include?('locomotivecms_wagon') core_gems = %w(did_you_mean).freeze Gem.loaded_specs.values.each do |spec| next if core_gems.include?(spec.name) spec.full_require_paths.each do |path| $LOAD_PATH.delete(path) end # Without this statement, bundler will raise the infamous "You have already activated ..." Gem.loaded_specs.delete(spec.name) end end if ENV["BUNDLE_BIN_PATH"] # Wagon is launched within the Bundler context (basically with bundle exec wagon), # do nothing since Bundler already took take care of loading the right gems. ENV['WAGON_GEMFILE'] = '1' elsif ENV['WAGON_GEMFILE'] reset_gem_specs! # For LocomotiveCMS developers who want to run a local version of Wagon # with gems like Steam, Coal and Common pointing to the local sources puts "!!!WARNING!!! Using Wagon described in the following Gemfile: #{ENV['WAGON_GEMFILE']}" ENV['BUNDLE_GEMFILE'] ||= ENV['WAGON_GEMFILE'] require 'bundler' Bundler.require else reset_gem_specs! # Almost of all the users will rely on the gems described in # the gemspec of the current Wagon version. require 'bundler/inline' gemfile do source 'https://rubygems.org' gemspec path: File.dirname(__FILE__) + '/..' # Mac OS X gem 'rb-fsevent', '~> 0.10.3', require: 'rb-fsevent' if RUBY_PLATFORM.include?('darwin') # Unix gem 'therubyracer', require: 'v8', platforms: :ruby unless RUBY_PLATFORM.include?('darwin') gem 'rb-inotify', '~> 0.10.0', require: 'rb-inotify' if RUBY_PLATFORM.include?('linux') # Windows gem 'wdm', '~> 0.1.1', require: 'wdm' if RUBY_PLATFORM =~ /mswin|mingw/i end end $stdout.sync = true require 'locomotive/wagon' require 'locomotive/wagon/cli' # Let the magin happens Locomotive::Wagon::CLI::Main.start