react_on_rails 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +4 -0
  3. data/.gitignore +2 -1
  4. data/.npmignore +2 -0
  5. data/.rubocop.yml +2 -3
  6. data/CHANGELOG.md +50 -19
  7. data/README.md +37 -4
  8. data/app/helpers/react_on_rails_helper.rb +6 -6
  9. data/docs/additional_reading/rspec_configuration.md +10 -0
  10. data/docs/additional_reading/turbolinks.md +39 -0
  11. data/docs/additional_reading/updating-dependencies.md +33 -0
  12. data/docs/coding-style/style.md +0 -1
  13. data/docs/contributing.md +2 -1
  14. data/docs/doctrine.md +78 -0
  15. data/docs/recommended-project-structure.md +22 -0
  16. data/docs/releasing.md +59 -27
  17. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  18. data/lib/generators/react_on_rails/generator_messages.rb +1 -1
  19. data/lib/generators/react_on_rails/install_generator.rb +1 -11
  20. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +29 -28
  21. data/lib/generators/react_on_rails/templates/base/base/client/server.js +14 -6
  22. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js +4 -2
  23. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +2 -2
  24. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -0
  25. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +1 -1
  26. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +3 -5
  27. data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +3 -5
  28. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +4 -3
  29. data/lib/react_on_rails.rb +11 -0
  30. data/lib/react_on_rails/configuration.rb +15 -13
  31. data/lib/react_on_rails/engine.rb +0 -2
  32. data/lib/react_on_rails/ensure_assets_compiled.rb +31 -0
  33. data/lib/react_on_rails/git_utils.rb +12 -0
  34. data/lib/react_on_rails/utils.rb +7 -0
  35. data/lib/react_on_rails/version.rb +1 -1
  36. data/lib/react_on_rails/version_checker.rb +0 -3
  37. data/lib/react_on_rails/version_syntax_converter.rb +3 -5
  38. data/npm-shrinkwrap.json +4253 -0
  39. data/package.json +20 -16
  40. data/rakelib/example_type.rb +5 -6
  41. data/rakelib/examples.rake +1 -0
  42. data/rakelib/lint.rake +2 -2
  43. data/rakelib/release.rake +70 -0
  44. data/rakelib/run_rspec.rake +17 -8
  45. data/rakelib/task_helpers.rb +3 -3
  46. data/react_on_rails.gemspec +2 -2
  47. data/script/release +1 -1
  48. metadata +14 -4
@@ -0,0 +1,22 @@
1
+ # Project structure
2
+
3
+ While React On Rails does not *enforce* a specific project structure, we do *recommend* a standard organization. The more we follow standards as a community, the easier it will be for all of us to move between various Rails projects that include React On Rails.
4
+
5
+ 1. `/client`: All client side JavaScript goes under the `/client` directory. Place all the major domains of the client side app under client.
6
+ 1. `/client/app`: All application JavaScript. Note the adherence to the [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript#naming-conventions) where we name the files to correspond to exported Objects (PascalCase) or exported functions (camelCase). We don't use dashes or snake_case for JavaScript files, except for possibly some config files.
7
+ 1. `/client/app/bundles`: Top level of different app domains. Use a name within this directory for you app domains. For example, if you had a domain called `widget-editing`, then you would have: `/client/app/bundles/widget-editing`
8
+ 1. `/client/app/lib`: Common code for bundles
9
+ 1. Within each bundle directory (or the lib directory), such as a domain named "comments"
10
+ `/client/app/bundle/comments`, use following directory structure:
11
+
12
+ * `/actions`: Redux actions.
13
+ * `/components`: "dumb" components (no connections to Redux or Ajax). These get props and can render themselves and children.
14
+ * `/constants`: Constants used by Redux actions and reducers.
15
+ * `/containers`: "smart" components. These components are bound to Redux.
16
+ * `/reducers`: Reducers for redux.
17
+ * `/routes`: Routes for React Router.
18
+ * `/store`: Store, which might be [configured differently for dev vs. production](https://github.com/rackt/redux/tree/master/examples/real-world/store).
19
+ * `/startup`: Component bindings to stores, with registration of components and stores.
20
+ * `/schemas`: Schemas for AJAX JSON requests and responses, as used by the [Normalizr](https://github.com/gaearon/normalizr) package.
21
+ 1. `/client/app/assets`: Assets for CSS for client app.
22
+ 1. `/client/app/assets/fonts` and `/client/app/assets/styles`: Globally shared assets for styling. Note, most Sass and image assets will be stored next to the JavaScript files.
@@ -6,39 +6,71 @@ We're now releasing this as a combined ruby gem plus npm package. We will keep t
6
6
  See [Contributing](../contributing.md)
7
7
 
8
8
  ## Releasing a new gem version
9
- Install https://github.com/svenfuchs/gem-release
10
-
11
- ```bash
12
- # Having the examples prevents publishing
13
- rm -rf examples
14
- gem bump
15
- # Or manually update the version number
16
- cd spec/dummy
17
- # Update the Gemfile.lock of the tests
18
- bundle
19
- git commit -am "Updated Gemfile.lock"
20
- cd ../..
21
- gem tag
22
- gem release
9
+ Run `rake -D release` to see instructions on how to release via the rake task.
10
+
11
+
12
+ As of 01-26-2016, this would give you an output like this:
13
+
23
14
  ```
15
+ rake release[gem_version,dry_run,tools_install]
16
+ Releases both the gem and node package using the given version.
24
17
 
18
+ IMPORTANT: the gem version must be in valid rubygem format (no dashes).
19
+ It will be automatically converted to a valid npm semver by the rake task
20
+ for the node package version. This only makes a difference for pre-release
21
+ versions such as `3.0.0.beta.1` (npm version would be `3.0.0-beta.1`).
25
22
 
26
- ## Releasing a npm version
27
- Be sure to keep the version number the same as the ruby gem!
23
+ This task will also globally install gem-release (ruby gem) and
24
+ release-it (node package) unless you specify skip installing tools.
28
25
 
29
- Use the npm package `release-it`
26
+ 2nd argument: Perform a dry run by passing 'true' as a second argument.
27
+ 3rd argument: Skip installing tools by passing 'false' as a third argument (default is true).
30
28
 
31
- ### Commands Used for Pushing Beta
29
+ Example: `rake release[2.1.0,false,false]`
30
+ ```
32
31
 
33
- Note the npm beta version has a dash and the gem version has a dot.
32
+ Running `rake release[2.1.0]` will create a commit that looks like this:
34
33
 
35
34
  ```
36
- gem bump -v 2.0.0.beta.3
37
- gem tag
38
- cd spec/dummy && bundle
39
- ga Gemfile.lock
40
- gc -m "Update Gemfile.lock for spec/dummy"
41
- ...
42
- gem release
43
- release-it 2.0.0-beta.3
35
+ commit d07005cde9784c69e41d73fb9a0ebe8922e556b3
36
+ Author: Rob Wise <robert.wise@outlook.com>
37
+ Date: Tue Jan 26 19:49:14 2016 -0500
38
+
39
+ Release 2.1.0
40
+
41
+ diff --git a/lib/react_on_rails/version.rb b/lib/react_on_rails/version.rb
42
+ index 3de9606..b71aa7a 100644
43
+ --- a/lib/react_on_rails/version.rb
44
+ +++ b/lib/react_on_rails/version.rb
45
+ @@ -1,3 +1,3 @@
46
+ module ReactOnRails
47
+ - VERSION = "2.0.2".freeze
48
+ + VERSION = "2.1.0".freeze
49
+ end
50
+ diff --git a/package.json b/package.json
51
+ index aa7b000..af8761e 100644
52
+ --- a/package.json
53
+ +++ b/package.json
54
+ @@ -1,6 +1,6 @@
55
+ {
56
+ "name": "react-on-rails",
57
+ - "version": "2.0.2",
58
+ + "version": "2.1.0",
59
+ "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
60
+ "main": "node_package/lib/ReactOnRails.js",
61
+ "directories": {
62
+ diff --git a/spec/dummy/Gemfile.lock b/spec/dummy/Gemfile.lock
63
+ index 8ef51df..4489bfe 100644
64
+ --- a/spec/dummy/Gemfile.lock
65
+ +++ b/spec/dummy/Gemfile.lock
66
+ @@ -1,7 +1,7 @@
67
+ PATH
68
+ remote: ../..
69
+ specs:
70
+ - react_on_rails (2.0.2)
71
+ + react_on_rails (2.1.0)
72
+ connection_pool
73
+ execjs (~> 2.5)
74
+ rails (>= 3.2)
75
+ (END)
44
76
  ```
@@ -24,7 +24,7 @@ module ReactOnRails
24
24
  package_json = File.join(destination_root, "client", "package.json")
25
25
  old_contents = File.read(package_json)
26
26
  new_contents = old_contents.gsub(/"react-on-rails": ".+",/,
27
- '"react-on-rails": "../../..",')
27
+ '"react-on-rails": "../../../..",')
28
28
  File.open(package_json, "w+") { |f| f.puts new_contents }
29
29
  end
30
30
 
@@ -29,7 +29,7 @@ module GeneratorMessages
29
29
  end
30
30
 
31
31
  def format_info(msg)
32
- Rainbow("#{msg}").green
32
+ Rainbow(msg.to_s).green
33
33
  end
34
34
 
35
35
  def clear
@@ -59,7 +59,6 @@ module ReactOnRails
59
59
  else
60
60
  error = "react_on_rails generator prerequisites not met!"
61
61
  GeneratorMessages.add_error(error)
62
- # fail("react_on_rails generator prerequisites not met!")
63
62
  end
64
63
  ensure
65
64
  print_generator_messages
@@ -87,7 +86,7 @@ module ReactOnRails
87
86
  # js(.coffee) are not checked by this method, but instead produce warning messages
88
87
  # and allow the build to continue
89
88
  def installation_prerequisites_met?
90
- !(missing_node? || missing_npm? || uncommitted_changes?)
89
+ !(missing_node? || missing_npm? || ReactOnRails::GitUtils.uncommitted_changes?(GeneratorMessages))
91
90
  end
92
91
 
93
92
  def missing_npm?
@@ -105,15 +104,6 @@ module ReactOnRails
105
104
  GeneratorMessages.add_error(error)
106
105
  true
107
106
  end
108
-
109
- def uncommitted_changes?
110
- return false if ENV["COVERAGE"]
111
- status = `git status`
112
- return false if status.include?("nothing to commit, working directory clean")
113
- error = "You have uncommitted code. Please commit or stash your changes before continuing"
114
- GeneratorMessages.add_error(error)
115
- true
116
- end
117
107
  end
118
108
  end
119
109
  end
@@ -38,40 +38,41 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "babel": "^6.3.26",
41
- "babel-cli": "^6.3.17",
42
- "babel-core": "^6.3.26",
43
- "babel-loader": "^6.2.0",
41
+ "babel-cli": "^6.4.5",
42
+ "babel-core": "^6.4.5",
43
+ "babel-loader": "^6.2.1",
44
44
  "babel-plugin-syntax-decorators": "^6.3.13",
45
45
  "babel-polyfill": "^6.3.14",
46
46
  "babel-preset-es2015": "^6.3.13",
47
47
  "babel-preset-react": "^6.3.13",
48
48
  "babel-preset-stage-0": "^6.3.13",
49
- "es5-shim": "^4.4.1",
49
+ "babel-types": "^6.4.5",
50
+ "es5-shim": "^4.5.0",
50
51
  "expose-loader": "^0.7.1",
51
52
  <%- if options.redux? -%>
52
- "immutable": "^3.7.5",
53
+ "immutable": "^3.7.6",
53
54
  <%- end -%>
54
55
  "imports-loader": "^0.6.5",
55
- "jquery": "^2.1.4",
56
+ "jquery": "^2.2.0",
56
57
  "jquery-ujs": "^1.1.0-1",
57
- "loader-utils": "^0.2.11",
58
- "lodash": "^3.10.1",
58
+ "loader-utils": "^0.2.12",
59
+ "lodash": "^4.0.0",
59
60
  <%- if options.redux? -%>
60
- "mirror-creator": "0.0.1",
61
+ "mirror-creator": "1.0.0",
61
62
  <%- end -%>
62
- "react": "^0.14.3",
63
+ "react": "^0.14.6",
63
64
  <%- unless options.skip_bootstrap? -%>
64
- "react-bootstrap": "^0.28.1",
65
+ "react-bootstrap": "^0.28.2",
65
66
  <%- end -%>
66
- "react-dom": "^0.14.3",
67
+ "react-dom": "^0.14.6",
67
68
  "react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
68
69
  <%- if options.redux? -%>
69
- "react-redux": "^4.0.5",
70
- "redux": "^3.0.5",
71
- "redux-promise": "^0.5.0",
72
- "redux-thunk": "^1.0.2",
70
+ "react-redux": "^4.0.6",
71
+ "redux": "^3.0.6",
72
+ "redux-promise": "^0.5.1",
73
+ "redux-thunk": "^1.0.3",
73
74
  <%- end -%>
74
- "webpack": "^1.12.8"
75
+ "webpack": "^1.12.12"
75
76
  },
76
77
  "devDependencies": {
77
78
  <%- unless options.skip_js_linters? -%>
@@ -79,27 +80,27 @@
79
80
  <%- end -%>
80
81
  "babel-plugin-react-transform": "^2.0.0",
81
82
  <%- unless options.skip_bootstrap? -%>
82
- "bootstrap-sass": "^3.3.5",
83
- "bootstrap-sass-loader": "^1.0.9",
83
+ "bootstrap-sass": "^3.3.6",
84
+ "bootstrap-sass-loader": "^1.0.10",
84
85
  <%- end -%>
85
- "css-loader": "^0.23.0",
86
+ "css-loader": "^0.23.1",
86
87
  <%- unless options.skip_js_linters? -%>
87
88
  "eslint": "^1.10.3",
88
- "eslint-config-airbnb": "^2.0.0",
89
- "eslint-config-shakacode": "^0.0.1",
90
- "eslint-plugin-react": "^3.11.3",
89
+ "eslint-config-airbnb": "^4.0.0",
90
+ "eslint-config-shakacode": "^1.0.0",
91
+ "eslint-plugin-react": "^3.16.1",
91
92
  <%- end -%>
92
- "express": "^4.13.3",
93
- "file-loader": "^0.8.4",
93
+ "express": "^4.13.4",
94
+ "file-loader": "^0.8.5",
94
95
  "jade": "^1.11.0",
95
96
  <%- unless options.skip_js_linters? -%>
96
97
  "jscs": "^2.8.0",
97
98
  <%- end -%>
98
99
  "node-sass": "^3.4.2",
99
100
  "react-transform-hmr": "^1.0.1",
100
- "sass-loader": "^3.1.1",
101
+ "sass-loader": "^3.1.2",
101
102
  "style-loader": "^0.13.0",
102
- "url-loader": "^0.5.6",
103
- "webpack-dev-server": "^1.12.1"
103
+ "url-loader": "^0.5.7",
104
+ "webpack-dev-server": "^1.14.1"
104
105
  }
105
106
  }
@@ -6,7 +6,10 @@ var WebpackDevServer = require('webpack-dev-server');
6
6
  var jade = require('jade');
7
7
  var config = require('./webpack.client.hot.config');
8
8
 
9
- var server = new WebpackDevServer(webpack(config), {
9
+ const PORT = 4000;
10
+ const compiler = webpack(config);
11
+
12
+ var server = new WebpackDevServer(compiler, {
10
13
  publicPath: config.output.publicPath,
11
14
  hot: true,
12
15
  historyApiFallback: true,
@@ -49,16 +52,21 @@ var server = new WebpackDevServer(webpack(config), {
49
52
 
50
53
  var initialName = 'Stranger';
51
54
 
52
- server.app.use('/', function routePath(req, res) {
55
+ server.app.use('/', (req, res) => {
53
56
  var locals = {
54
57
  props: JSON.stringify(initialName),
55
58
  };
56
- var layout = process.cwd() + '/index.jade';
59
+ var layout = `${process.cwd()}/index.jade`;
57
60
  var html = jade.compileFile(layout, { pretty: true })(locals);
58
61
  res.send(html);
59
62
  });
60
63
 
61
- server.listen(4000, 'localhost', function onListen(err) {
62
- if (err) console.log(err);
63
- console.log('Listening at localhost:4000...');
64
+ server.listen(PORT, 'localhost', err => {
65
+ if (err) console.error(err);
66
+ console.log(
67
+ '=> 🔥 Webpack development server is running on port ' + PORT
68
+ );
69
+ });
70
+ compiler.plugin('done', () => {
71
+ process.stdout.write('Webpack: Done compiling assets!\n');
64
72
  });
@@ -18,7 +18,8 @@ module.exports = {
18
18
  'jquery',
19
19
  ],
20
20
 
21
- // This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
21
+ // This will contain the app entry points defined by webpack.hot.config and
22
+ // webpack.rails.config
22
23
  app: [
23
24
  './app/bundles/HelloWorld/startup/clientRegistration',
24
25
  ],
@@ -55,7 +56,8 @@ module.exports = {
55
56
  module: {
56
57
  loaders: [
57
58
 
58
- // Not all apps require jQuery. Many Rails apps do, such as those using TurboLinks or bootstrap js
59
+ // Not all apps require jQuery. Many Rails apps do, such as those using TurboLinks or
60
+ // bootstrap js
59
61
  { test: require.resolve('jquery'), loader: 'expose?jQuery' },
60
62
  { test: require.resolve('jquery'), loader: 'expose?$' },
61
63
  ],
@@ -54,8 +54,8 @@ config.module.loaders.push(
54
54
  { test: /\.css$/, loader: 'style-loader!css-loader' },
55
55
  {
56
56
  test: /\.scss$/,
57
- loader: 'style!css!sass?outputStyle=expanded&imagePath=/assets/images&includePaths[]=' +
58
- path.resolve(__dirname, './assets/stylesheets'),
57
+ loader: `style!css!sass?outputStyle=expanded&imagePath=/assets/images&includePaths[]=\
58
+ ${path.resolve(__dirname, './assets/stylesheets')}`,
59
59
  },
60
60
 
61
61
  // The url-loader uses DataUrls. The file-loader emits files.
@@ -23,4 +23,6 @@ ReactOnRails.configure do |config|
23
23
  config.prerender = false
24
24
  # Default is true for development, off otherwise
25
25
  config.trace = Rails.env.development?
26
+ # Default is false, enable if your content security policy doesn't include `style-src: 'unsafe-inline'`
27
+ config.skip_display_none = false
26
28
  end
@@ -10,7 +10,7 @@ if ENV["COVERAGE"]
10
10
  SimpleCov.start("rails") do
11
11
  # Consider the entire gem project as the root
12
12
  # (typically this will be the folder named "react_on_rails")
13
- gem_root_path = File.expand_path("../../../../.", __FILE__)
13
+ gem_root_path = File.expand_path("../../../../../.", __FILE__)
14
14
  root gem_root_path
15
15
 
16
16
  # Don't report anything that has "spec" in the path
@@ -1,8 +1,6 @@
1
1
  import React from 'react';
2
2
  import HelloWorld from '../containers/HelloWorld';
3
3
 
4
- export default (props) => {
5
- return (
6
- <HelloWorld {...props} />
7
- );
8
- };
4
+ export default (props) => (
5
+ <HelloWorld {...props} />
6
+ );
@@ -1,8 +1,6 @@
1
1
  import React from 'react';
2
2
  import HelloWorld from '../containers/HelloWorld';
3
3
 
4
- export default (props) => {
5
- return (
6
- <HelloWorld {...props} />
7
- );
8
- };
4
+ export default (props) => (
5
+ <HelloWorld {...props} />
6
+ );
@@ -1,8 +1,9 @@
1
1
  import { compose, createStore, applyMiddleware, combineReducers } from 'redux';
2
2
 
3
- // See https://github.com/gaearon/redux-thunk and http://redux.js.org/docs/advanced/AsyncActions.html
4
- // This is not actually used for this simple example, but you'd probably want to use this once your app has
5
- // asynchronous actions.
3
+ // See
4
+ // https://github.com/gaearon/redux-thunk and http://redux.js.org/docs/advanced/AsyncActions.html
5
+ // This is not actually used for this simple example, but you'd probably want to use this
6
+ // once your app has asynchronous actions.
6
7
  import thunkMiddleware from 'redux-thunk';
7
8
 
8
9
  // This provides an example of logging redux actions to the console.
@@ -1,6 +1,17 @@
1
1
  require "rails"
2
2
 
3
3
  require "react_on_rails/version"
4
+ require "react_on_rails/version_checker"
4
5
  require "react_on_rails/configuration"
5
6
  require "react_on_rails/server_rendering_pool"
6
7
  require "react_on_rails/engine"
8
+ require "react_on_rails/version_syntax_converter"
9
+ require "react_on_rails/ensure_assets_compiled"
10
+ require "react_on_rails/git_utils"
11
+ require "react_on_rails/utils"
12
+
13
+ module ReactOnRails
14
+ def self.configure_rspec_to_compile_assets(config, metatag = :js)
15
+ config.before(:example, metatag) { ReactOnRails::EnsureAssetsCompiled.check_built_assets }
16
+ end
17
+ end
@@ -14,35 +14,37 @@ module ReactOnRails
14
14
  trace: Rails.env.development?,
15
15
  development_mode: Rails.env.development?,
16
16
  server_renderer_pool_size: 1,
17
- server_renderer_timeout: 20)
17
+ server_renderer_timeout: 20,
18
+ skip_display_none: false)
18
19
  end
19
20
 
20
21
  class Configuration
21
22
  attr_accessor :server_bundle_js_file, :prerender, :replay_console,
22
23
  :trace, :development_mode,
23
24
  :logging_on_server, :server_renderer_pool_size,
24
- :server_renderer_timeout, :raise_on_prerender_error
25
+ :server_renderer_timeout, :raise_on_prerender_error,
26
+ :skip_display_none
25
27
 
26
28
  def initialize(server_bundle_js_file: nil, prerender: nil, replay_console: nil,
27
29
  trace: nil, development_mode: nil,
28
30
  logging_on_server: nil, server_renderer_pool_size: nil,
29
- server_renderer_timeout: nil, raise_on_prerender_error: nil)
30
- if File.exist?(server_bundle_js_file)
31
- self.server_bundle_js_file = server_bundle_js_file
32
- else
33
- self.server_bundle_js_file = nil
34
- end
31
+ server_renderer_timeout: nil, raise_on_prerender_error: nil,
32
+ skip_display_none: nil)
33
+ self.server_bundle_js_file = if File.exist?(server_bundle_js_file)
34
+ server_bundle_js_file
35
+ end
35
36
 
36
37
  self.prerender = prerender
37
38
  self.replay_console = replay_console
38
39
  self.logging_on_server = logging_on_server
39
- if development_mode.nil?
40
- self.development_mode = Rails.env.development?
41
- else
42
- self.development_mode = development_mode
43
- end
40
+ self.development_mode = if development_mode.nil?
41
+ Rails.env.development?
42
+ else
43
+ development_mode
44
+ end
44
45
  self.trace = trace.nil? ? Rails.env.development? : trace
45
46
  self.raise_on_prerender_error = raise_on_prerender_error
47
+ self.skip_display_none = skip_display_none
46
48
 
47
49
  # Server rendering:
48
50
  self.server_renderer_pool_size = self.development_mode ? 1 : server_renderer_pool_size