Class: MobileWorkflow::Cli::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- MobileWorkflow::Cli::AppBuilder
- Defined in:
- lib/mobile_workflow/cli/app_builder.rb
Instance Method Summary collapse
- #active_storage ⇒ Object
- #administrate_generator ⇒ Object
- #dokku(dokku_host) ⇒ Object
- #factory_bot ⇒ Object
- #format_source ⇒ Object
- #gemfile ⇒ Object
- #generate_dot_env ⇒ Object
- #git_commit(message = 'Initial commit') ⇒ Object
- #heroku ⇒ Object
- #migrate_db ⇒ Object
- #mobile_workflow_generator(open_api_spec_path) ⇒ Object
- #procfiles ⇒ Object
- #readme ⇒ Object
- #rollbar ⇒ Object
- #rspec_generator ⇒ Object
- #rubocop ⇒ Object
- #s3_backend(region) ⇒ Object
- #simplecov ⇒ Object
Instance Method Details
#active_storage ⇒ Object
54 55 56 57 58 59 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 54 def active_storage rails_command 'active_storage:install' copy_file 'storage.s3.yml', 'config/storage.yml' gsub_file 'config/environments/production.rb', 'config.active_storage.service = :local', 'config.active_storage.service = :amazon' end |
#administrate_generator ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 35 def administrate_generator generate 'administrate:install' file 'app/assets/config/manifest.js', <<~CODE //= link administrate/application.css //= link administrate/application.js CODE file 'app/controllers/admin/application_controller.rb', <<~CODE module Admin class ApplicationController < Administrate::ApplicationController http_basic_authenticate_with(name: ENV["ADMIN_USER"], password: ENV["ADMIN_PASSWORD"]) end end CODE generate 'administrate:routes' end |
#dokku(dokku_host) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 133 def dokku(dokku_host) @dokku_host = dokku_host dokku_backend.create! dokku_backend.configure_activestorage if [:s3_storage] dokku_backend.deploy dokku_backend.sync_dotenv end |
#factory_bot ⇒ Object
23 24 25 26 27 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 23 def factory_bot inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do "\tconfig.include FactoryBot::Syntax::Methods\n" end end |
#format_source ⇒ Object
68 69 70 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 68 def format_source `rufo .` end |
#gemfile ⇒ Object
10 11 12 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 10 def gemfile template 'Gemfile.erb', 'Gemfile' end |
#generate_dot_env ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 72 def generate_dot_env admin_user = 'admin' admin_password = SecureRandom.base64(12) file '.env', <<~CODE ADMIN_USER=#{admin_user} ADMIN_PASSWORD=#{admin_password} CODE end |
#git_commit(message = 'Initial commit') ⇒ Object
105 106 107 108 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 105 def git_commit( = 'Initial commit') git add: '.' git commit: %( -m '#{}') end |
#heroku ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 125 def heroku heroku_backend.create! heroku_backend.configure_activestorage if [:s3_storage] heroku_backend.deploy heroku_backend.seed_db heroku_backend.sync_dotenv end |
#migrate_db ⇒ Object
29 30 31 32 33 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 29 def migrate_db rails_command('db:drop') rails_command('db:create') rails_command('db:migrate') end |
#mobile_workflow_generator(open_api_spec_path) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 61 def mobile_workflow_generator(open_api_spec_path) copy_file open_api_spec_path, 'config/open_api_spec.json' gen_opts = '' gen_opts += '--doorkeeper_oauth' if [:doorkeeper_oauth] generate "mobile_workflow:install #{gen_opts}" end |
#procfiles ⇒ Object
14 15 16 17 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 14 def procfiles copy_file 'Procfile', 'Procfile' copy_file 'Procfile.dev', 'Procfile.dev' end |
#readme ⇒ Object
6 7 8 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 6 def readme template 'README.md.erb', 'README.md' end |
#rollbar ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 97 def generate 'rollbar' gsub_file 'config/initializers/rollbar.rb', 'if Rails.env.test?', 'if Rails.env.test? || Rails.env.development?' copy_file 'config/initializers/mobile_workflow_rollbar.rb' gsub_file 'app/jobs/application_job.rb', 'class ApplicationJob < ActiveJob::Base', "class ApplicationJob < ActiveJob::Base\n include Rollbar::ActiveJob\n" end |
#rspec_generator ⇒ Object
19 20 21 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 19 def rspec_generator generate 'rspec:install' end |
#rubocop ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 82 def rubocop copy_file '.rubocop.yml' command = 'rubocop --auto-gen-config' puts "Running: #{command}" output = `#{command}` puts "Output: #{output}" end |
#s3_backend(region) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 110 def s3_backend(region) @region = region aws_backend.create! aws_backend.write_env if [:heroku] heroku_backend.sync_dotenv sleep 10 # Wait for the server to restart aws_backend.create_topic_subscription(heroku_backend.notifications_endpoint) elsif [:dokku] dokku_backend.sync_dotenv aws_backend.create_topic_subscription(dokku_backend.notifications_endpoint) end end |
#simplecov ⇒ Object
91 92 93 94 95 |
# File 'lib/mobile_workflow/cli/app_builder.rb', line 91 def simplecov append_to_file 'spec/rails_helper.rb', "\n# Config for Test Coverage\nrequire 'simplecov'\nSimpleCov.start\nSimpleCov.minimum_coverage 80\n" append_to_file '.gitignore', "\n# Ignore test coverage reports\n/coverage\n" end |