Class: RailsOnboarding::Generators::UpdateGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rails_onboarding/update_generator.rb

Overview

Re-copies the gem's Stimulus controllers into a bundler-based host app so that a gem upgrade actually reaches the app. esbuild/webpack/vite apps bundle their own copy of these controllers (see docs/ESBUILD_SETUP.md) rather than importing them from the engine the way importmap apps do, so the copy goes stale on every gem bump unless it is re-synced. This generator is that re-sync step - run it after updating the gem:

bin/rails generate rails_onboarding:update
bin/rails generate rails_onboarding:update --path some/other/dir

It copies the controllers flat into app/javascript/controllers (so Stimulus derives the flat identifiers the gem's views use - onboarding, tooltip, progress, ... - not prefixed rails-onboarding--* ones; see docs/ESBUILD_SETUP.md). The gem's application.js is intentionally NOT copied: it would clobber the host's own controllers/application.js entrypoint, and nothing imports it.

It overwrites the vendored controllers unconditionally (that is the point - they are meant to mirror the gem, so there is nothing to preserve), but is deliberately scoped to those files ONLY: it never touches your initializer, migrations, rails_onboarding_custom.css, or your onboarding step views. Importmap apps don't need it (they import the controllers from the gem).

Constant Summary collapse

VERSION_MARKER =

Written into the destination so the engine's boot-time staleness check (see Engine.warn_if_controllers_stale) can tell which gem version the copied controllers came from. Keep in sync with that constant.

".rails_onboarding_version".freeze

Instance Method Summary collapse

Instance Method Details

#copy_controllersObject



39
40
41
42
43
# File 'lib/generators/rails_onboarding/update_generator.rb', line 39

def copy_controllers
  controller_paths.each do |rel|
    copy_file rel, File.join(dest_dir, rel), force: true
  end
end


50
51
52
53
54
55
56
57
# File 'lib/generators/rails_onboarding/update_generator.rb', line 50

def print_next_steps
  say ""
  say "rails_onboarding: synced #{controller_paths.size} controller(s) to " \
      "#{dest_dir} (v#{RailsOnboarding::VERSION}).", :green
  say "Next, re-register the controllers and rebuild your JS bundle:", :yellow
  say "  bin/rails stimulus:manifest:update   # if you use stimulus-rails", :yellow
  say "  yarn build                           # or your bundler's build command", :yellow
end

#stamp_versionObject



45
46
47
48
# File 'lib/generators/rails_onboarding/update_generator.rb', line 45

def stamp_version
  create_file File.join(dest_dir, VERSION_MARKER),
              "#{RailsOnboarding::VERSION}\n", force: true
end