Skip to content

Commit

Permalink
Merge pull request #35085 from vinistock/check_testing_framework_in_a…
Browse files Browse the repository at this point in the history
…ction_text_installer

Check testing framework in action text installer
  • Loading branch information
kaspth committed Nov 17, 2019
2 parents cd84dfe + 028d161 commit fe094cb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 65 deletions.
73 changes: 73 additions & 0 deletions actiontext/lib/generators/action_text/install/install_generator.rb
@@ -0,0 +1,73 @@
# frozen_string_literal: true

require "pathname"
require "json"

module ActionText
module Generators
class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

def install_javascript_dependencies
run "rake app:update:bin"

say "Installing JavaScript dependencies"
run "yarn add #{js_dependencies.map { |name, version| "#{name}@#{version}" }.join(" ")}",
abort_on_failure: true, capture: true
end

def append_dependencies_to_package_file
app_javascript_pack_path = Pathname.new("app/javascript/packs/application.js")

if app_javascript_pack_path.exist?
js_dependencies.keys.each do |name|
line = %[require("#{name}")]

unless app_javascript_pack_path.read.include? line
say "Adding #{name} to #{app_javascript_pack_path}"
append_to_file app_javascript_pack_path, "\n#{line}"
end
end
else
warn <<~WARNING
WARNING: Action Text can't locate your JavaScript bundle to add its package dependencies.
Add these lines to any bundles:
require("trix")
require("@rails/actiontext")
Alternatively, install and setup the webpacker gem then rerun `bin/rails action_text:install`
to have these dependencies added automatically.
WARNING
end
end

def create_actiontext_files
template "actiontext.scss", "app/assets/stylesheets/actiontext.scss"

copy_file "#{GEM_ROOT}/app/views/active_storage/blobs/_blob.html.erb",
"app/views/active_storage/blobs/_blob.html.erb"
end

def create_migrations
run "rake active_storage:install:migrations"
run "rake railties:install:migrations"
run "rake action_text:install:migrations"
end

hook_for :test_framework

private
GEM_ROOT = "#{__dir__}/../../../.."

def js_dependencies
package_contents = File.read(Pathname.new("#{GEM_ROOT}/package.json"))
js_package = JSON.load(package_contents)

js_package["peerDependencies"].dup.merge \
js_package["name"] => "^#{js_package["version"]}"
end
end
end
end
File renamed without changes.
13 changes: 13 additions & 0 deletions actiontext/lib/rails/generators/test_unit/install_generator.rb
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module TestUnit
module Generators
class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("templates", __dir__)

def create_test_files
template "fixtures.yml", "test/fixtures/action_text/rich_texts.yml"
end
end
end
end
File renamed without changes.
20 changes: 0 additions & 20 deletions actiontext/lib/tasks/actiontext.rake

This file was deleted.

45 changes: 0 additions & 45 deletions actiontext/lib/templates/installer.rb

This file was deleted.

1 comment on commit fe094cb

@Cyarakd
Copy link

@Cyarakd Cyarakd commented on fe094cb Feb 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.