# require "rails/generators" require "rails/generators/rails/app/app_generator" require_relative "app_builder" module Rsg # AppGenerator is the entrypoint for generation of new apps which builds on # top of the core `rails new` command class AppGenerator < Rails::Generators::AppGenerator include Generators::Actions hide! class_option :version, type: :boolean, aliases: "-v", group: :rsg, desc: "Show RSG version number and quit" class_option :help, type: :boolean, aliases: "-h", group: :rsg, desc: "Show this help message and quit" class_option :path, type: :string, default: nil, desc: "Path to the RSG gem" class_option :template, aliases: "-m", type: :string, default: "rsg-default", desc: "Path to some application template (can be a filesystem path or URL)" # --minimal might take care of some of these, but not all, we change all defaults here regardless since # --minimal is subject to change with new releases. We also hide them all, and re-add things as necessary # based on user input as generators kick in class_option :skip_action_cable, type: :boolean, default: true, desc: "Skip Action Cable files", hide: true class_option :skip_action_mailbox, type: :boolean, default: true, desc: "Skip Action Mailbox files", hide: true class_option :skip_action_mailer, type: :boolean, default: true, desc: "Skip Action Mailer files", hide: true class_option :skip_action_text, type: :boolean, default: true, desc: "Skip Action Text files", hide: true class_option :skip_active_job, type: :boolean, default: true, desc: "Skip Active Job files", hide: true class_option :skip_active_record, type: :boolean, default: true, desc: "Skip Active Record files", hide: true class_option :skip_active_storage, type: :boolean, default: true, desc: "Skip Active Storage files", hide: true class_option :skip_bundle, type: :boolean, default: true, desc: "Don't run bundle install", hide: true class_option :skip_javascript, type: :boolean, default: true, desc: "Skip JavaScript files", hide: true class_option :skip_jbuilder, type: :boolean, default: true, desc: "Skip jbuilder gem", hide: true class_option :skip_keeps, type: :boolean, default: true, desc: "Skip Puma", hide: true class_option :skip_spring, type: :boolean, default: true, desc: "Don't install Spring application preloader", hide: true class_option :skip_sprockets, type: :boolean, default: true, desc: "Skip Sprockets files", hide: true class_option :skip_system_test, type: :boolean, default: true, desc: "Skip system test files", hide: true class_option :skip_test, type: :boolean, default: true, desc: "Skip Test Unit", hide: true class_option :skip_turbolinks, type: :boolean, default: true, desc: "Skip turbolinks gem", hide: true class_option :skip_webpack_install, type: :boolean, default: true, desc: "Don't run webpack install", hide: true # Hide other flags, but leave their defaults untouched class_option :database, type: :string, default: "sqlite3", desc: "Configure for selected database (options: #{DATABASES.join("/")})", hide: true class_option :dev, type: :boolean, default: false, desc: "Set up the application with Gemfile pointing to your Rails checkout", hide: true class_option :edge, type: :boolean, default: false, desc: "Set up the application with Gemfile pointing to Rails repository", hide: true class_option :master, type: :boolean, default: false, desc: "Preconfigure a minimal rails app", hide: true class_option :minimal, type: :boolean, default: false, desc: "Preconfigure a minimal rails app", hide: true class_option :skip_bootsnap, type: :boolean, default: false, desc: "Skip bootsnap gem", hide: true class_option :skip_collision_check, type: :boolean, default: false, desc: "Skip collision check", hide: true class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile", hide: true class_option :skip_git, type: :boolean, default: false, desc: "Skip .gitignore file", hide: true class_option :skip_listen, type: :boolean, default: false, desc: "Don't generate configuration that depends on the listen gem", hide: true class_option :skip_namespace, type: :boolean, default: false, desc: "Skip namespace (affects only isolated engines)", hide: true class_option :skip_puma, type: :boolean, default: false, desc: "Skip Puma related files", hide: true class_option :webpack, type: :string, desc: "Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus)", hide: true def self.banner "rsg #{arguments.map(&:usage).join(" ")} [options]" end def self.source_paths @__source_paths ||= [ Rails::Generators::AppGenerator.source_root, Pathname.new(__FILE__).dirname.join("templates").expand_path ] end def set_default_accessors! bundled_template = Rsg.lookup_app_template(options[:template]) super self.rails_template = bundled_template if bundled_template end protected # rubocop:disable Naming/AccessorMethodName def get_builder_class Rsg::AppBuilder end # rubocop:enable Naming/AccessorMethodName end end