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.



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/react_manifest/configuration.rb', line 44

def initialize
  @ux_root           = "app/assets/javascripts/ux"
  @app_dir           = "app"
  @output_dir        = "app/assets/javascripts"
  @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
end

Instance Attribute Details

#always_includeObject

Bundles always prepended by react_bundle_tag (e.g. [“ux_main”])



24
25
26
# File 'lib/react_manifest/configuration.rb', line 24

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

Print what would change, write nothing



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

def dry_run
  @dry_run
end

#exclude_pathsObject

Top-level dirs under output_dir to never scan (vendor libs, etc.)



30
31
32
# File 'lib/react_manifest/configuration.rb', line 30

def exclude_paths
  @exclude_paths
end

#extensionsObject

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



36
37
38
# File 'lib/react_manifest/configuration.rb', line 36

def extensions
  @extensions
end

#ignoreObject

Directories under app_dir to completely ignore



27
28
29
# File 'lib/react_manifest/configuration.rb', line 27

def ignore
  @ignore
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)



21
22
23
# File 'lib/react_manifest/configuration.rb', line 21

def shared_bundle
  @shared_bundle
end

#size_threshold_kbObject

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



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

def size_threshold_kb
  @size_threshold_kb
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 logging



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

def verbose
  @verbose
end

Instance Method Details

#abs_app_dirObject



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

def abs_app_dir
  File.join(abs_ux_root, app_dir)
end

#abs_output_dirObject



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

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

#abs_ux_rootObject

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



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

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

#dry_run?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/react_manifest/configuration.rb', line 58

def dry_run?
  !!@dry_run
end

#extensions_globObject

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



67
68
69
# File 'lib/react_manifest/configuration.rb', line 67

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

#extensions_patternObject

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



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

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

#verbose?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/react_manifest/configuration.rb', line 62

def verbose?
  !!@verbose
end