react_on_rails 6.0.0.rc.1 → 6.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68bfa72cdabcd0e2d861afb7da5ca7af104b5140
4
- data.tar.gz: baac4a7186be9bc820dfe64b660b241c08bba3fa
3
+ metadata.gz: 4fa57ce474be6cdecc395a2a0241a4a543ef1a68
4
+ data.tar.gz: dc3f4b0fc45854395163b3cec9b128c8983584d4
5
5
  SHA512:
6
- metadata.gz: 1cd07693555179d1e8ddc79fc7c495eeaee20ce5081f8897c5d79af468c1a98f219ae9ff76b9ecb4a4875c189b21ba32f05de6ee8c84ddc1bb1b89c31f909dda
7
- data.tar.gz: 5753b635513ceb439fc2f19f9a453a27533ee07c1435811f0aa982727136fb1f07316e73b0108aa9d89617c3506797d34fd5622e2f9359e1a73c1b376ca3c01a
6
+ metadata.gz: 436ca89cf6a4531b363dabd0dbbeee60208e5889f6cbe6c349c93070759ac032ae5ec4cc3ab62918fea4afe7f724c8a1b1d4a6721e559578410c583e644333a9
7
+ data.tar.gz: 714db3dc3ed5d8777be27bc7d33fe12c477eaa2920f6887d463a4cc18681d7206b1a2e77f7470de1439771cc658741b5fcf6e60f0e1f6f0007f973457a8e64c3
data/CHANGELOG.md CHANGED
@@ -4,20 +4,30 @@ All notable changes to this project will be documented in this file. Items under
4
4
  Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.
5
5
  ## [Unreleased]
6
6
 
7
- ## [6.0.0-rc1]
7
+ ## [6.0.0-rc.1]
8
8
  ##### Breaking Changes
9
9
  - Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own assets.rake file that does the precompilation.
10
10
  [#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808).
11
- - **Migration to v6: you can either:**
11
+ - **Migration to v6**
12
12
 
13
- 1. Specify a `config/react_on_rails` setting for `npm_build_production_command` to be nil to turn this feature off.
14
- 2. Specify the script command you want to run to build your production assets, and remove your assets.rake file.
13
+ - To configure the asset compliation you can either
14
+ 1. Specify a `config/react_on_rails` setting for `npm_build_production_command` to be nil to turn this feature off.
15
+ 2. Specify the script command you want to run to build your production assets, and remove your assets.rake file.
16
+
17
+ - If you are using the ReactOnRails test helper, then you will need to add the 'config.npm_build_test_command' to your config to tell react_on_rails what command to run when you run rspec.
18
+
19
+ - See [shakacode/react-webpack-rails-tutorial #287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287/files) for an upgrade example. The PR has a few comments on the upgrade.
15
20
 
16
21
  Here is the addition to the generated config file:
17
22
  ```ruby
18
23
  # This configures the script to run to build the production assets by webpack. Set this to nil
19
24
  # if you don't want react_on_rails building this file for you.
20
25
  config.npm_build_production_command = "npm run build:production"
26
+
27
+ # If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
28
+ # with rspec then this controls what npm command is run
29
+ # to automatically refresh your webpack assets on every test run.
30
+ config.npm_build_test_command = "npm run build:test"
21
31
  ```
22
32
 
23
33
  ##### Fixed
data/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  **Project Objective**: To provide an opinionated and optimal framework for integrating **Ruby on Rails** with modern JavaScript tooling and libraries, including [**Webpack**](http://webpack.github.io/), [**Babel**](https://babeljs.io/), [**React**](https://facebook.github.io/react/), [**Redux**](https://github.com/reactjs/redux), [**React-Router**](https://github.com/reactjs/react-router). This differs significantly from typical Rails. When considering what goes into **react_on_rails**, we ask ourselves, is the functionality related to the intersection of using Rails and with modern JavaScript? If so, then the functionality belongs right here. In other cases, we're releasing separate npm packages or Ruby gems. If you are interested in implementing React using traditional Rails architecture, see [react-rails](https://github.com/reactjs/react-rails).
20
20
 
21
- React on Rails integrates Facebook's [React](https://github.com/facebook/react) front-end framework with Rails. React v0.14.x and greate is supported, with server rendering. [Redux](https://github.com/reactjs/redux) and [React-Router](https://github.com/reactjs/react-redux) are supported as well, also with server rendering, using either **execJS** or a [Node.js server](https://github.com/shakacode/react_on_rails/blob/master/docs%2Fadditional-reading%2Fnode-server-rendering.md). See the Rails on Maui [blog post](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/) that started it all!
21
+ React on Rails integrates Facebook's [React](https://github.com/facebook/react) front-end framework with Rails. React v0.14.x and greater is supported, with server rendering. [Redux](https://github.com/reactjs/redux) and [React-Router](https://github.com/reactjs/react-redux) are supported as well, also with server rendering, using either **execJS** or a [Node.js server](https://github.com/shakacode/react_on_rails/blob/master/docs%2Fadditional-reading%2Fnode-server-rendering.md). See the Rails on Maui [blog post](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/) that started it all!
22
22
 
23
23
  ## Including your React Component in your Rails Views
24
24
  Please see [Getting Started](#getting-started) for how to set up your Rails project for React on Rails to understand how `react_on_rails` can see your ReactComponents.
@@ -72,6 +72,7 @@ Please see [Getting Started](#getting-started) for how to set up your Rails proj
72
72
  - [ReactOnRails JavaScript API](#reactonrails-javascript-api)
73
73
  - [React-Router](#react-router)
74
74
  - [Deployment](#deployment)
75
+ + [Integration with Node](#integration-with-node)
75
76
  + [Additional Reading](#additional-reading)
76
77
  + [Contributing](#contributing)
77
78
  + [License](#license)
@@ -101,37 +102,39 @@ Universal React with Rails: Part I](https://medium.com/@alexfedoseev/isomorphic-
101
102
  We're definitely not doing that. With react_on_rails, webpack is mainly generating a nice JavaScript file for inclusion into `application.js`. We're going to KISS. And that's all relative given how much there is to get right in an enterprise class web application.
102
103
 
103
104
  ## Getting Started
104
- 1. Add the following to your Gemfile and bundle install:
105
+ 1. Add the following to your Gemfile and bundle install.
105
106
 
106
107
  ```ruby
107
108
  gem "react_on_rails", "~> 5"
108
109
  ```
109
110
 
110
- 2. See help for the generator:
111
+ 2. Commit this to git (you cannot run the generator unless you do this).
112
+
113
+ 3. See help for the generator:
111
114
 
112
115
  ```bash
113
116
  rails generate react_on_rails:install --help
114
117
  ```
115
118
 
116
- 2. Run the generator with a simple "Hello World" example (more options below):
119
+ 4. Run the generator with a simple "Hello World" example (more options below):
117
120
 
118
121
  ```bash
119
122
  rails generate react_on_rails:install
120
123
  ```
121
124
 
122
- 3. NPM install. Make sure you are on a recent version of node. Please use at least Node v5.
125
+ 5. NPM install. Make sure you are on a recent version of node. Please use at least Node v5.
123
126
 
124
127
  ```bash
125
128
  npm install
126
129
  ```
127
130
 
128
- 4. Start your Rails server:
131
+ 6. Start your Rails server:
129
132
 
130
133
  ```bash
131
134
  foreman start -f Procfile.dev
132
135
  ```
133
136
 
134
- 5. Visit [localhost:3000/hello_world](http://localhost:3000/hello_world)
137
+ 7. Visit [localhost:3000/hello_world](http://localhost:3000/hello_world)
135
138
 
136
139
  ### Installation Summary
137
140
 
@@ -414,6 +417,117 @@ See [ReactOnRails JavaScriptAPI](docs/api/javascript-api.md).
414
417
  * See the [Heroku Deployment](docs/additional-reading/heroku-deployment.md) doc for specifics regarding Heroku.
415
418
  * If you're using the node server for server rendering, you may want to do your own AWS install. We'll have more docs on this in the future.
416
419
 
420
+ ## Integration with Node
421
+ NodeJS can be used as the backend for server-side rendering instead of ExecJS. To do this you need to add a few files and then configure react_on_rails to use NodeJS. Here are the relevant files to add.
422
+
423
+ ```javascript
424
+ // client/node/package.json
425
+ {
426
+ "name": "react_on_rails_node",
427
+ "version": "0.0.0",
428
+ "private": true,
429
+ "scripts": {
430
+ "start": "node ./server.js -s webpack-bundle.js"
431
+ },
432
+ "dependencies": {
433
+ }
434
+ }
435
+ ```
436
+
437
+ ```javascript
438
+ // client/node/server.js
439
+ var net = require('net');
440
+ var fs = require('fs');
441
+
442
+ var bundlePath = '../../app/assets/webpack/';
443
+ var bundleFileName = 'webpack-bundle.js';
444
+
445
+ var currentArg;
446
+
447
+ function Handler() {
448
+ this.queue = [];
449
+ this.initialized = false;
450
+ }
451
+
452
+ Handler.prototype.handle = function (connection) {
453
+ var callback = function () {
454
+ connection.setEncoding('utf8');
455
+ connection.on('data', (data)=> {
456
+ console.log('Processing request: ' + data);
457
+ var result = eval(data);
458
+ connection.write(result);
459
+ });
460
+ };
461
+
462
+ if (this.initialized) {
463
+ callback();
464
+ } else {
465
+ this.queue.push(callback);
466
+ }
467
+ };
468
+
469
+ Handler.prototype.initialize = function () {
470
+ console.log('Processing ' + this.queue.length + ' pending requests');
471
+ var callback;
472
+ while (callback = this.queue.pop()) {
473
+ callback();
474
+ }
475
+
476
+ this.initialized = true;
477
+ };
478
+
479
+ var handler = new Handler();
480
+
481
+ process.argv.forEach((val) => {
482
+ if (val[0] == '-') {
483
+ currentArg = val.slice(1);
484
+ return;
485
+ }
486
+
487
+ if (currentArg == 's') {
488
+ bundleFileName = val;
489
+ }
490
+ });
491
+
492
+ try {
493
+ fs.mkdirSync(bundlePath);
494
+ } catch (e) {
495
+ if (e.code != 'EEXIST') throw e;
496
+ }
497
+
498
+ fs.watchFile(bundlePath + bundleFileName, (curr) => {
499
+ if (curr && curr.blocks && curr.blocks > 0) {
500
+ if (handler.initialized) {
501
+ console.log('Reloading server bundle must be implemented by restarting the node process!');
502
+ return;
503
+ }
504
+
505
+ require(bundlePath + bundleFileName);
506
+ console.log('Loaded server bundle: ' + bundlePath + bundleFileName);
507
+ handler.initialize();
508
+ }
509
+ });
510
+
511
+ var unixServer = net.createServer(function (connection) {
512
+ handler.handle(connection);
513
+ });
514
+
515
+ unixServer.listen('node.sock');
516
+
517
+ process.on('SIGINT', () => {
518
+ unixServer.close();
519
+ process.exit();
520
+ });
521
+
522
+ ```
523
+
524
+ The last thing you'll need to do is change the server_render_method to "NodeJS".
525
+
526
+ ```ruby
527
+ # app/config/initializers/react_on_rails.rb
528
+ config.server_render_method = "NodeJS"
529
+ ```
530
+
417
531
  ## Additional Reading
418
532
  + [JavaScript API](docs/api/javascript-api.md)
419
533
  + [Ruby API](docs/api/ruby-api.md)
@@ -85,14 +85,6 @@ module ReactOnRails
85
85
  append_to_file("Gemfile", "\ngem 'therubyracer', platforms: :ruby\n")
86
86
  end
87
87
 
88
- def install_node_files
89
- base_path = "base/base/"
90
- %w(client/node/package.json
91
- client/node/server.js).each do |file|
92
- copy_file(base_path + file, file)
93
- end
94
- end
95
-
96
88
  ASSETS_RB_APPEND = <<-DATA.strip_heredoc
97
89
  # Add client/assets/ folders to asset pipeline's search path.
98
90
  # If you do not want to move existing images and fonts from your Rails app
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ReactOnRails
3
- VERSION = "6.0.0.rc.1".freeze
3
+ VERSION = "6.0.0.rc.2".freeze
4
4
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "6.0.0-rc.1",
3
+ "version": "6.0.0-rc.2",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.rc.1
4
+ version: 6.0.0.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -379,13 +379,9 @@ files:
379
379
  - lib/generators/react_on_rails/templates/base/base/client/.babelrc
380
380
  - lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md
381
381
  - lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt
382
- - lib/generators/react_on_rails/templates/base/base/client/node/package.json
383
- - lib/generators/react_on_rails/templates/base/base/client/node/server.js
384
382
  - lib/generators/react_on_rails/templates/base/base/client/package.json.tt
385
383
  - lib/generators/react_on_rails/templates/base/base/client/webpack.config.js
386
384
  - lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
387
- - lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
388
- - lib/generators/react_on_rails/templates/base/base/lib/tasks/load_test.rake
389
385
  - lib/generators/react_on_rails/templates/base/base/package.json.tt
390
386
  - lib/generators/react_on_rails/templates/dev_tests/.rspec
391
387
  - lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb
@@ -1,10 +0,0 @@
1
- {
2
- "name": "react_on_rails_node",
3
- "version": "0.0.0",
4
- "private": true,
5
- "scripts": {
6
- "start": "node ./server.js -s webpack-bundle.js"
7
- },
8
- "dependencies": {
9
- }
10
- }
@@ -1,82 +0,0 @@
1
- var net = require('net');
2
- var fs = require('fs');
3
-
4
- var bundlePath = '../../app/assets/webpack/';
5
- var bundleFileName = 'webpack-bundle.js';
6
-
7
- var currentArg;
8
-
9
- function Handler() {
10
- this.queue = [];
11
- this.initialized = false;
12
- }
13
-
14
- Handler.prototype.handle = function (connection) {
15
- var callback = function () {
16
- connection.setEncoding('utf8');
17
- connection.on('data', (data)=> {
18
- console.log('Processing request: ' + data);
19
- var result = eval(data);
20
- connection.write(result);
21
- });
22
- };
23
-
24
- if (this.initialized) {
25
- callback();
26
- } else {
27
- this.queue.push(callback);
28
- }
29
- };
30
-
31
- Handler.prototype.initialize = function () {
32
- console.log('Processing ' + this.queue.length + ' pending requests');
33
- var callback;
34
- while (callback = this.queue.pop()) {
35
- callback();
36
- }
37
-
38
- this.initialized = true;
39
- };
40
-
41
- var handler = new Handler();
42
-
43
- process.argv.forEach((val) => {
44
- if (val[0] == '-') {
45
- currentArg = val.slice(1);
46
- return;
47
- }
48
-
49
- if (currentArg == 's') {
50
- bundleFileName = val;
51
- }
52
- });
53
-
54
- try {
55
- fs.mkdirSync(bundlePath);
56
- } catch (e) {
57
- if (e.code != 'EEXIST') throw e;
58
- }
59
-
60
- fs.watchFile(bundlePath + bundleFileName, (curr) => {
61
- if (curr && curr.blocks && curr.blocks > 0) {
62
- if (handler.initialized) {
63
- console.log('Reloading server bundle must be implemented by restarting the node process!');
64
- return;
65
- }
66
-
67
- require(bundlePath + bundleFileName);
68
- console.log('Loaded server bundle: ' + bundlePath + bundleFileName);
69
- handler.initialize();
70
- }
71
- });
72
-
73
- var unixServer = net.createServer(function (connection) {
74
- handler.handle(connection);
75
- });
76
-
77
- unixServer.listen('node.sock');
78
-
79
- process.on('SIGINT', () => {
80
- unixServer.close();
81
- process.exit();
82
- });
@@ -1,23 +0,0 @@
1
- # lib/tasks/assets.rake
2
- # The webpack task must run before assets:environment task.
3
- # Otherwise Sprockets cannot find the files that webpack produces.
4
- # This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
5
- Rake::Task["assets:precompile"]
6
- .clear_prerequisites
7
- .enhance(["assets:compile_environment"])
8
-
9
- namespace :assets do
10
- # In this task, set prerequisites for the assets:precompile task
11
- task compile_environment: :webpack do
12
- Rake::Task["assets:environment"].invoke
13
- end
14
-
15
- desc "Compile assets with webpack"
16
- task :webpack do
17
- sh "cd client && npm run build:production"
18
- end
19
-
20
- task :clobber do
21
- rm_r Dir.glob(Rails.root.join("app/assets/webpack/*"))
22
- end
23
- end
@@ -1,8 +0,0 @@
1
- namespace :load_test do
2
- desc "Load test with apache benchmark"
3
- task :run, [:url, :count] do |_, args|
4
- url = args[:url] || "http://localhost:3000/hello_world"
5
- count = args[:count] || 500
6
- system("ab -c 10 -n #{count} #{url}")
7
- end
8
- end