class Fanforce::PluginFactory::CLI::Scripts include Fanforce::PluginFactory::CLI::Utils require_relative '../lib/env' require_relative '../lib/scaffolding' require_relative '../lib/bundler' ###################################################################################################################### def update(type) type = type.to_sym return update_factory if type == :factory if Fanforce::CLI::TYPE == :directory_of_plugins confirm("\nYou are about to update #{Fanforce::CLI::Plugins.total_count} plugins in this directory. This cannot be undone.\n"+ 'ARE YOU SURE?', true) Fanforce::CLI::Plugins.each do |plugin, processed_count, total_count| log divider '+-------------------------------------------------------------------------------------------------' log "#{'PLUGIN'.format(:bold)} - #{plugin._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " update_plugin(plugin, type) end elsif Fanforce::CLI::TYPE == :single_plugin plugin = Fanforce::CLI::Plugin.load(Fanforce::CLI::DIR) confirm("\nYou are about to update #{plugin.name}. This cannot be undone.\n" + 'ARE YOU SURE?', true) update_plugin(plugin, type) end puts '' end def update_plugin(plugin, type) if [:all,:files].include?(type) if !Fanforce::PluginFactory::CLI::Scaffolding.new(plugin).update log 'NO FILES NEED UPDATING' end end if [:all,:env].include?(type) Fanforce::PluginFactory::CLI::Env.new(plugin).setup(:development) end end def update_factory require_gem 'rest-client', 'rest_client' require_gem 'multi_json', 'multi_json' log divider '+--------------------------------------------------------------------------------------------------+' print 'CHECKING RUBYGEMS... ' response = RestClient::Request.execute(:method => :get, :url => 'https://rubygems.org/api/v1/versions/fanforce-plugin-factory.json', :ssl_version => 'SSLv23').body rubygems_version = MultiJson.load(response, symbolize_keys: true).first[:number] current_version = config[:plugin_factory_gem][:version].match(/(\S+)\s*$/)[1] if config[:plugin_factory_gem][:version] local_path = '/Fanforce/gems/fanforce-plugin-factory' if File.directory?(local_path) silence_warnings do require "#{local_path}/lib/fanforce/plugin_factory/version" end local_version = Fanforce::PluginFactory::VERSION end if current_version and (rubygems_version != current_version or local_version) i = 0 options = {} log "\n\nWe found multiple gem versions. Select the one you want used:" if local_version or config[:plugin_factory_gem][:path] if config[:plugin_factory_gem][:path] log " #{i+=1}. #{local_version} (found in .fanforce-plugin-factory / locally)" else log " #{i+=1}. #{local_version} (found locally)" end options[i] = :local end log " #{i+=1}. #{rubygems_version} (found in rubygems)" options[i] = :rubygems if !local_version log " #{i+=1}. #{current_version} (found in .fanforce-plugin-factory)" options[i] = :current end num_selected = prompt('> ').to_i if options[num_selected] == :local version = local_version config[:plugin_factory_gem][:path] = local_path elsif options[num_selected] == :rubygems version = rubygems_version config[:plugin_factory_gem].delete(:path) local_path = nil elsif options[num_selected] == :current version = current_version local_path = nil else error "Error: must enter a valid number [1-#{i}]" end File.open(config_filepath,'w') do |f| config[:plugin_factory_gem][:version] = version f.write config.to_yaml end else log 'DONE' version = rubygems_version end log divider '---------------------------------------------------------------------------------------------------+' local_path ? install_local_factory_gem(version, local_path) : install_remote_factory_gem(version) puts '' end def install_remote_factory_gem(version) system "gem install fanforce-plugin-factory -v #{version}" end def install_local_factory_gem(version, local_gem_path) return if !local_gem_path gem_filepath = nil Dir.chdir(local_gem_path) do system 'git add -A' system 'rake build' Dir.glob("#{local_gem_path}/pkg/*.gem").each do |file| break gem_filepath = file if file.include?(version) end end Dir.chdir(Fanforce::CLI::DIR) do log "INSTALLING #{gem_filepath}..." system "gem install #{gem_filepath}" end end end