Class: Decidim::Webpacker::Configuration

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/lib/decidim/webpacker/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.


8
9
10
11
12
# File 'decidim-core/lib/decidim/webpacker/configuration.rb', line 8

def initialize
  @additional_paths = []
  @entrypoints = {}
  @stylesheet_imports = {}
end

Instance Attribute Details

#additional_pathsObject (readonly)

Returns the value of attribute additional_paths.


6
7
8
# File 'decidim-core/lib/decidim/webpacker/configuration.rb', line 6

def additional_paths
  @additional_paths
end

#entrypointsObject (readonly)

Returns the value of attribute entrypoints.


6
7
8
# File 'decidim-core/lib/decidim/webpacker/configuration.rb', line 6

def entrypoints
  @entrypoints
end

#stylesheet_importsObject (readonly)

Returns the value of attribute stylesheet_imports.


6
7
8
# File 'decidim-core/lib/decidim/webpacker/configuration.rb', line 6

def stylesheet_imports
  @stylesheet_imports
end

Instance Method Details

#configuration_fileObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'decidim-core/lib/decidim/webpacker/configuration.rb', line 14

def configuration_file
  # Before webpacker is installed, the original configuration file may not
  # be available yet.
  return unless File.exist?(original_configuration_file_path)
  return configuration_file_path if configurations_loaded?

  load_asset_configurations

  # Read the original configuration and append the paths
  config = YAML.load_file(original_configuration_file_path)
  default = config["default"] || {}
  all_additional_paths = default["additional_paths"] || []
  all_additional_paths += additional_paths
  all_stylesheet_imports = default["stylesheet_imports"] || {}
  all_stylesheet_imports.merge!(stylesheet_imports)
  all_entrypoints = default["entrypoints"] || {}
  all_entrypoints.merge!(entrypoints)
  config.each do |environment, env_config|
    config[environment] = env_config.merge(
      "additional_paths" => all_additional_paths,
      "entrypoints" => all_entrypoints,
      "stylesheet_imports" => all_stylesheet_imports
    )
  end

  # Write the runtime configuration and override the configuration
  File.write(configuration_file_path, config.to_yaml)

  self.configurations_loaded = true

  configuration_file_path
end