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) heroku.ensure_app_exists(environment) 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) case environment when :staging then env = :stg when :production then env = :prd end remote_name = "#{env}-heroku" heroku.setup(environment) if !(`git remote`).split(/\r?\n/).include?(remote_name) vars = Fanforce::AppFactory::CLI::Env.new(app).vars(environment) heroku.update_config(environment, 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} (#{remote_name})..." console_command("git push #{remote_name} master", true) end end