require "jobshop/dummy_app" require "generators/jobshop/app/app_generator" module Jobshop class DummyBuilder < Jobshop::AppBuilder def readme # Do not generate README.md end # Comment out username, password from production group. def config_database_yml gsub_file "config/database.yml", /^([ ]*[^#])(username: .*|password: .*)$/, '\1# \2' end # The db/migrate folder isn't created automatically. def db_migrate unless Dir.exist?("db/migrate") say_status :create, "db/migrate" Dir.mkdir("db/migrate") end end def expose_mailer_previews # Mailer previews don't really play nice with Engines so in the dummy app we # create an initializer to expose them properly. initializer "jobshop_expose_mailer_previews.rb", <<~INITIALIZER if Rails.env.development? || Rails.env.test? Rails.application.configure do config.action_mailer.preview_path = "\#{Jobshop::Engine.root}/spec/mailers" end end INITIALIZER end def localhost_tld_length # This allows us to easily use the localhost hostname in development. initializer "jobshop_tld_length.rb", <<~INITIALIZER if Rails.env.development? || Rails.env.test? Rails.application.configure do config.action_dispatch.tld_length = 0 end end INITIALIZER end end module Generators class DummyGenerator < Jobshop::Generators::AppGenerator def self.source_root File.expand_path("templates", __dir__) end def self.source_paths Array(super) | [ Jobshop::Generators::DummyGenerator.source_root ] end hide! class_options[:skip_bundle].instance_variable_set(:@default, "true") class_options[:skip_gemfile].instance_variable_set(:@default, "true") class_options[:skip_git].instance_variable_set(:@default, "true") class_options[:skip_listen].instance_variable_set(:@default, "true") class_options[:skip_test].instance_variable_set(:@default, "true") def initialize(*) DummyApp.destroy! if Jobshop::DummyApp.exist? super end def self.banner "jobshop dummy [options]" end def create_boot_file template "config/boot.rb.tt" end def finish_template build :config_database_yml build :db_migrate build :expose_mailer_previews build :localhost_tld_length super end def run_bundle super bundle_command("exec rails db:drop:all") bundle_command("exec rails db:create") bundle_command("exec rails db:migrate") bundle_command("exec rails db:test:load_schema") bundle_command("exec rails g jobshop:team") end protected def get_builder_class Jobshop::DummyBuilder end end end end