Class: ReactManifest::Configuration

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

Overview

Holds all configuration for the gem. Obtain via configure.

Examples:

ReactManifest.configure do |c|
  c.ux_root           = "app/assets/javascripts/ux"
  c.extensions        = %w[js jsx ts tsx]
  c.size_threshold_kb = 1000
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/react_manifest/configuration.rb', line 57

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            = []
  @exclude_paths     = %w[react react_dev vendor]
  @size_threshold_kb = 500
  @extensions        = %w[js jsx]
  @dry_run           = false
  @verbose           = false
  @stdout_logging    = true
end

Instance Attribute Details

#always_includeObject

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_dirObject

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_runObject

Preview mode: print what would change, write nothing. Applies anywhere generation runs (manual task, boot sync, watcher).



48
49
50
# File 'lib/react_manifest/configuration.rb', line 48

def dry_run
  @dry_run
end

#exclude_pathsObject

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.



38
39
40
# File 'lib/react_manifest/configuration.rb', line 38

def exclude_paths
  @exclude_paths
end

#extensionsObject

File extensions to scan (default: js and jsx; add “ts”, “tsx” for TypeScript)



44
45
46
# File 'lib/react_manifest/configuration.rb', line 44

def extensions
  @extensions
end

#ignoreObject

Controller directory names directly under ux_root/app_dir to skip entirely. Example: ignore = [“admin”] skips ux/app/admin/* when building ux_<controller>.js.



32
33
34
# File 'lib/react_manifest/configuration.rb', line 32

def ignore
  @ignore
end

#manifest_subdirObject

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_dirObject

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_bundleObject

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_kbObject

Warn if a bundle exceeds this size in KB (0 = disabled)



41
42
43
# File 'lib/react_manifest/configuration.rb', line 41

def size_threshold_kb
  @size_threshold_kb
end

#stdout_loggingObject

Emit ReactManifest status lines to stdout in development. Independent from Rails.logger output.



55
56
57
# File 'lib/react_manifest/configuration.rb', line 55

def stdout_logging
  @stdout_logging
end

#ux_rootObject

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

#verboseObject

Extra diagnostic logging (summary lines and richer error context).



51
52
53
# File 'lib/react_manifest/configuration.rb', line 51

def verbose
  @verbose
end

Instance Method Details

#abs_app_dirObject



100
101
102
# File 'lib/react_manifest/configuration.rb', line 100

def abs_app_dir
  File.join(abs_ux_root, app_dir)
end

#abs_manifest_dirObject



108
109
110
111
112
113
# File 'lib/react_manifest/configuration.rb', line 108

def abs_manifest_dir
  subdir = normalized_manifest_subdir
  return abs_output_dir if subdir.empty?

  File.join(abs_output_dir, subdir)
end

#abs_output_dirObject



104
105
106
# File 'lib/react_manifest/configuration.rb', line 104

def abs_output_dir
  Rails.root.join(output_dir).to_s
end

#abs_ux_rootObject

Absolute path helpers (requires Rails.root to be set)



96
97
98
# File 'lib/react_manifest/configuration.rb', line 96

def abs_ux_root
  Rails.root.join(ux_root).to_s
end

#dry_run?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/react_manifest/configuration.rb', line 73

def dry_run?
  !!@dry_run
end

#extensions_globObject

Glob fragment used by Dir.glob, e.g. “*.js,jsx” or “*.js,jsx,ts,tsx”



86
87
88
# File 'lib/react_manifest/configuration.rb', line 86

def extensions_glob
  "*.{#{extensions.join(',')}}"
end

#extensions_patternObject

Regexp used by the file watcher to filter events, e.g. /.(js|jsx)$/



91
92
93
# File 'lib/react_manifest/configuration.rb', line 91

def extensions_pattern
  Regexp.new("\\.(#{extensions.map { |e| Regexp.escape(e) }.join('|')})$")
end

#normalized_manifest_subdirObject



115
116
117
# File 'lib/react_manifest/configuration.rb', line 115

def normalized_manifest_subdir
  manifest_subdir.to_s.gsub(%r{\A/+|/+\z}, "")
end

#stdout_logging?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/react_manifest/configuration.rb', line 81

def stdout_logging?
  !!@stdout_logging
end

#verbose?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/react_manifest/configuration.rb', line 77

def verbose?
  !!@verbose
end