Skip to content

Instantly share code, notes, and snippets.

@MOZGIII
Created January 22, 2016 00:32
Show Gist options
  • Save MOZGIII/ebdb96ccc321b90f77ae to your computer and use it in GitHub Desktop.
Save MOZGIII/ebdb96ccc321b90f77ae to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV["BUNDLE_IGNORE_CONFIG"] = 'true'
install_only = ARGV.to_a.map(&:to_sym)
install_only = [:host] if install_only.empty?
require 'bundler'
Bundler.configure
gemfile = Pathname.new(Bundler.default_gemfile).expand_path
builder = Bundler::Dsl.new
builder.eval_gemfile(gemfile)
all_groups = builder.dependencies.map(&:groups).flatten.uniq
groups_to_skip = all_groups - install_only
Bundler.settings.without = groups_to_skip
Bundler.settings.with = install_only
definition = builder.to_definition(Bundler.default_lockfile, {})
def definition.lock(*); end # never lock or preserve options
definition.validate_ruby!
Bundler.ui = Bundler::UI::Shell.new
Bundler::Installer.install(Bundler.root, definition, system: true)
module Bundler; module CLI; end; end
def confirm_without_groups
if Bundler.settings.without.any?
require 'bundler/cli/common'
Bundler.ui.confirm Bundler::CLI::Common.without_groups_message
end
end
def dependencies_count_for(definition)
count = definition.dependencies.count
"#{count} Gemfile #{count == 1 ? 'dependency' : 'dependencies'}"
end
def gems_installed_for(definition)
count = definition.specs.count
"#{count} #{count == 1 ? 'gem' : 'gems'} now installed"
end
def print_post_install_message(name, msg)
Bundler.ui.confirm "Post-install message from #{name}:"
Bundler.ui.info msg
end
Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}."
confirm_without_groups
Bundler::Installer.post_install_messages.each do |name, message|
print_post_install_message(name, message)
end
@bogdanRada
Copy link

awesome. I think this is exactly what i needed :) Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment