class Fanforce::PluginFactory::CLI::Scripts include Fanforce::PluginFactory::CLI::Utils require_relative '../lib/env' require_relative '../lib/iron' require_relative '../lib/heroku' ###################################################################################################################### def push(environment, command) environment = environment.to_sym command = command.to_sym plugin = Fanforce::CLI::Plugin.load(Fanforce::CLI::DIR) if Fanforce::CLI::TYPE == :directory_of_plugins confirm("\nYou are about to push iron works for #{Fanforce::CLI::Plugins.total_count} plugins in this directory.\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})... " push_plugin(plugin, environment, command) end elsif Fanforce::CLI::TYPE == :single_plugin log divider '+---------------------------------------------------------------------------------------------------' plugin = Fanforce::CLI::Plugin.load(Fanforce::CLI::DIR) push_plugin(plugin, environment, command) end log divider '----------------------------------------------------------------------------------------------------++' end def push_plugin(plugin, environment, command) if command.to_s.include?('.worker') return push_plugin_worker(plugin, environment, command.to_s) end if [:all,:heroku].include?(command) and environment != :development heroku = Fanforce::PluginFactory::CLI::Heroku.new(plugin, environment) heroku.ensure_app_exists end if [:all,:iron].include?(command) push_plugin_workers(plugin, environment) end if [:all,:env].include?(command) push_env(plugin, environment) end if [:all,:heroku].include?(command) and environment != :development push_heroku(heroku, plugin, environment) end end def push_plugin_worker(plugin, environment, filename) Dir.chdir(plugin.dir) do Fanforce::PluginFactory::CLI::Iron.new(plugin).upload(environment, filename) end end def push_plugin_workers(plugin, environment) Dir.chdir(plugin.dir) do Fanforce::PluginFactory::CLI::Iron.new(plugin).upload(environment) end end def push_env(plugin, environment) Fanforce::PluginFactory::CLI::Env.new(plugin).setup(environment) end def push_heroku(heroku, plugin, environment) heroku.ensure_git_remote_exists vars = Fanforce::PluginFactory::CLI::Env.new(plugin).vars(environment) heroku.update_config(vars) log 'Updated ENV'.format(:green,:bold) + " on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..." puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{heroku.git_remote_name})..." console_command("git push #{heroku.git_remote_name} master", true) end end