|
25 | 25 |
|
26 | 26 | desc 'Automate the Config Setup for New Environments'
|
27 | 27 | task setup_workspace: :environment do
|
28 |
| - SECRETS = { |
29 |
| - SECRET_KEY_BASE: generate_secret, |
30 |
| - DEVISE_SECRET_KEY: generate_secret |
31 |
| - }.freeze |
32 |
| - |
33 |
| - %w[development test].each do |environment| |
34 |
| - example = Rails.root.join('config', 'env', "#{environment}.example.env") |
35 |
| - target = Rails.root.join('config', 'env', "#{environment}.env") |
36 |
| - FileUtils.cp(example, target) |
37 |
| - |
38 |
| - # insert the secrets into the file |
39 |
| - content = File.read(target) |
40 |
| - %w[SECRET_KEY_BASE DEVISE_SECRET_KEY].each do |key| |
41 |
| - content.sub!(%(#{key}=""), %(#{key}="#{SECRETS[key.to_sym]}")) |
| 28 | + begin |
| 29 | + SECRETS = { |
| 30 | + SECRET_KEY_BASE: generate_secret, |
| 31 | + DEVISE_SECRET_KEY: generate_secret |
| 32 | + }.freeze |
| 33 | + |
| 34 | + %w[development test].each do |environment| |
| 35 | + example = Rails.root.join('config', 'env', "#{environment}.example.env") |
| 36 | + target = Rails.root.join('config', 'env', "#{environment}.env") |
| 37 | + FileUtils.cp(example, target) |
| 38 | + |
| 39 | + # insert the secrets into the file |
| 40 | + content = File.read(target) |
| 41 | + %w[SECRET_KEY_BASE DEVISE_SECRET_KEY].each do |key| |
| 42 | + content.sub!(%(#{key}=""), %(#{key}="#{SECRETS[key.to_sym]}")) |
| 43 | + end |
| 44 | + File.write(target, content) |
42 | 45 | end
|
43 |
| - File.write(target, content) |
| 46 | + |
| 47 | + puts "Workspace setup completed successfully 🎉" |
| 48 | + rescue StandardError => e |
| 49 | + puts "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}" |
| 50 | + Rails.logger.error "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}" |
44 | 51 | end
|
45 | 52 | end
|
46 | 53 |
|
|
0 commit comments