Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35085 from vinistock/check_testing_framework_in_a…
…ction_text_installer Check testing framework in action text installer
- Loading branch information
Showing
6 changed files
with
86 additions
and
65 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
actiontext/lib/generators/action_text/install/install_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
13
actiontext/lib/rails/generators/test_unit/install_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
fe094cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fe094cb?diff=split#r37082029