lib/hem/tasks/deps.rb in hem-1.0.1.beta6 vs lib/hem/tasks/deps.rb in hem-1.1.0

- old
+ new

@@ -2,11 +2,11 @@ hidden true namespace :deps do desc "Install Gem dependencies" task :gems do - locate "*Gemfile" do + locate "Gemfile" do required = shell("bundle check", :exit_status => true) != 0 if required Hem.ui.title "Installing Gem dependencies" bundler_args = "#{Hem.user_config.bundler_args} #{Hem.project_config.bundler_args}".strip @@ -44,25 +44,24 @@ end end end if !complete - run_command *args + run *args end Hem.ui.success "Composer dependencies installed" end Hem.ui.separator end end desc "Install vagrant plugins" - task :vagrant_plugins => [ "deps:gems" ] do - require 'semantic' - plugins = shell "vagrant plugin list", :capture => true - locate "*Vagrantfile" do + task :vagrant_plugins do + raw_plugins = shell "vagrant plugin list", :capture => true + locate "Vagrantfile" do to_install = {} File.read("Vagrantfile").split("\n").each do |line| if line.match(/#\s*(?:Hem|Hobo)\.(vagrant_plugin.*)/) to_install.merge! Hash[[eval("Hem.#{$1}")]] else @@ -71,41 +70,41 @@ to_install[$1.gsub(/['"]*/, '')] = nil end end plugins = Hash[ - plugins.scan(/^([^\s]+)\s+\(([^,\)]+)(?:,[^\)]+)?\)$/).map do |plugin, version| - [plugin, Semantic::Version.new(version)] + raw_plugins.scan(/^([^\s]+)\s+\(([^,\)]+)(?:,[^\)]+)?\)$/).map do |plugin, version| + [plugin, version] end ] to_install.each do |plugin, constraint| - next if plugins.has_key?(plugin) && (constraint.nil? || plugins[plugin].satisfies(constraint)) - Hem.ui.title "Installing vagrant plugin: #{plugin}#{constraint && " #{constraint}"}" + next if plugins.has_key?(plugin) && (constraint.nil? || constraint.match?(plugin, plugins[plugin])) + Hem.ui.title "Installing vagrant plugin: #{plugin}#{constraint.nil? ? '' : " #{constraint.requirement.to_s}"}" args = ["vagrant", "plugin", "install", plugin] if constraint args << '--plugin-version' - args << constraint + args << constraint.requirement.to_s end shell *args, :realtime => true, :indent => 2 Hem.ui.separator end end end desc "Install chef dependencies" task :chef => [ "deps:gems" ] do - locate "*Cheffile" do + locate "Cheffile" do Hem.ui.title "Installing chef dependencies via librarian" bundle_shell "librarian-chef", "install", "--verbose", :realtime => true, :indent => 2 do |line| line =~ /Installing.*</ ? line.strip + "\n" : nil end Hem.ui.separator end - locate "*Berksfile" do + locate "Berksfile" do Hem.ui.title "Installing chef dependencies via berkshelf" - executor = (shell("bash -c 'which berks'", :capture => true).strip =~ /chefdk/) ? + executor = (shell("bundle show berkshelf", exit_status: true) > 0) ? lambda { |*args| shell *args } : lambda { |*args| bundle_shell *args } executor.call "berks", "install", :realtime => true, :indent => 2 version = executor.call "berks", "-v", :capture => true