docbrown/lib/tasks/temporary/env_variables.rake
Molly Struve 1be8c72206
[deploy] Refactor:Remove ENVied Gem, Use dotenv Instead for Test and Development (#9621)
* Refactor:Remove ENVied Gem in Favor of Default application.yml

* Copy sample_application.yml for Travis

* Create .env_sample file, Warn of missing ENV variables, ignore .env file

* Use dotenv For ENV variables and create Rake Task to Populate

* Update docs to copy .env_sample file

* make application config a bit more resilient

* update more documentation and only initialize dotenv in dev and test

* Update doc code snippet types and refactor rake task and app config

* remove push defaults

* Make initializers more resilient, remove unused ENV from travis

* Exit new rake task if application.yml does not exist, include dotenv in docs
2020-08-12 11:01:38 -04:00

18 lines
524 B
Ruby

# Create a .env file from your application.yml file
task create_dot_env_file: :environment do
exit unless File.file?("config/application.yml")
File.open(".env", "w") do |env_file|
File.open("config/application.yml", 'r') do |file|
file.each_line do |line|
new_line = line.gsub(": ", "=")
unless new_line.blank? || new_line.starts_with?("#")
new_line.prepend("export ")
end
env_file.write(new_line)
end
end
end
File.delete("config/application.yml")
end