-
-
Save bogdanRada/9b6c7e7100e7c486d9161acb9598b0db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment