class Fanforce::AppFactory::CLI::Scripts include Fanforce::AppFactory::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 app = Fanforce::CLI::App.load(Fanforce::CLI::DIR) if Fanforce::CLI::TYPE == :directory_of_apps confirm("\nYou are about to push iron works for #{Fanforce::CLI::Apps.total_count} apps in this directory.\n"+ 'ARE YOU SURE?', true) Fanforce::CLI::Apps.each do |app, processed_count, total_count| log divider '+-----------------------------------------------------------------------------------------------' log "#{'APP'.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... " push_app(app, environment, command) end elsif Fanforce::CLI::TYPE == :single_app log divider '+---------------------------------------------------------------------------------------------------' app = Fanforce::CLI::App.load(Fanforce::CLI::DIR) push_app(app, environment, command) end log divider '----------------------------------------------------------------------------------------------------++' end def push_app(app, environment, command) if command.to_s.include?('.worker') return push_app_worker(app, environment, command.to_s) end if [:all,:heroku].include?(command) and environment != :development heroku = Fanforce::AppFactory::CLI::Heroku.new(app, environment) heroku.ensure_app_exists end if [:all,:iron].include?(command) push_app_workers(app, environment) end if [:all,:env].include?(command) push_env(app, environment) end if [:all,:heroku].include?(command) and environment != :development push_heroku(heroku, app, environment) end end def push_app_worker(app, environment, filename) Dir.chdir(app.dir) do Fanforce::AppFactory::CLI::Iron.new(app).upload(environment, filename) end end def push_app_workers(app, environment) Dir.chdir(app.dir) do Fanforce::AppFactory::CLI::Iron.new(app).upload(environment) end end def push_env(app, environment) Fanforce::AppFactory::CLI::Env.new(app).setup(environment) end def push_heroku(heroku, app, environment) heroku.ensure_git_remote_exists vars = Fanforce::AppFactory::CLI::Env.new(app).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