| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | #!/usr/bin/env ruby | 
					
						
							| 
									
										
										
										
											2019-02-01 11:54:16 -06:00
										 |  |  | require 'fileutils' | 
					
						
							| 
									
										
										
										
											2020-06-02 17:12:06 -05:00
										 |  |  | require 'securerandom' | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | # path to your application root. | 
					
						
							| 
									
										
										
										
											2020-05-20 15:36:31 -05:00
										 |  |  | APP_ROOT = File.expand_path('..', __dir__) | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-01 11:54:16 -06:00
										 |  |  | def system!(*args) | 
					
						
							|  |  |  |   system(*args) || abort("\n== Command #{args} failed ==") | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-20 15:36:31 -05:00
										 |  |  | FileUtils.chdir APP_ROOT do | 
					
						
							|  |  |  |   # This script is a way to setup or update your development environment automatically. | 
					
						
							|  |  |  |   # This script is idempotent, so that you can run it at anytime and get an expectable outcome. | 
					
						
							| 
									
										
										
										
											2019-02-01 11:54:16 -06:00
										 |  |  |   # Add necessary setup steps to this file. | 
					
						
							| 
									
										
										
										
											2020-06-05 14:37:52 -05:00
										 |  |  |    | 
					
						
							|  |  |  |   # we don't install dependencies on ci because it's been done already | 
					
						
							|  |  |  |   if ARGV.length == 0 || (ARGV.length > 0 && ARGV[0] != 'ci') | 
					
						
							|  |  |  |     puts '== Installing dependencies (Ruby) ==' | 
					
						
							|  |  |  |     system! 'gem install bundler --conservative' | 
					
						
							|  |  |  |     system('bundle check') || system!('bundle install') | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 14:37:52 -05:00
										 |  |  |     puts "\n== Installing dependencies (JS) ==" | 
					
						
							|  |  |  |     system!('yarn -s') | 
					
						
							| 
									
										
										
										
											2020-06-04 11:19:29 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-06-02 17:12:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 11:19:29 -05:00
										 |  |  |   if ARGV.length == 0 || (ARGV.length > 0 && ARGV[0] != 'ci') | 
					
						
							|  |  |  |     puts "\n== Copying env file ==" | 
					
						
							|  |  |  |     unless File.exist?('.env') | 
					
						
							|  |  |  |       FileUtils.cp '.env.template', '.env' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     puts "\n== Create new secrets ==" | 
					
						
							|  |  |  |     File.write('.env', File.read('.env').gsub(/-- secret string --/) { SecureRandom.hex(64) }) | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     puts "\n== Copying env file ==" | 
					
						
							|  |  |  |     FileUtils.cp '.env.test', '.env' | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   puts "\n== Preparing database ==" | 
					
						
							| 
									
										
										
										
											2020-06-22 16:48:59 -05:00
										 |  |  |   system! 'bin/rails db:prepare db:seed' | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   puts "\n== Removing old logs and tempfiles ==" | 
					
						
							| 
									
										
										
										
											2019-02-01 11:54:16 -06:00
										 |  |  |   system! 'bin/rails log:clear tmp:clear' | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   puts "\n== Restarting application server ==" | 
					
						
							| 
									
										
										
										
											2019-02-01 11:54:16 -06:00
										 |  |  |   system! 'bin/rails restart' | 
					
						
							| 
									
										
										
										
											2019-01-29 14:13:52 -06:00
										 |  |  | end |