Skip to content
Permalink
Browse files

Fix install generator

  • Loading branch information...
florentferry committed Feb 2, 2019
1 parent c2853f3 commit d8f3be95bf937bfdf14fb1f351af2cd13d5289d9
@@ -7,6 +7,8 @@
/pkg/
/spec/reports/
/tmp/
/test/tmp

/fixtures/my_app/tmp
/fixtures/my_app/log

@@ -8,6 +8,7 @@ AllCops:
- fixtures/**/*
- Appraisals
- gemfiles/**/*
- test/tmp/**/*

Gemspec/OrderedDependencies:
Enabled: true

This file was deleted.

Oops, something went wrong.
@@ -199,11 +199,12 @@ DEPENDENCIES
coveralls
cucumber
komponent!
minitest (~> 5.8)
rails (~> 5.0)
rake (>= 11.1)
rubocop
simplecov
webpacker

BUNDLED WITH
1.16.0
1.16.4
@@ -36,4 +36,9 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "appraisal"
spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "minitest", "~> 5.8"
spec.add_development_dependency "rake", ">= 11.1"
spec.add_development_dependency "rubocop", "~> 0.52"
spec.add_development_dependency "simplecov"
end
@@ -1,51 +1,51 @@
# frozen_string_literal: true

require 'rails/generators'

module Komponent
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :stimulus, type: :boolean, default: false
source_root File.join(File.dirname(__FILE__), "templates")

def check_webpacker_dependency
return if komponent_already_installed?

unless File.exist?(webpacker_configuration_file) and File.directory?(webpacker_default_structure)
raise Thor::Error, dependencies_not_met_error_message
end
end

def create_root_directory
return if File.directory?(komponent_root_directory)

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

def modify_webpacker_configuration
gsub_file(webpacker_configuration_file, /source_path: app\/javascript$/, "source_path: #{relative_path_from_rails}")
def create_komponent_directory
empty_directory(komponent_directory)
directory(
javascript_directory,
komponent_directory,
recursive: true,
)
end

def move_webpacker_default_structure
return if File.directory?(komponent_root_directory)

run("mv #{webpacker_default_structure}/* #{komponent_root_directory}")
def alter_webpacker_configuration
gsub_file(
webpacker_configuration_file,
/source_path: app\/javascript$/,
"source_path: #{komponent_directory}",
)
end

def create_komponent_default_structure
return if File.exist?(components_directory.join("index.js"))

return if File.exist?(join(components_directory, "index.js"))
empty_directory(components_directory)
create_file(components_directory.join("index.js"))
create_file(join(components_directory, "index.js"))
end

def create_stimulus_file
return if File.exist?(stimulus_application_path)
return unless stimulus?

create_file(stimulus_application_path, stimulus_application_template)
end

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

def append_to_application_pack
@@ -73,31 +73,27 @@ def stimulus_application_template
end

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

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

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

def components_directory
Rails.root.join(komponent_root_directory, "components")
join(komponent_directory, "components")
end

def webpacker_configuration_file
Rails.root.join("config", "webpacker.yml")
def komponent_directory
default_path
end

def webpacker_default_structure
Rails.root.join("app", "javascript")
def webpacker_configuration_file
join("config", "webpacker.yml")
end

def komponent_already_installed?
File.directory?(relative_path_from_rails)
def javascript_directory
join("app", "javascript")
end

def dependencies_not_met_error_message
@@ -113,10 +109,6 @@ def default_path
rails_configuration.komponent.root
end

def relative_path_from_rails
default_path.relative_path_from(Rails.root)
end

private

def komponent_configuration
@@ -133,6 +125,10 @@ def rails_configuration
def app_generators
rails_configuration.app_generators
end

def join(*paths)
File.expand_path(File.join(*paths), destination_root)
end
end
end
end
File renamed without changes.
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module GeneratorTestHelpers
def self.included(base)
base.extend ClassMethods
end

module ClassMethods
def test_path
File.join(File.dirname(__FILE__), '..')
end

def create_generator_sample_app
FileUtils.cd(test_path) do
`rails new tmp --skip-spring --skip-bundle --skip-bootsnap --skip-test --skip-coffee --skip-sprockets --skip-action-cable --skip-active-storage --skip-active-record --force`
end
end

def remove_generator_sample_app
FileUtils.rm_rf(destination_root)
end
end
end
@@ -3,9 +3,11 @@
require 'simplecov'

ENV['RAILS_ENV'] ||= 'test'

require File.expand_path('../../fixtures/my_app/config/environment', __FILE__)
require 'rails/test_help'
require 'caching_helper'
require 'minitest/autorun'
require 'minitest/pride'

class FakeController < ApplicationController
def initialize(method_name = nil, &method_body)
@@ -17,3 +19,5 @@ def initialize(method_name = nil, &method_body)
end
end
end

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

0 comments on commit d8f3be9

Please sign in to comment.
You can’t perform that action at this time.