Class: ReactOnRails::Generators::DevTestsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ReactOnRails::Generators::DevTestsGenerator
show all
- Includes:
- GeneratorHelper
- Defined in:
- lib/generators/react_on_rails/dev_tests_generator.rb
Instance Method Summary
collapse
#add_documentation_reference, #add_npm_dependencies, #component_extension, #copy_file_and_missing_parent_directories, #dest_dir_exists?, #dest_file_exists?, #destination_config_path, #detect_react_version, #empty_directory_with_keep_file, #gem_in_lockfile?, #keep_file, #mark_pro_gem_installed!, #package_json, #print_generator_messages, #pro_gem_installed?, #resolve_server_client_or_both_path, #root_route_present?, #setup_file_error, #shakapacker_version_9_or_higher?, #symlink_dest_file_to_dest_file, #use_pro?, #use_rsc?, #use_rsc_pro_mode?, #using_rspack?, #using_swc?
Instance Method Details
#add_react_on_rails_as_file_dependency ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 58
def add_react_on_rails_as_file_dependency
package_json = File.join(destination_root, "package.json")
contents = JSON.parse(File.read(package_json))
contents["dependencies"] ||= {}
contents["dependencies"]["react-on-rails"] = "file:../../../packages/react-on-rails"
File.open(package_json, "w+") { |f| f.puts JSON.pretty_generate(contents) }
end
|
40
41
42
43
44
45
|
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 40
def add_test_related_gems_to_gemfile
gem("rspec-rails", group: :test)
gem("coveralls", require: false)
end
|
#copy_rspec_files ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 26
def copy_rspec_files
%w[.eslintrc
spec/spec_helper.rb
spec/rails_helper.rb
spec/simplecov_helper.rb
.rspec].each { |file| copy_file(file) }
end
|
#copy_tests ⇒ Object
34
35
36
37
38
|
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 34
def copy_tests
files = %w[spec/system/hello_world_spec.rb]
files << "spec/system/hello_server_spec.rb" if options.rsc
files.each { |file| copy_file(file) }
end
|
#replace_prerender_if_server_rendering ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/generators/react_on_rails/dev_tests_generator.rb', line 47
def replace_prerender_if_server_rendering
return unless options.example_server_rendering
hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
hello_world_contents = File.read(hello_world_index)
new_hello_world_contents = hello_world_contents.gsub("prerender: false",
"prerender: true")
File.open(hello_world_index, "w+") { |f| f.puts new_hello_world_contents }
end
|