react_on_rails 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -1
  3. data/.travis.yml +9 -11
  4. data/CHANGELOG.md +13 -1
  5. data/CONTRIBUTING.md +2 -2
  6. data/Gemfile +8 -18
  7. data/README.md +7 -3
  8. data/Rakefile +6 -1
  9. data/app/helpers/react_on_rails_helper.rb +41 -35
  10. data/docs/basics/generator.md +1 -1
  11. data/lib/generators/react_on_rails/base_generator.rb +13 -11
  12. data/lib/generators/react_on_rails/dev_tests_generator.rb +8 -16
  13. data/lib/generators/react_on_rails/generator_helper.rb +4 -0
  14. data/lib/generators/react_on_rails/generator_messages.rb +2 -0
  15. data/lib/generators/react_on_rails/install_generator.rb +4 -4
  16. data/lib/generators/react_on_rails/node_generator.rb +4 -2
  17. data/lib/generators/react_on_rails/react_no_redux_generator.rb +3 -1
  18. data/lib/generators/react_on_rails/react_with_redux_generator.rb +5 -3
  19. data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +2 -0
  20. data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +2 -0
  21. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -0
  22. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +2 -0
  23. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +2 -0
  24. data/lib/react_on_rails/assets_precompile.rb +11 -5
  25. data/lib/react_on_rails/configuration.rb +3 -1
  26. data/lib/react_on_rails/controller.rb +2 -0
  27. data/lib/react_on_rails/engine.rb +2 -0
  28. data/lib/react_on_rails/git_utils.rb +2 -0
  29. data/lib/react_on_rails/json_output.rb +2 -0
  30. data/lib/react_on_rails/locales_to_js.rb +13 -9
  31. data/lib/react_on_rails/prerender_error.rb +13 -10
  32. data/lib/react_on_rails/react_component/options.rb +2 -0
  33. data/lib/react_on_rails/server_rendering_pool/exec.rb +8 -0
  34. data/lib/react_on_rails/server_rendering_pool/node.rb +3 -1
  35. data/lib/react_on_rails/server_rendering_pool.rb +2 -0
  36. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +4 -0
  37. data/lib/react_on_rails/test_helper/node_process_launcher.rb +2 -0
  38. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +4 -2
  39. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +2 -0
  40. data/lib/react_on_rails/test_helper.rb +3 -1
  41. data/lib/react_on_rails/utils.rb +49 -3
  42. data/lib/react_on_rails/version.rb +3 -1
  43. data/lib/react_on_rails/version_checker.rb +2 -0
  44. data/lib/react_on_rails/version_syntax_converter.rb +2 -0
  45. data/lib/react_on_rails.rb +2 -0
  46. data/lib/tasks/assets.rake +12 -9
  47. data/lib/tasks/locale.rake +7 -4
  48. data/package.json +2 -2
  49. data/rakelib/docker.rake +2 -0
  50. data/rakelib/dummy_apps.rake +3 -6
  51. data/rakelib/example_type.rb +3 -1
  52. data/rakelib/examples.rake +4 -1
  53. data/rakelib/lint.rake +2 -0
  54. data/rakelib/node_package.rake +3 -1
  55. data/rakelib/release.rake +3 -1
  56. data/rakelib/run_rspec.rake +10 -13
  57. data/rakelib/task_helpers.rb +2 -4
  58. data/react_on_rails.gemspec +7 -3
  59. metadata +30 -30
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rainbow"
2
4
 
3
5
  module GeneratorHelper
@@ -13,11 +15,13 @@ module GeneratorHelper
13
15
  end
14
16
 
15
17
  def setup_file_error(file, data)
18
+ # rubocop:disable Layout/IndentHeredoc
16
19
  <<-MSG
17
20
  #{file} was not found.
18
21
  Please add the following content to your #{file} file:
19
22
  #{data}
20
23
  MSG
24
+ # rubocop:enable Layout/IndentHeredoc
21
25
  end
22
26
 
23
27
  def empty_directory_with_keep_file(destination, config = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeneratorMessages
2
4
  class << self
3
5
  def output
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators"
2
4
  require_relative "generator_helper"
3
5
  require_relative "generator_messages"
@@ -65,16 +67,14 @@ module ReactOnRails
65
67
 
66
68
  def missing_yarn?
67
69
  return false unless ReactOnRails::Utils.running_on_windows? ? `where yarn`.blank? : `which yarn`.blank?
68
- error = "yarn is required. Please install it before continuing. "
69
- error << "https://yarnpkg.com/en/docs/install"
70
+ error = "yarn is required. Please install it before continuing. https://yarnpkg.com/en/docs/install"
70
71
  GeneratorMessages.add_error(error)
71
72
  true
72
73
  end
73
74
 
74
75
  def missing_node?
75
76
  return false unless ReactOnRails::Utils.running_on_windows? ? `where node`.blank? : `which node`.blank?
76
- error = "** nodejs is required. Please install it before continuing. "
77
- error << "https://nodejs.org/en/"
77
+ error = "** nodejs is required. Please install it before continuing. https://nodejs.org/en/"
78
78
  GeneratorMessages.add_error(error)
79
79
  true
80
80
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators"
2
4
 
3
5
  module ReactOnRails
@@ -12,8 +14,8 @@ module ReactOnRails
12
14
 
13
15
  def copy_base_redux_files
14
16
  base_path = "node/base/"
15
- %w(client/node/server.js
16
- client/node/package.json).each do |file|
17
+ %w[client/node/server.js
18
+ client/node/package.json].each do |file|
17
19
  copy_file(base_path + file, file)
18
20
  end
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators"
2
4
  require_relative "generator_helper"
3
5
 
@@ -10,7 +12,7 @@ module ReactOnRails
10
12
 
11
13
  def copy_base_files
12
14
  base_path = "base/base/"
13
- base_files = %w(client/app/bundles/HelloWorld/components/HelloWorld.jsx)
15
+ base_files = %w[client/app/bundles/HelloWorld/components/HelloWorld.jsx]
14
16
  base_files.each { |file| copy_file("#{base_path}#{file}", file) }
15
17
  end
16
18
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators"
2
4
 
3
5
  module ReactOnRails
@@ -7,19 +9,19 @@ module ReactOnRails
7
9
  source_root(File.expand_path("../templates", __FILE__))
8
10
 
9
11
  def create_redux_directories
10
- dirs = %w(actions constants reducers store)
12
+ dirs = %w[actions constants reducers store]
11
13
  dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
12
14
  end
13
15
 
14
16
  def copy_base_redux_files
15
17
  base_path = "redux/base/"
16
- %w(client/app/bundles/HelloWorld/components/HelloWorld.jsx
18
+ %w[client/app/bundles/HelloWorld/components/HelloWorld.jsx
17
19
  client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
18
20
  client/app/bundles/HelloWorld/containers/HelloWorldContainer.jsx
19
21
  client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
20
22
  client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
21
23
  client/app/bundles/HelloWorld/store/helloWorldStore.jsx
22
- client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx).each do |file|
24
+ client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx].each do |file|
23
25
  copy_file(base_path + file, file)
24
26
  end
25
27
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class HelloWorldController < ApplicationController
2
4
  layout "hello_world"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../rails_helper"
2
4
 
3
5
  feature "Hello World", js: true do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is copied to spec/ when you run "rails generate rspec:install"
2
4
  ENV["RAILS_ENV"] ||= "test"
3
5
  require_relative "../config/environment"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Starts SimpleCov for code coverage.
2
4
 
3
5
  if ENV["COVERAGE"]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  class AssetsPrecompile
3
- class SymlinkTargetDoesNotExistException < StandardError; end
5
+ class SymlinkTargetDoesNotExistException < StandardError
6
+ end
4
7
 
5
8
  # Used by the rake task
6
9
  def default_asset_path
@@ -9,13 +12,16 @@ module ReactOnRails
9
12
  Pathname.new(dir)
10
13
  end
11
14
 
15
+ # assets_path should be a Pathname object
12
16
  def initialize(assets_path: nil,
13
17
  symlink_non_digested_assets_regex: nil,
14
18
  generated_assets_dir: nil)
15
- @assets_path = assets_path.presence || default_asset_path
16
- @symlink_non_digested_assets_regex = symlink_non_digested_assets_regex.presence ||
17
- ReactOnRails.configuration.symlink_non_digested_assets_regex
18
- @generated_assets_dir = generated_assets_dir.presence || ReactOnRails.configuration.generated_assets_dir
19
+ @assets_path = ReactOnRails::Utils.truthy_presence(assets_path) || default_asset_path
20
+ @symlink_non_digested_assets_regex =
21
+ ReactOnRails::Utils.truthy_presence(symlink_non_digested_assets_regex) ||
22
+ ReactOnRails.configuration.symlink_non_digested_assets_regex
23
+ @generated_assets_dir = ReactOnRails::Utils.truthy_presence(generated_assets_dir) ||
24
+ ReactOnRails.configuration.generated_assets_dir
19
25
  end
20
26
 
21
27
  # target and symlink are relative to the assets directory
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  def self.configure
3
5
  yield(configuration)
4
6
  setup_config_values
5
7
  end
6
8
 
7
- DEFAULT_GENERATED_ASSETS_DIR = File.join(%w(public webpack), Rails.env).freeze
9
+ DEFAULT_GENERATED_ASSETS_DIR = File.join(%w[public webpack], Rails.env).freeze
8
10
 
9
11
  def self.setup_config_values
10
12
  ensure_webpack_generated_files_exists
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module Controller
3
5
  # Separate initialization of store from react_component allows multiple react_component calls to
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/railtie"
2
4
 
3
5
  module ReactOnRails
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module GitUtils
3
5
  def self.uncommitted_changes?(message_handler)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/string/output_safety"
2
4
 
3
5
  module ReactOnRails
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "erb"
2
4
 
3
5
  module ReactOnRails
@@ -27,7 +29,7 @@ module ReactOnRails
27
29
  end
28
30
 
29
31
  def js_file_names
30
- %w(translations default)
32
+ %w[translations default]
31
33
  end
32
34
 
33
35
  def js_files
@@ -43,7 +45,9 @@ module ReactOnRails
43
45
  if i18n_yml_dir.present?
44
46
  Dir["#{i18n_yml_dir}/**/*.yml"]
45
47
  else
46
- (Rails.application && Rails.application.config.i18n.load_path).presence
48
+ ReactOnRails::Utils.truthy_presence(
49
+ Rails.application && Rails.application.config.i18n.load_path
50
+ ).presence
47
51
  end
48
52
  end
49
53
  end
@@ -110,20 +114,20 @@ module ReactOnRails
110
114
  end
111
115
 
112
116
  def template_translations
113
- <<-JS
114
- export const translations = #{@translations};
117
+ <<-JS.strip_heredoc
118
+ export const translations = #{@translations};
115
119
  JS
116
120
  end
117
121
 
118
122
  def template_default
119
- <<-JS
120
- import { defineMessages } from 'react-intl';
123
+ <<-JS.strip_heredoc
124
+ import { defineMessages } from 'react-intl';
121
125
 
122
- const defaultLocale = \'#{default_locale}\';
126
+ const defaultLocale = \'#{default_locale}\';
123
127
 
124
- const defaultMessages = defineMessages(#{@defaults});
128
+ const defaultMessages = defineMessages(#{@defaults});
125
129
 
126
- export { defaultMessages, defaultLocale };
130
+ export { defaultMessages, defaultLocale };
127
131
  JS
128
132
  end
129
133
  end
@@ -1,27 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable: Layout/IndentHeredoc
1
4
  module ReactOnRails
2
5
  class PrerenderError < RuntimeError
3
6
  # err might be nil if JS caught the error
4
7
  def initialize(component_name: nil, err: nil, props: nil,
5
8
  js_code: nil, console_messages: nil)
6
- message = "ERROR in SERVER PRERENDERING\n"
9
+ message = "ERROR in SERVER PRERENDERING\n".dup
7
10
  if err
8
- message << <<-MSG
9
- Encountered error: \"#{err}\"
11
+ message << <<~MSG
12
+ Encountered error: \"#{err}\"
10
13
  MSG
11
14
  backtrace = err.backtrace.join("\n")
12
15
  else
13
16
  backtrace = nil
14
17
  end
15
- message << <<-MSG
16
- when prerendering #{component_name} with props: #{props}
17
- js_code was:
18
- #{js_code}
18
+ message << <<~MSG
19
+ when prerendering #{component_name} with props: #{props}
20
+ js_code was:
21
+ #{js_code}
19
22
  MSG
20
23
 
21
24
  if console_messages
22
- message << <<-MSG
23
- console messages:
24
- #{console_messages}
25
+ message << <<~MSG
26
+ console messages:
27
+ #{console_messages}
25
28
  MSG
26
29
  end
27
30
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "react_on_rails/utils"
2
4
 
3
5
  module ReactOnRails
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module ServerRenderingPool
3
5
  # This implementation of the rendering pool uses ExecJS to execute javasript code
@@ -89,11 +91,13 @@ module ReactOnRails
89
91
  end
90
92
 
91
93
  bundle_js_code = File.read(server_js_file)
94
+ # rubocop:disable Layout/IndentHeredoc
92
95
  base_js_code = <<-JS
93
96
  #{console_polyfill}
94
97
  #{execjs_timer_polyfills}
95
98
  #{bundle_js_code};
96
99
  JS
100
+ # rubocop:enable Layout/IndentHeredoc
97
101
  file_name = "tmp/base_js_code.js"
98
102
  begin
99
103
  trace_messsage(base_js_code, file_name)
@@ -111,6 +115,7 @@ module ReactOnRails
111
115
  end
112
116
 
113
117
  def execjs_timer_polyfills
118
+ # rubocop:disable Layout/IndentHeredoc
114
119
  <<-JS
115
120
  function getStackTrace () {
116
121
  var stack;
@@ -136,6 +141,7 @@ function clearTimeout() {
136
141
  #{undefined_for_exec_js_logging('clearTimeout')}
137
142
  }
138
143
  JS
144
+ # rubocop:enable Layout/IndentHeredoc
139
145
  end
140
146
 
141
147
  def undefined_for_exec_js_logging(function_name)
@@ -150,6 +156,7 @@ function clearTimeout() {
150
156
 
151
157
  # Reimplement console methods for replaying on the client
152
158
  def console_polyfill
159
+ # rubocop:disable Layout/IndentHeredoc
153
160
  <<-JS
154
161
  var console = { history: [] };
155
162
  ['error', 'log', 'info', 'warn'].forEach(function (level) {
@@ -162,6 +169,7 @@ var console = { history: [] };
162
169
  };
163
170
  });
164
171
  JS
172
+ # rubocop:enable Layout/IndentHeredoc
165
173
  end
166
174
  end
167
175
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module ServerRenderingPool
3
5
  class Node
@@ -51,7 +53,7 @@ module ReactOnRails
51
53
  end
52
54
 
53
55
  def eval_js(js_code)
54
- eof_symbol = "\r\n\0".freeze
56
+ eof_symbol = "\r\n\0"
55
57
  max_int = (2**30 - 1)
56
58
  @js_context_pool.with do |js_context|
57
59
  js_context.send(js_code + eof_symbol, 0)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "connection_pool"
2
4
  require_relative "server_rendering_pool/exec"
3
5
  require_relative "server_rendering_pool/node"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module TestHelper
3
5
  class EnsureAssetsCompiled
@@ -41,6 +43,7 @@ module ReactOnRails
41
43
  end
42
44
 
43
45
  def puts_start_compile_check_message(stale_files)
46
+ # rubocop:disable Layout/IndentHeredoc
44
47
  puts <<-MSG
45
48
 
46
49
  Detected the following stale generated files:
@@ -50,6 +53,7 @@ React on Rails will ensure your JavaScript generated files are up to date, using
50
53
  /client level package.json `#{ReactOnRails.configuration.npm_build_test_command}` command.
51
54
 
52
55
  MSG
56
+ # rubocop:enable Layout/IndentHeredoc
53
57
  end
54
58
  end
55
59
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReactOnRails
2
4
  module TestHelper
3
5
  def self.launch_node
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # You can replace this implementation with your own for use by the
2
4
  # ReactOnRails::TestHelper.ensure_assets_compiled helper
3
5
  module ReactOnRails
@@ -6,9 +8,9 @@ module ReactOnRails
6
8
  def compile_assets
7
9
  puts "\nBuilding Webpack assets..."
8
10
 
9
- build_output = `cd client && #{ReactOnRails.configuration.npm_build_test_command}`
11
+ cmd = "cd client && #{ReactOnRails.configuration.npm_build_test_command}"
10
12
 
11
- raise "Error in building assets!\n#{build_output}" unless Utils.last_process_completed_successfully?
13
+ ReactOnRails::Utils.invoke_and_exit_if_failed(cmd, "Error in building webpack assets!")
12
14
 
13
15
  puts "Completed building Webpack assets."
14
16
  end