Class: ReactManifest::ApplicationMigrator

Inherits:
Object
  • Object
show all
Defined in:
lib/react_manifest/application_migrator.rb

Overview

Rewrites application*.js files to remove UX/app code requires, keeping only vendor lib requires.

Safety:

- Creates a .bak backup before any write; aborts if backup fails
- Dry-run mode: prints what would change, writes nothing
- Never removes :vendor or :passthrough lines
- Adds a managed-by comment at the top

Constant Summary collapse

MANAGED_COMMENT =
<<~JS.freeze
  // Vendor libraries — loaded on every page.
  // React app code is now served per-controller via react_bundle_tag.
  // Managed by react-manifest-rails — do not add require_tree.
JS

Instance Method Summary collapse

Constructor Details

#initialize(config = ReactManifest.configuration) ⇒ ApplicationMigrator

Returns a new instance of ApplicationMigrator.



17
18
19
20
# File 'lib/react_manifest/application_migrator.rb', line 17

def initialize(config = ReactManifest.configuration)
  @config   = config
  @analyzer = ApplicationAnalyzer.new(config)
end

Instance Method Details

#migrate!Object

Migrate all application*.js files. Returns array of status: hashes.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/react_manifest/application_migrator.rb', line 23

def migrate!
  results = @analyzer.analyze

  if results.empty?
    $stdout.puts "[ReactManifest] No application*.js files found to migrate."
    return []
  end

  results.map do |result|
    if result.clean?
      $stdout.puts "[ReactManifest] #{short(result.file)} — already clean, skipping."
      { file: result.file, status: :already_clean }
    else
      rewrite(result)
    end
  end
end