Skip to content

Commit

Permalink
Merge 02288ba into cb158f1
Browse files Browse the repository at this point in the history
  • Loading branch information
Spone committed Mar 26, 2019
2 parents cb158f1 + 02288ba commit 5b18152
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,21 @@

## Upcoming release

**Breaking changes:**
- It's now recommended to use eager loading to prevent `uninitialized component` issues
(see [#121](https://github.com/komposable/komponent/issues/121) for background).

The install generator has been updated. When upgrading, please make sure you replace:

config.autoload_paths << config.root.join("app/frontend/components")

with

config.paths.add "frontend/components", eager_load: true

**Enhancements:**
- Refactoring to use `Utils` in `InstallGenerator` and prevent code duplication

## v3.0.0.beta1 (2019-02-28)

**Breaking changes:**
Expand Down
46 changes: 11 additions & 35 deletions lib/generators/komponent/install_generator.rb
@@ -1,24 +1,27 @@
# frozen_string_literal: true

require 'rails/generators'
require File.expand_path('../utils', __FILE__)

module Komponent
module Generators
class InstallGenerator < Rails::Generators::Base
include Utils

class_option :stimulus, type: :boolean, default: false
source_root File.join(File.dirname(__FILE__), "templates")

def check_webpacker_installed
return if File.directory?(komponent_directory)
return if komponent_already_installed?
installed = File.exist?(webpacker_configuration_file)
raise Thor::Error, dependencies_not_met_error_message unless installed
end

def create_komponent_directory
empty_directory(komponent_directory)
empty_directory(komponent_root_directory)
directory(
javascript_directory,
komponent_directory,
komponent_root_directory,
recursive: true,
)
end
Expand All @@ -27,7 +30,7 @@ def alter_webpacker_configuration
gsub_file(
webpacker_configuration_file,
/source_path: app\/javascript$/,
"source_path: #{komponent_directory}",
"source_path: #{komponent_root_directory}",
)
end

Expand All @@ -44,8 +47,8 @@ def create_stimulus_file
end

def append_to_application_configuration
application "config.autoload_paths << config.root.join('#{komponent_directory}/components')"
application "config.i18n.load_path += Dir[config.root.join('#{komponent_directory}/components/**/*.*.yml')]"
application "config.paths.add '#{relative_path_from_rails}/components', eager_load: true"
application "config.i18n.load_path += Dir[config.root.join('#{komponent_root_directory}/components/**/*.*.yml')]"
end

def append_to_application_pack
Expand Down Expand Up @@ -73,19 +76,11 @@ def stimulus_application_template
end

def stimulus_application_path
join(komponent_directory, "stimulus_application.js")
join(komponent_root_directory, "stimulus_application.js")
end

def application_pack_path
join(komponent_directory, "packs", "application.js")
end

def components_directory
join(komponent_directory, "components")
end

def komponent_directory
default_path
join(komponent_root_directory, "packs", "application.js")
end

def webpacker_configuration_file
Expand All @@ -105,27 +100,8 @@ def stimulus?
komponent_configuration[:stimulus]
end

def default_path
rails_configuration.komponent.root
end

private

def komponent_configuration
{
stimulus: nil,
locale: nil,
}.merge(app_generators.komponent)
end

def rails_configuration
Rails.application.config
end

def app_generators
rails_configuration.app_generators
end

def join(*paths)
File.expand_path(File.join(*paths), destination_root)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/komponent/engine.rb
Expand Up @@ -52,7 +52,7 @@ class Engine < Rails::Engine
end

initializer 'komponent.autoload', before: :set_autoload_paths do |app|
app.config.autoload_paths << Komponent::Engine.root.join('frontend')
app.config.paths.add app.config.komponent.root.to_s, eager_load: true
end
end
end

0 comments on commit 5b18152

Please sign in to comment.