Class: ReactManifest::Generator
- Inherits:
-
Object
- Object
- ReactManifest::Generator
- Defined in:
- lib/react_manifest/generator.rb
Overview
Generates all ux_*.js Sprockets manifest files.
Instantiate with a Configuration and call #run!:
ReactManifest::Generator.new(ReactManifest.configuration).run!
Returns an array of result hashes:
[{path: "/abs/path/ux_shared.js", status: :written}, ...]
Possible status values: :written, :unchanged, :skipped_pinned, :dry_run.
Generates:
ux_shared.js — requires all files from shared dirs (components/, hooks/, lib/, etc.)
ux_<ctrl>.js — one per controller subdir, requires ux_shared + controller files
All generated files carry the AUTO-GENERATED header and are idempotent (skips write if content unchanged). Writes are atomic (temp-file + rename) to avoid partial reads from concurrent processes.
Never touches application.js, application_dev.js, or files in exclude_paths.
Constant Summary collapse
- HEADER =
<<~JS.freeze // AUTO-GENERATED — DO NOT EDIT // react-manifest-rails %<version>s | %<timestamp>s // Run `rails react_manifest:generate` to regenerate. JS
Instance Method Summary collapse
-
#initialize(config = ReactManifest.configuration) ⇒ Generator
constructor
A new instance of Generator.
-
#run! ⇒ Object
Run full generation.
Constructor Details
#initialize(config = ReactManifest.configuration) ⇒ Generator
Returns a new instance of Generator.
33 34 35 36 |
# File 'lib/react_manifest/generator.rb', line 33 def initialize(config = ReactManifest.configuration) @config = config @classifier = TreeClassifier.new(config) end |
Instance Method Details
#run! ⇒ Object
Run full generation. Returns array of status: hashes.
All manifest content is built first (no filesystem writes), then written in a second pass so that a failure midway does not leave some bundles written and others stale/missing.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/react_manifest/generator.rb', line 43 def run! classification = @classifier.classify # Phase 1: build all content in memory — no I/O. manifests = [] manifests << build_shared(classification.shared_dirs) classification.controller_dirs.each { |ctrl| manifests << build_controller(ctrl) } migrate_legacy_manifests! # Phase 2: write — each write is atomic (tmp + rename). results = manifests.map { |m| write_manifest(m[:filename], m[:content]) } print_summary(results) if @config.verbose? results end |