Class: Rolemodel::HerokuGenerator

Inherits:
GeneratorBase
  • Object
show all
Defined in:
lib/generators/rolemodel/heroku/heroku_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_assets_rake_tasksObject

rubocop:disable Metrics/MethodLength



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/rolemodel/heroku/heroku_generator.rb', line 35

def create_assets_rake_tasks # rubocop:disable Metrics/MethodLength
  say 'Enhancing assets:precompile task to remove node_modules directory during production build.', :green
  rakefile('assets.rake', <<~RAKE)
    # All runtime asset dependencies should be bundled by Webpack during asset precompilation.
    # Therefore, the node_modules directory can be removed after assets are compiled to significantly reduce slug size.
    # In rare cases, you may have a runtime dependency into node_modules directly. If this is the case and you are unable
    # to bundle the dependency, delete this file and the node_modules directory will be included in your production slug.

    Rake::Task['assets:precompile'].enhance do
      if Rails.env.production?
        puts '----> Removing node_modules directory to reduce slug size.'
        FileUtils.rm_rf(Rails.root.join('node_modules'))
      end
    end
  RAKE
end

#enable_log_level_configurabilityObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/rolemodel/heroku/heroku_generator.rb', line 24

def enable_log_level_configurability
  say 'Enable log-level adjustment via "LOG_LEVEL" environment variable', :green

  gsub_file(
    'config/environments/production.rb',
    'config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")',
    "config.log_level = ENV.fetch('LOG_LEVEL', 'INFO')"
  )
  gsub_file('config/environments/production.rb', 'config.log_level = :info', "config.log_level = ENV.fetch('LOG_LEVEL', 'INFO')")
end

#force_sslObject



18
19
20
21
22
# File 'lib/generators/rolemodel/heroku/heroku_generator.rb', line 18

def force_ssl
  say 'Require SSL for production environment.', :green

  uncomment_lines('config/environments/production.rb', 'config.force_ssl = true')
end

#install_app_jsonObject



5
6
7
8
9
10
# File 'lib/generators/rolemodel/heroku/heroku_generator.rb', line 5

def install_app_json
  say 'Install app.json file', :green

  @project_name = Rails.application.class.try(:parent_name) || Rails.application.class.module_parent_name
  template 'app.json'
end

#install_procfileObject



12
13
14
15
16
# File 'lib/generators/rolemodel/heroku/heroku_generator.rb', line 12

def install_procfile
  say 'Install Procfile', :green

  template 'Procfile'
end