Class: Kowl::Overrides::AppGenerator
- Inherits:
-
Rails::Generators::AppGenerator
- Object
- Rails::Generators::AppGenerator
- Kowl::Overrides::AppGenerator
- Defined in:
- lib/kowl/generators/overrides/app_generator.rb
Constant Summary collapse
- WEBPACKS =
If the person wants to use webpack in their application (vuew, react etc)
%w[react vue angular elm stimulus].freeze
Instance Method Summary collapse
-
#add_uuids_to_migrations ⇒ Object
If UUIDs are to be used, add id: :uuid to all migrations.
-
#initial_commit ⇒ Object
Create a git initial commit.
-
#install_webpack_assets ⇒ Object
Rails6 has issues when genereting a new app using Oracle/sqlserver right away, this ensures webpack is installed if it previously failed because of the missing ruby-oci8/sqlserver gems In addition his also prevents a Psych error as the application is generated.
-
#kowl_generators ⇒ Object
Begin calling all the Kowl application generators to override the default rails application based on the options supplied.
-
#remove_sqlite_yaml ⇒ Object
While generating the application the config/database.yml is defaulted to using sqlite3.
-
#run_after_bundle_callbacks ⇒ Object
Used with Rails6 v6, because this has the application generate.
-
#setup_spring ⇒ Object
Setup spring for the application unless specified otherwise.
-
#setup_staging ⇒ Object
Setup a staging envirnment for application config and webpacker.
Methods included from Docker
#alpine_docker_dependencies, #app_js_volumes, #app_volumes, #db_volumes, #debian_database_dependencies, #debian_docker_dependencies, #docker_app_command, #docker_compose_database_string, #docker_databases, #docker_depends_on, #docker_port_watcher, #docker_redis_service, #docker_sidekiq_service, #docker_variables, #docker_volumes, #docker_webpacker_service, #dockerfile_database_args, #dockerfile_migration_snip, #js_volumes, #mysql_volumes, #postgresql_volumes, #redis_volumes
Methods included from Actions
#add_extension_routes, #add_package, #append_to_file, #database_route, #dev_config, #dup_file, #file_exists?, #mailer_gems, #mailer_route, #mk_dir, #move_file, #pry_gems, #rails_cmd, #remove_dir, #remove_file, #remove_gem, #replace_string_in_file, #robocop_test_engine, #sidekiq_route, #template_linter_gems
Instance Method Details
#add_uuids_to_migrations ⇒ Object
If UUIDs are to be used, add id: :uuid to all migrations
206 207 208 209 210 211 212 213 214 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 206 def add_uuids_to_migrations return nil unless [:database] == 'postgresql' && [:uuid] Dir.foreach('db/migrate/') do |migration| next if %w[. ..].include?(migration) || migration.match(/_enable_pgcrypto_extension.rb$/) inject_into_file("db/migrate/#{migration}", ', id: :uuid', after: /create_table \:[a-z\_]+/) end end |
#initial_commit ⇒ Object
Create a git initial commit
199 200 201 202 203 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 199 def initial_commit git :init git add: '.' git commit: "-aqm 'Initial Commit' --quiet" end |
#install_webpack_assets ⇒ Object
Rails6 has issues when genereting a new app using Oracle/sqlserver right away, this ensures webpack is installed if it previously failed because of the missing ruby-oci8/sqlserver gems In addition his also prevents a Psych error as the application is generated
236 237 238 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 236 def install_webpack_assets rails_command('webpacker:install') unless [:skip_javascript] end |
#kowl_generators ⇒ Object
Begin calling all the Kowl application generators to override the default rails application based on the options supplied
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 127 def kowl_generators build :replace_gemfile build :procfile bundle_command 'install --jobs=4 --retry=3 --quiet' bundle_command 'exec spring stop' unless [:skip_spring] invoke :install_webpack_assets invoke :setup_staging # Ran afterwards webpack is setup for oracle, because it also createas a staging webpacker file generate("kowl:config --database=#{[:database]} --encrypt=#{[:encrypt]} --framework=#{[:framework]} --noauth=#{[:noauth]} --skip_docker=#{[:skip_docker]} --skip_erd=#{[:skip_erd]} --skip_pagination=#{[:skip_pagination]} --skip_sidekiq=#{[:skip_sidekiq]} --skip_tests=#{[:skip_tests]} --template_engine=#{[:template_engine]} --simpleform=#{[:simpleform]} --test_engine=#{[:test_engine]} --uuid=#{[:uuid]}") generate('kowl:uuid') if [:database] == 'postgresql' && [:uuid] generate("kowl:dotfiles --database=#{[:database]} --encrypt=#{[:encrypt]} --skip_docker=#{[:skip_docker]} --skip_erd=#{[:skip_erd]} --skip_javascript=#{[:skip_javascript]} --skip_mailer=#{[:skip_mailer]} --skip_pry=#{[:skip_pry]} --skip_sidekiq=#{[:skip_sidekiq]} --skip_tests=#{[:skip_tests]} --test_engine=#{[:test_engine]} --template_engine=#{[:template_engine]} ") generate("kowl:assets --framework=#{[:framework]} --noauth=#{[:noauth]} --skip_javascript=#{[:skip_javascript]} --skip_mailer=#{[:skip_mailer]} --skip_turbolinks=#{[:skip_turbolinks]}") generate("kowl:views_and_helpers --framework=#{[:framework]} --noauth=#{[:noauth]} --simpleform=#{[:simpleform]} --skip_javascript=#{[:skip_javascript]} --skip_pagination=#{[:skip_pagination]} --skip_turbolinks=#{[:skip_turbolinks]} --template_engine=#{[:template_engine]}") generate("kowl:users_and_auth --database=#{[:database]} --encrypt=#{[:encrypt]} --framework=#{[:framework]} --skip_javascript=#{[:skip_javascript]} --skip_mailer=#{[:skip_mailer]} --skip_pagination=#{[:skip_pagination]} --skip_sidekiq=#{[:skip_sidekiq]} --template_engine=#{[:template_engine]}") unless [:noauth] # tests are generated after users, because devise migrations tries to create empty minitest and rspec migration tests generate("kowl:test --noauth=#{[:noauth]} --test_engine=#{[:test_engine]}") unless [:test_engine] == :none || [:skip_tests] generate('kowl:staging') unless [:database] == 'sqlite3' generate("kowl:controller --noauth=#{[:noauth]}") generate("kowl:database --database=#{[:database]} --noauth=#{[:noauth]}") generate("kowl:action --database=#{[:database]} --simpleform=#{[:simpleform]} --skip_javascript=#{[:skip_javascript]}") generate("kowl:mailer --noauth=#{[:noauth]} --mailer=#{[:mailer]}") unless [:skip_mailer] generate("kowl:sidekiq --database=#{[:database]} --noauth=#{[:noauth]}") unless [:skip_sidekiq] generate('kowl:misc') # Generator misc application directores such as serializers, services, workers, etc. generate("kowl:decorators --noauth=#{[:noauth]}") generate("kowl:text_files --framework=#{[:framework]} --noauth=#{[:noauth]}") generate("kowl:pages --framework=#{[:framework]} --noauth=#{[:noauth]} --template_engine=#{[:template_engine]}") # Generate welcome pages and routes for the application generate("kowl:routes --database=#{[:database]} --noauth=#{[:noauth]} --skip_mailer=#{[:skip_mailer]} --skip_sidekiq=#{[:skip_sidekiq]}") generate('kowl:libs') # Generate admin dashboard if user authentication is enabled generate("kowl:docker --database=#{[:database]} --docker_distro=#{[:docker_distro]} --encrypt=#{[:encrypt]} --skip_erd=#{[:skip_erd]} --skip_javascript=#{[:skip_javascript]} --skip_sidekiq=#{[:skip_sidekiq]}") unless [:skip_docker] rake 'db:migrate' unless ([:database] == 'postgresql' && [:uuid]) || [:noauth] generate("kowl:admin --database=#{[:database]} --skip_javascript=#{[:skip_javascript]} --skip_turbolinks=#{[:skip_turbolinks]} --uuid=#{[:uuid]} ") unless [:noauth] invoke :add_uuids_to_migrations if [:database] == 'postgresql' && [:uuid] invoke :remove_sqlite_yaml unless [:database] == 'sqlite3' invoke :setup_spring unless [:skip_spring] # Remove the kowl gem, it is initially required to run the rails generators # => Removing the gem removes the generators from application remove_gem('kowl') # This should be ran last, thus there will only be 1 commit when application is started # This is a method tather than a generate, because generations can't be called after the gem has been removed invoke :initial_commit unless [:skip_git] end |
#remove_sqlite_yaml ⇒ Object
While generating the application the config/database.yml is defaulted to using sqlite3.
This is because we can't run migrations, and various tasks without a valid database.yml
but this file should be remove and replace with the config/database[#{database_type}].yml file once the application is ready
219 220 221 222 223 224 225 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 219 def remove_sqlite_yaml return nil if [:database] == 'sqlite3' db_file = "config/database[#{[:database]}].yml" remove_file('config/database.yml') move_file(db_file, 'config/database.yml') end |
#run_after_bundle_callbacks ⇒ Object
Used with Rails6 v6, because this has the application generate.
> We want it after the applicaton config and assets are generated, otherwise it generates a large number of errors
117 118 119 120 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 117 def run_after_bundle_callbacks super invoke :kowl_generators unless [:skip_javascript] end |
#setup_spring ⇒ Object
Setup spring for the application unless specified otherwise
228 229 230 231 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 228 def setup_spring say 'Springifying binstubs' build :setup_spring unless [:skip_spring] end |
#setup_staging ⇒ Object
Setup a staging envirnment for application config and webpacker
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/kowl/generators/overrides/app_generator.rb', line 175 def setup_staging template 'config/environments/production.rb.tt', 'config/environments/staging.rb' # Enable displaying error messages in staging replace_string_in_file('config/environments/staging.rb', '^[\s]*?(config.consider_all_requests_local)[\s]*= false[\s]?$', ' config.consider_all_requests_local = true') # create a webpacker staging environment return if [:skip_javascript] dup_file('config/webpack/production.js', 'config/webpack/staging.js') webpacker_str = <<~STAGING staging: <<: *default # Production depends on precompilation of packs prior to booting for performance. compile: false # Extract and emit a css file extract_css: true # Cache manifest.json for performance cache_manifest: true STAGING append_to_file('config/webpacker.yml', "\n#{webpacker_str}") end |