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.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -1
- data/.travis.yml +9 -11
- data/CHANGELOG.md +13 -1
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +8 -18
- data/README.md +7 -3
- data/Rakefile +6 -1
- data/app/helpers/react_on_rails_helper.rb +41 -35
- data/docs/basics/generator.md +1 -1
- data/lib/generators/react_on_rails/base_generator.rb +13 -11
- data/lib/generators/react_on_rails/dev_tests_generator.rb +8 -16
- data/lib/generators/react_on_rails/generator_helper.rb +4 -0
- data/lib/generators/react_on_rails/generator_messages.rb +2 -0
- data/lib/generators/react_on_rails/install_generator.rb +4 -4
- data/lib/generators/react_on_rails/node_generator.rb +4 -2
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +3 -1
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +5 -3
- data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +2 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +2 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +2 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +2 -0
- data/lib/react_on_rails/assets_precompile.rb +11 -5
- data/lib/react_on_rails/configuration.rb +3 -1
- data/lib/react_on_rails/controller.rb +2 -0
- data/lib/react_on_rails/engine.rb +2 -0
- data/lib/react_on_rails/git_utils.rb +2 -0
- data/lib/react_on_rails/json_output.rb +2 -0
- data/lib/react_on_rails/locales_to_js.rb +13 -9
- data/lib/react_on_rails/prerender_error.rb +13 -10
- data/lib/react_on_rails/react_component/options.rb +2 -0
- data/lib/react_on_rails/server_rendering_pool/exec.rb +8 -0
- data/lib/react_on_rails/server_rendering_pool/node.rb +3 -1
- data/lib/react_on_rails/server_rendering_pool.rb +2 -0
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +4 -0
- data/lib/react_on_rails/test_helper/node_process_launcher.rb +2 -0
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +4 -2
- data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +2 -0
- data/lib/react_on_rails/test_helper.rb +3 -1
- data/lib/react_on_rails/utils.rb +49 -3
- data/lib/react_on_rails/version.rb +3 -1
- data/lib/react_on_rails/version_checker.rb +2 -0
- data/lib/react_on_rails/version_syntax_converter.rb +2 -0
- data/lib/react_on_rails.rb +2 -0
- data/lib/tasks/assets.rake +12 -9
- data/lib/tasks/locale.rake +7 -4
- data/package.json +2 -2
- data/rakelib/docker.rake +2 -0
- data/rakelib/dummy_apps.rake +3 -6
- data/rakelib/example_type.rb +3 -1
- data/rakelib/examples.rake +4 -1
- data/rakelib/lint.rake +2 -0
- data/rakelib/node_package.rake +3 -1
- data/rakelib/release.rake +3 -1
- data/rakelib/run_rspec.rake +10 -13
- data/rakelib/task_helpers.rb +2 -4
- data/react_on_rails.gemspec +7 -3
- 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
|
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
|
|
16
|
-
client/node/package.json
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
# 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
|
|
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
|
|
16
|
-
@symlink_non_digested_assets_regex =
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
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
|
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
|
|
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
|
-
(
|
|
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 <<
|
|
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 <<
|
|
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 <<
|
|
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
|
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"
|
|
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
|
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
|
# 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
|
-
|
|
11
|
+
cmd = "cd client && #{ReactOnRails.configuration.npm_build_test_command}"
|
|
10
12
|
|
|
11
|
-
|
|
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
|