react_on_rails 2.0.0.beta.2 → 2.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.travis.yml +2 -0
  4. data/Gemfile +1 -0
  5. data/Rakefile +5 -0
  6. data/app/helpers/react_on_rails_helper.rb +0 -1
  7. data/docs/contributing.md +30 -19
  8. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -0
  9. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt +2 -0
  10. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -0
  11. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +1 -1
  12. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +4 -2
  13. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +7 -2
  14. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +2 -2
  15. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +5 -5
  16. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +0 -1
  17. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +1 -1
  18. data/lib/react_on_rails/configuration.rb +3 -9
  19. data/lib/react_on_rails/version.rb +1 -1
  20. data/lib/react_on_rails/version_checker.rb +52 -0
  21. data/package.json +2 -1
  22. data/rakelib/examples.rake +3 -1
  23. data/rakelib/examples_config.yml +2 -2
  24. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e31774c6bd02e65296e93fbfbefbf45ffcbe2a9b
4
- data.tar.gz: 7734b39bc33436dbbb9fbe611be63e32320cfbd5
3
+ metadata.gz: 1e6a3e3f5a956072da985398fcc4a47717c1c654
4
+ data.tar.gz: 54dd160efba8dfe5ce0c35c2d56fb326f5e82984
5
5
  SHA512:
6
- metadata.gz: 5e36562a5e9bb7aca5cdbba893d94e1fcea207a31dbd67e2fa2d0a3af8ef23c8a40820839d15b6a3edfb4b11f2e869b083752f62fdd81638cee865d828eb9f74
7
- data.tar.gz: b19b18901a1c8e08a880b72a88acebb5dfcaf46b8300133228457565da75c1fc8590012f734e06d021400d42d1841daf05458edc33c2977e1ae9a1ea7a12cd39
6
+ metadata.gz: 7f6910bd7f55013c68d046febb69b0b709cb470351b2ce008a66580336cd9a540e1f7cf97f7480bb0a617c681e4004b284785db8e1d4d7eb75dab1a417a811cb
7
+ data.tar.gz: cfbb296cbd1b90af417facd4850292eb9f76a705eadd380535dd9d50b2fdba1000212d7c46b2d248dc325bd7f6b0eab519543afecb6d436093adf616589973dc
@@ -8,11 +8,13 @@ AllCops:
8
8
  Exclude:
9
9
  - 'vendor/**/*'
10
10
  - 'spec/fixtures/**/*'
11
+ - 'node_modules/**/*.*'
11
12
  - 'node_modules/**/*'
12
13
  - 'coverage/**/*'
13
14
  - 'db/**/*'
14
15
  - 'db/schema.rb'
15
16
  - 'db/seeds.rb'
17
+ - 'client/node_modules/**/*.*'
16
18
  - 'client/node_modules/**/*'
17
19
  - 'bin/**/*'
18
20
  - !ruby/regexp /old_and_unused\.rb$/
@@ -25,6 +25,7 @@ before_install:
25
25
  install:
26
26
  - rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 4.2.0
27
27
  - npm install -g npm
28
+ - npm install -g poltergeist
28
29
  - bundle install
29
30
  - npm install
30
31
  - rake dummy_apps
@@ -34,6 +35,7 @@ install:
34
35
  before_script:
35
36
  - "export DISPLAY=:99"
36
37
  - Xvfb :99 -ac -screen scn 1600x1200x16 &
38
+ - npm run symlink_node_package
37
39
 
38
40
  script:
39
41
  - rake
data/Gemfile CHANGED
@@ -16,6 +16,7 @@ gem "coffee-rails", "~> 4.1.0"
16
16
  gem "jbuilder", "~> 2.0"
17
17
  gem "jquery-rails"
18
18
  gem "launchy"
19
+ gem "poltergeist"
19
20
  gem "pry"
20
21
  gem "pry-byebug"
21
22
  gem "pry-doc"
data/Rakefile CHANGED
@@ -3,3 +3,8 @@
3
3
 
4
4
  desc "Run all tests and linting"
5
5
  task default: ["run_rspec", "docker:lint"]
6
+
7
+ desc "Has all examples and dummy apps use local node_package folder for react-on-rails node dependency"
8
+ task :symlink_node_package do
9
+ sh_in_dir(gem_root, "npm run symlink_node_package")
10
+ end
@@ -146,7 +146,6 @@ module ReactOnRailsHelper
146
146
 
147
147
  # Returns Array [0]: html, [1]: script to console log
148
148
  # NOTE, these are NOT html_safe!
149
- # rubocop:disable Metrics/CyclomaticComplexity
150
149
  def server_rendered_react_component_html(options, props, react_component_name, dom_id)
151
150
  return { "html" => "", "consoleReplayScript" => "" } unless prerender(options)
152
151
 
@@ -1,6 +1,13 @@
1
1
  # Tips for Contributors
2
2
  *See [Releasing](../releasing.md) for instructions on releasing.*
3
3
 
4
+ * After Syncing, to prepare all examples and run all tests
5
+
6
+ ```
7
+ bundle && npm i && rake examples:prepare_all && rake symlink_node_package && rake
8
+ ```
9
+
10
+
4
11
  # IDE/IDE SETUP
5
12
  It's critical to configure your IDE/editor to ignore certain directories. Otherwise your IDE might slow to a crawl!
6
13
 
@@ -28,8 +35,10 @@ Note that you will need to bundle install after making this change, but also tha
28
35
  ## NPM for react-on-rails
29
36
  First, be **sure** to build the NPM package
30
37
 
31
- npm i
32
- npm run build
38
+ ```sh
39
+ npm i
40
+ npm run build
41
+ ```
33
42
 
34
43
  Use either npm-link (described below), or use a relative path in your `package.json`, like this:
35
44
 
@@ -39,7 +48,6 @@ Use either npm-link (described below), or use a relative path in your `package.j
39
48
 
40
49
  If you use a relative path, be sure to run `npm i` whenever you rebuild the node package.
41
50
 
42
-
43
51
  # Development Setup for Gem and Node Package Contributors
44
52
 
45
53
  ## Checklist before Committing
@@ -52,18 +60,22 @@ If you use a relative path, be sure to run `npm i` whenever you rebuild the node
52
60
  ### Prereqs
53
61
  After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
62
 
55
- ### Npm link
63
+ Additionally, our RSpec tests use the poltergeist web driver. You will need to install the poltergeist node module:
64
+
65
+ ```sh
66
+ npm install -g poltergeist
67
+ ```
56
68
 
57
- By the following steps, the node package code of react-on-rails is directly coming from `node_package/lib`
69
+ ### NPM link
70
+ Because the example and dummy apps rely on the react-on-rails node package, they should link directly to your local version to pick up any changes you may have made to that package. To achieve this, switch to the app's root directory and run:
58
71
 
59
72
  ```sh
60
- cd <top level>
61
- npm link
62
- cd spec/dummy/client
63
- npm link react-on-rails
73
+ npm run symlink_node_package
64
74
  ```
65
75
 
66
- *Side note: It's critical to use the alias section of the webpack config to avoid the double inclusion error:*
76
+ From now on, the example and dummy apps will use your local node_package folder as the react-on-rails node package. This will also be done automatically for you via the `rake examples:prepare_all` rake task.
77
+
78
+ *Side note: It's critical to use the alias section of the webpack config to avoid a double inclusion error. This has already been done for you in the example and dummy apps, but for reference:*
67
79
 
68
80
  ```js
69
81
  resolve: {
@@ -73,7 +85,7 @@ npm link react-on-rails
73
85
  },
74
86
  ```
75
87
 
76
- ### Install npm dependencies and build the npm package for react-on-rails
88
+ ### Install NPM dependencies and build the NPM package for react-on-rails
77
89
 
78
90
  ```sh
79
91
  cd <top level>
@@ -83,7 +95,7 @@ cd spec/dummy
83
95
  npm i
84
96
  ```
85
97
 
86
- ### Run npm JS tests
98
+ ### Run NPM JS tests
87
99
 
88
100
  ```sh
89
101
  cd <top level>
@@ -96,15 +108,14 @@ npm test
96
108
  cd spec/dummy
97
109
  npm run test
98
110
  ```
99
-
111
+
100
112
  ### Run most tests and linting
101
113
 
102
- ```
114
+ ```sh
103
115
  cd <top level>
104
116
  node_package/scripts/ci
105
117
  ```
106
118
 
107
-
108
119
  ### Starting the Dummy App
109
120
  To run the test app, it's **CRITICAL** to not just run `rails s`. You have to run `foreman start`. If you don't do this, then `webpack` will not generate a new bundle, and you will be seriously confused when you change JavaScript and the app does not change. If you change the webpack configs, then you need to restart foreman. If you change the JS code for react-on-rails, you need to run `node_package/scripts/build`. Since the react-on-rails package should be sym linked, you don't have to `npm i react-on-rails` after every change.
110
121
 
@@ -118,14 +129,14 @@ After running a test, you can view the coverage results SimpleCov reports by ope
118
129
  ### Debugging
119
130
  Start the sample app like this for some debug printing:
120
131
 
121
- ```bash
132
+ ```sh
122
133
  TRACE_REACT_ON_RAILS=true && foreman start
123
134
  ```
124
135
 
125
136
  ### Install Generator
126
137
  In your Rails app add this gem with a path to your fork.
127
138
 
128
- ```
139
+ ```ruby
129
140
  gem 'react_on_rails', path: '../relative/path/to/react_on_rails'
130
141
  ```
131
142
 
@@ -147,11 +158,11 @@ Run `rake -D docker` to see all docker linting commands for rake. `rake docker:l
147
158
 
148
159
  You can run specific linting for directories or files by using `docker-compose run lint rubocop (file path or directory)`, etc.
149
160
 
150
- `docker-compose run lint bash` sets you up to run from the container command line.
161
+ `docker-compose run lint bash` sets you up to run from the container command line.
151
162
 
152
163
  ### Docker CI - Test and Linting
153
164
  Docker CI and Tests containers have a xvfd server automatically started for headless browser testing with selenium and Firefox.
154
165
 
155
166
  Run `docker-compose build ci` to build the CI container. Run `docker-compose run ci` to start all rspec tests and linting. `docker-compose run --entrypoint=/bin/bash` will override the default CI action and place you inside the CI container in a bash session. This is what is run on Travis-CI.
156
167
 
157
- Run `docker-compose build tests` to build the tests container. Run `docker-compose run tests` to start all rspec tests.
168
+ Run `docker-compose build tests` to build the tests container. Run `docker-compose run tests` to start all RSpec tests.
@@ -33,6 +33,7 @@ module ReactOnRails
33
33
  gem("capybara", group: :test)
34
34
  gem("selenium-webdriver", group: :test)
35
35
  gem("coveralls", require: false)
36
+ gem("poltergeist")
36
37
  end
37
38
  end
38
39
  end
@@ -27,6 +27,8 @@ module.exports = {
27
27
  extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.scss', '.css', 'config.js'],
28
28
  alias: {
29
29
  lib: path.join(process.cwd(), 'app', 'lib'),
30
+ react: path.resolve('./node_modules/react'),
31
+ 'react-dom': path.resolve('./node_modules/react-dom'),
30
32
  },
31
33
  },
32
34
  plugins: [
@@ -11,6 +11,8 @@ require_relative "spec_helper"
11
11
  require "rspec/rails"
12
12
  require "capybara/rspec"
13
13
  require "capybara/rails"
14
+ require "capybara/poltergeist"
15
+ Capybara.javascript_driver = :poltergeist
14
16
 
15
17
  # Requires supporting ruby files with custom matchers and macros, etc, in
16
18
  # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
@@ -1,4 +1,4 @@
1
- import * as actionTypes from '../constants/helloWorldConstants';
1
+ import actionTypes from '../constants/helloWorldConstants';
2
2
 
3
3
  export function updateName(name) {
4
4
  return {
@@ -11,9 +11,11 @@ export default class HelloWorldWidget extends React.Component {
11
11
  // We prefix all property and variable names pointing to Immutable.js objects with '$$'.
12
12
  // This allows us to immediately know we don't call $$helloWorldStore['someProperty'], but instead use
13
13
  // the Immutable.js `get` API for Immutable.Map
14
- actions: PropTypes.object.isRequired,
14
+ actions: PropTypes.shape({
15
+ updateName: PropTypes.func.isRequired,
16
+ }).isRequired,
15
17
  $$helloWorldStore: PropTypes.instanceOf(Immutable.Map).isRequired,
16
- }
18
+ };
17
19
 
18
20
  constructor(props, context) {
19
21
  super(props, context);
@@ -1,8 +1,13 @@
1
1
  // See https://www.npmjs.com/package/mirror-creator
2
- // Allows us to easily setup constants inside of
2
+ // Allows us to set up constants in a slightly more concise syntax. See:
3
3
  // client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
4
4
  import mirrorCreator from 'mirror-creator';
5
5
 
6
- export default mirrorCreator([
6
+ const actionTypes = mirrorCreator([
7
7
  'HELLO_WORLD_NAME_UPDATE',
8
8
  ]);
9
+
10
+ // actionTypes = {HELLO_WORLD_NAME_UPDATE: "HELLO_WORLD_NAME_UPDATE"}
11
+ // Notice how we don't have to duplicate HELLO_WORLD_NAME_UPDATE twice
12
+ // thanks to mirror-creator.
13
+ export default actionTypes;
@@ -18,7 +18,7 @@ class HelloWorld extends React.Component {
18
18
 
19
19
  // This corresponds to the value used in function select above.
20
20
  $$helloWorldStore: PropTypes.instanceOf(Immutable.Map).isRequired,
21
- }
21
+ };
22
22
 
23
23
  constructor(props, context) {
24
24
  super(props, context);
@@ -32,7 +32,7 @@ class HelloWorld extends React.Component {
32
32
  // This is equivalent to:
33
33
  // <HelloWorldWidget $$helloWorldStore={$$helloWorldStore} actions={actions} />
34
34
  return (
35
- <HelloWorldWidget {...{$$helloWorldStore, actions}} />
35
+ <HelloWorldWidget {...{ $$helloWorldStore, actions }} />
36
36
  );
37
37
  }
38
38
  }
@@ -1,6 +1,6 @@
1
1
  import Immutable from 'immutable';
2
2
 
3
- import * as actionTypes from '../constants/helloWorldConstants';
3
+ import actionTypes from '../constants/helloWorldConstants';
4
4
 
5
5
  export const $$initialState = Immutable.fromJS({
6
6
  name: '', // this is the default state that would be used if one were not passed into the store
@@ -10,10 +10,10 @@ export default function helloWorldReducer($$state = $$initialState, action) {
10
10
  const { type, name } = action;
11
11
 
12
12
  switch (type) {
13
- case actionTypes.HELLO_WORLD_NAME_UPDATE:
14
- return $$state.set('name', name);
13
+ case actionTypes.HELLO_WORLD_NAME_UPDATE:
14
+ return $$state.set('name', name);
15
15
 
16
- default:
17
- return $$state;
16
+ default:
17
+ return $$state;
18
18
  }
19
19
  }
@@ -20,7 +20,7 @@ export default props => {
20
20
  // Redux expects to initialize the store using an Object, not an Immutable.Map
21
21
  const initialState = {
22
22
  $$helloWorldStore: $$helloWorldState.merge({
23
- name: name,
23
+ name,
24
24
  }),
25
25
  };
26
26
 
@@ -1,17 +1,12 @@
1
+ require_relative "version_checker"
2
+
1
3
  module ReactOnRails
2
4
  def self.configure
3
5
  yield(configuration)
4
6
  end
5
7
 
6
- # TODO ROB
7
- # parse the client/package.json and ensure that either:
8
- # 1. version number matches
9
- # 2. version number is a relative path (for testing)
10
- # Throw error if not.
11
- # Allow skipping this check in the configuration in case somebody has a wacky configuration, such
12
- # as you don't know where their package.json
13
-
14
8
  def self.configuration
9
+ VersionChecker.warn_if_gem_and_node_package_versions_differ
15
10
  @configuration ||= Configuration.new(
16
11
  server_bundle_js_file: "app/assets/javascripts/generated/server.js",
17
12
  prerender: false,
@@ -22,7 +17,6 @@ module ReactOnRails
22
17
  development_mode: Rails.env.development?,
23
18
  server_renderer_pool_size: 1,
24
19
  server_renderer_timeout: 20)
25
- # TODO ROB: do the version check
26
20
  end
27
21
 
28
22
  class Configuration
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "2.0.0.beta.2"
2
+ VERSION = "2.0.0.beta.3"
3
3
  end
@@ -0,0 +1,52 @@
1
+ require_relative "version"
2
+
3
+ module ReactOnRails
4
+ module VersionChecker
5
+ # TODO: ROB
6
+ # parse the client/package.json and ensure that either:
7
+ # 1. version number matches
8
+ # 2. version number is a relative path (for testing)
9
+ # Throw error if not.
10
+ # Allow skipping this check in the configuration in case somebody has a wacky configuration, such
11
+ # as you don't know where their package.json
12
+
13
+ # For compatibility, the gem and the node package versions should always match, unless the user
14
+ # really knows what they're doing. So we will give a warning if they do not.
15
+ def self.warn_if_gem_and_node_package_versions_differ
16
+ return unless
17
+ File.exist?(client_package_json) &&
18
+ node_package_version_is_standard_version_number? &&
19
+ gem_version != node_package_version
20
+ msg = "**WARNING** ReactOnRails: ReactOnRails gem and node package versions do not match\n" \
21
+ " gem: #{gem_version}\n" \
22
+ " node package: #{node_package_version}\n" \
23
+ "Ensure the installed version of the gem is the same as the version of your installed node package"
24
+ puts(msg)
25
+ Rails.logger.warn(msg)
26
+ end
27
+
28
+ private
29
+
30
+ def self.gem_version
31
+ ReactOnRails::VERSION
32
+ end
33
+
34
+ # Warning: we replace all hyphens with periods for normalization purposes
35
+ def self.node_package_version
36
+ package_json = client_package_json
37
+ contents = File.read(package_json)
38
+ raw_version = contents.match(/"react-on-rails": "(.*)",/)[1]
39
+ raw_version.tr("-", ".")
40
+ end
41
+
42
+ def self.client_package_json
43
+ package_json = Rails.root.join("client", "package.json")
44
+ end
45
+
46
+ # Basically this means "not a relative path" as we don't want warn the user
47
+ # if they are purposely doing some wacky configuration.
48
+ def self.node_package_version_is_standard_version_number?
49
+ node_package_version =~ (/\d+\.\d+\.\d+(\..+\.\d+)?/)
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.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": {
@@ -42,6 +42,7 @@
42
42
  "scripts": {
43
43
  "test": "node_package/scripts/test",
44
44
  "clean": "node_package/scripts/clean",
45
+ "symlink-node-package": "node_package/scripts/symlink-node-package",
45
46
  "prepublish": "npm run build",
46
47
  "build": "node_package/scripts/build",
47
48
  "lint": "node_package/scripts/lint && cd spec/dummy/client && npm run lint",
@@ -71,7 +71,9 @@ namespace :examples do
71
71
 
72
72
  # PREPARE
73
73
  desc "Prepares #{example_type.name_pretty} (generates example, `npm install`s, and generates webpack bundles)"
74
- multitask example_type.prepare_task_name_short => example_type.prepared_files
74
+ multitask example_type.prepare_task_name_short => example_type.prepared_files do
75
+ Rake::Task[:refresh_node_package].invoke
76
+ end
75
77
  end
76
78
 
77
79
  desc "Cleans all example apps"
@@ -7,7 +7,7 @@ example_type_data:
7
7
  generator_options: --server-rendering
8
8
  -
9
9
  name: redux
10
- generator_options: --redux --server-rendering
10
+ generator_options: --redux
11
11
  -
12
12
  name: redux-server-rendering
13
13
  generator_options: --redux --server-rendering
@@ -16,4 +16,4 @@ example_type_data:
16
16
  generator_options: --heroku-deployment
17
17
  -
18
18
  name: skip-bootstrap
19
- generator_options: --skip-bootstrap
19
+ generator_options: --skip-bootstrap
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: 2.0.0.beta.2
4
+ version: 2.0.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-31 00:00:00.000000000 Z
11
+ date: 2016-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -234,6 +234,7 @@ files:
234
234
  - lib/react_on_rails/prerender_error.rb
235
235
  - lib/react_on_rails/server_rendering_pool.rb
236
236
  - lib/react_on_rails/version.rb
237
+ - lib/react_on_rails/version_checker.rb
237
238
  - package.json
238
239
  - rakelib/docker.rake
239
240
  - rakelib/dummy_apps.rake