Class: ReactManifest::Configuration
- Inherits:
-
Object
- Object
- ReactManifest::Configuration
- Defined in:
- lib/react_manifest/configuration.rb
Overview
Holds all configuration for the gem. Obtain via configure.
Instance Attribute Summary collapse
-
#always_include ⇒ Object
Bundles always prepended by react_bundle_tag (e.g. ["ux_main"]).
-
#app_dir ⇒ Object
Subdir within ux_root that contains per-controller JSX.
-
#dry_run ⇒ Object
Preview mode: print what would change, write nothing.
-
#exclude_paths ⇒ Object
Path segments to exclude while scanning files under ux_root.
-
#extensions ⇒ Object
File extensions to scan (default: js and jsx; add "ts", "tsx" for TypeScript).
-
#external_providers ⇒ Object
Explicit symbol-to-require-path mapping for external globals.
-
#external_roots ⇒ Object
Extra root directories (absolute or relative to Rails.root) to scan for symbol definitions outside of ux_root.
-
#ignore ⇒ Object
Controller directory names directly under ux_root/app_dir to skip entirely.
-
#isolated_app_dirs ⇒ Object
Controller directory names (under ux_root/app_dir) whose files must never be inlined into any OTHER controller's manifest via inferred cross-app dependency detection.
-
#manifest_subdir ⇒ Object
Subdirectory under output_dir that holds generated ux_*.js manifests.
-
#output_dir ⇒ Object
Where generated ux_*.js manifests are written (relative to Rails.root).
-
#shared_bundle ⇒ Object
Bundle name for auto-generated shared bundle (all non-app/ dirs).
-
#size_threshold_kb ⇒ Object
Warn if a bundle exceeds this size in KB (0 = disabled).
-
#stdout_logging ⇒ Object
Also print ReactManifest status lines directly to stdout, in addition to Rails.logger (which always receives them regardless of this flag).
-
#ux_root ⇒ Object
Root of the ux/ tree to scan (relative to Rails.root).
-
#verbose ⇒ Object
Extra diagnostic logging (summary lines and richer error context).
Instance Method Summary collapse
- #abs_app_dir ⇒ Object
- #abs_manifest_dir ⇒ Object
- #abs_output_dir ⇒ Object
-
#abs_ux_root ⇒ Object
Absolute path helpers (requires Rails.root to be set).
- #cache_key ⇒ Object
- #dry_run? ⇒ Boolean
- #excluded_path?(abs_path) ⇒ Boolean
-
#extensions_glob ⇒ Object
Glob fragment used by Dir.glob, e.g.
-
#extensions_pattern ⇒ Object
Regexp used by the file watcher to filter events, e.g.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #normalized_manifest_subdir ⇒ Object
- #stdout_logging? ⇒ Boolean
- #verbose? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/react_manifest/configuration.rb', line 99 def initialize @ux_root = "app/assets/javascripts/ux" @app_dir = "app" @output_dir = "app/assets/javascripts" @manifest_subdir = "ux_manifests" @shared_bundle = "ux_shared" @always_include = [] @ignore = [] @isolated_app_dirs = [] @exclude_paths = %w[react react_dev vendor] @size_threshold_kb = 500 @extensions = %w[js jsx] @dry_run = false @verbose = false @stdout_logging = false @external_providers = {} @external_roots = [] end |
Instance Attribute Details
#always_include ⇒ Object
Bundles always prepended by react_bundle_tag (e.g. ["ux_main"])
28 29 30 |
# File 'lib/react_manifest/configuration.rb', line 28 def always_include @always_include end |
#app_dir ⇒ Object
Subdir within ux_root that contains per-controller JSX
15 16 17 |
# File 'lib/react_manifest/configuration.rb', line 15 def app_dir @app_dir end |
#dry_run ⇒ Object
Preview mode: print what would change, write nothing. Applies anywhere generation runs (manual task, boot sync, watcher).
64 65 66 |
# File 'lib/react_manifest/configuration.rb', line 64 def dry_run @dry_run end |
#exclude_paths ⇒ Object
Path segments to exclude while scanning files under ux_root. This is segment matching (not full path matching), so "vendor" excludes ux/vendor/foo.js and ux/app/users/vendor/bar.jsx, but not ux/vendor_custom/x.js. These are not application.js includes; they only affect ux tree scanning.
54 55 56 |
# File 'lib/react_manifest/configuration.rb', line 54 def exclude_paths @exclude_paths end |
#extensions ⇒ Object
File extensions to scan (default: js and jsx; add "ts", "tsx" for TypeScript)
60 61 62 |
# File 'lib/react_manifest/configuration.rb', line 60 def extensions @extensions end |
#external_providers ⇒ Object
Explicit symbol-to-require-path mapping for external globals. Use for third-party libraries that export a PascalCase or camelCase symbol not located inside ux_root (e.g. MiniSearch, Chart.js wrappers).
Keys are exact symbol names (case-sensitive); values are the Sprockets require path that should be emitted into the controller manifest.
Example:
config.external_providers = { "MiniSearch" => "mini-search", "axios" => "vendor/axios" }
87 88 89 |
# File 'lib/react_manifest/configuration.rb', line 87 def external_providers @external_providers end |
#external_roots ⇒ Object
Extra root directories (absolute or relative to Rails.root) to scan for
symbol definitions outside of ux_root. Symbols found here are added to
the shared symbol index and will trigger an include when used by a
controller. Empty by default; files in these dirs are subject to the
same exclude_paths and extensions filters.
Example:
config.external_roots = ["app/assets/javascripts/vendor_components"]
97 98 99 |
# File 'lib/react_manifest/configuration.rb', line 97 def external_roots @external_roots end |
#ignore ⇒ Object
Controller directory names directly under ux_root/app_dir to skip entirely.
Example: ignore = ["admin"] skips ux/app/admin/* when building ux_
32 33 34 |
# File 'lib/react_manifest/configuration.rb', line 32 def ignore @ignore end |
#isolated_app_dirs ⇒ Object
Controller directory names (under ux_root/app_dir) whose files must never
be inlined into any OTHER controller's manifest via inferred cross-app
dependency detection. Their own ux_
Symbol usage detection is pure regex (no AST), so a generic component name can collide with an unrelated word appearing as plain JSX text elsewhere (e.g. a "Show" component vs a "Show More" button label in a completely different controller) and get wrongly inlined everywhere. Use this for self-contained dirs (e.g. a page-builder tool bundling its own vendored library) that should truly never leak into other bundles.
Example:
config.isolated_app_dirs = ["rvb"]
48 49 50 |
# File 'lib/react_manifest/configuration.rb', line 48 def isolated_app_dirs @isolated_app_dirs end |
#manifest_subdir ⇒ Object
Subdirectory under output_dir that holds generated ux_*.js manifests. Keeping generated files out of output_dir root avoids clutter.
22 23 24 |
# File 'lib/react_manifest/configuration.rb', line 22 def manifest_subdir @manifest_subdir end |
#output_dir ⇒ Object
Where generated ux_*.js manifests are written (relative to Rails.root)
18 19 20 |
# File 'lib/react_manifest/configuration.rb', line 18 def output_dir @output_dir end |
#shared_bundle ⇒ Object
Bundle name for auto-generated shared bundle (all non-app/ dirs)
25 26 27 |
# File 'lib/react_manifest/configuration.rb', line 25 def shared_bundle @shared_bundle end |
#size_threshold_kb ⇒ Object
Warn if a bundle exceeds this size in KB (0 = disabled)
57 58 59 |
# File 'lib/react_manifest/configuration.rb', line 57 def size_threshold_kb @size_threshold_kb end |
#stdout_logging ⇒ Object
Also print ReactManifest status lines directly to stdout, in addition to Rails.logger (which always receives them regardless of this flag). Off by default: many development setups already have Rails.logger broadcast to the terminal (RAILS_LOG_TO_STDOUT, Docker/Foreman, etc.), and enabling this on top of that prints every line twice. Turn it on only if your Rails.logger does NOT already surface output in your terminal and you want a guaranteed visible line per event.
76 77 78 |
# File 'lib/react_manifest/configuration.rb', line 76 def stdout_logging @stdout_logging end |
#ux_root ⇒ Object
Root of the ux/ tree to scan (relative to Rails.root)
12 13 14 |
# File 'lib/react_manifest/configuration.rb', line 12 def ux_root @ux_root end |
#verbose ⇒ Object
Extra diagnostic logging (summary lines and richer error context).
67 68 69 |
# File 'lib/react_manifest/configuration.rb', line 67 def verbose @verbose end |
Instance Method Details
#abs_app_dir ⇒ Object
145 146 147 |
# File 'lib/react_manifest/configuration.rb', line 145 def abs_app_dir File.join(abs_ux_root, app_dir) end |
#abs_manifest_dir ⇒ Object
153 154 155 156 157 158 |
# File 'lib/react_manifest/configuration.rb', line 153 def abs_manifest_dir subdir = normalized_manifest_subdir return abs_output_dir if subdir.empty? File.join(abs_output_dir, subdir) end |
#abs_output_dir ⇒ Object
149 150 151 |
# File 'lib/react_manifest/configuration.rb', line 149 def abs_output_dir Rails.root.join(output_dir).to_s end |
#abs_ux_root ⇒ Object
Absolute path helpers (requires Rails.root to be set)
141 142 143 |
# File 'lib/react_manifest/configuration.rb', line 141 def abs_ux_root Rails.root.join(ux_root).to_s end |
#cache_key ⇒ Object
169 170 171 |
# File 'lib/react_manifest/configuration.rb', line 169 def cache_key [ux_root, app_dir, extensions, always_include, exclude_paths, external_providers, isolated_app_dirs].hash end |
#dry_run? ⇒ Boolean
118 119 120 |
# File 'lib/react_manifest/configuration.rb', line 118 def dry_run? !!@dry_run end |
#excluded_path?(abs_path) ⇒ Boolean
160 161 162 163 |
# File 'lib/react_manifest/configuration.rb', line 160 def excluded_path?(abs_path) parts = abs_path.split(File::SEPARATOR) exclude_paths.any? { |ep| parts.include?(ep) } end |
#extensions_glob ⇒ Object
Glob fragment used by Dir.glob, e.g. ".js,jsx" or ".js,jsx,ts,tsx"
131 132 133 |
# File 'lib/react_manifest/configuration.rb', line 131 def extensions_glob "*.{#{extensions.join(',')}}" end |
#extensions_pattern ⇒ Object
Regexp used by the file watcher to filter events, e.g. /.(js|jsx)$/
136 137 138 |
# File 'lib/react_manifest/configuration.rb', line 136 def extensions_pattern Regexp.new("\\.(#{extensions.map { |e| Regexp.escape(e) }.join('|')})$") end |
#normalized_manifest_subdir ⇒ Object
165 166 167 |
# File 'lib/react_manifest/configuration.rb', line 165 def normalized_manifest_subdir manifest_subdir.to_s.gsub(%r{\A/+|/+\z}, "") end |
#stdout_logging? ⇒ Boolean
126 127 128 |
# File 'lib/react_manifest/configuration.rb', line 126 def stdout_logging? !!@stdout_logging end |
#verbose? ⇒ Boolean
122 123 124 |
# File 'lib/react_manifest/configuration.rb', line 122 def verbose? !!@verbose end |