Skip to content

Commit e7d068c

Browse files
Added OS detection for install generator, system call for Windows and unit-tests for it.
1 parent 13cff3f commit e7d068c

File tree

33 files changed

+527
-99
lines changed

33 files changed

+527
-99
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ env:
2525
- DRIVER=selenium_chrome
2626
- CHROME_BIN=/usr/bin/google-chrome
2727
- ENABLE_TURBOLINKS_5=TRUE
28+
- USE_COVERALLS=TRUE
2829

2930
before_install:
3031
- sudo apt-get update

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
55

66
## [Unreleased]
77
*Please add entries here for your pull requests.*
8+
### Fixed
9+
- Added OS detection for install generator, system call for Windows and unit-tests for it. [#666](https://github.com/shakacode/react_on_rails/pull/666) by [GeorgeGorbanev](https://github.com/GeorgeGorbanev).
10+
11+
## [6.4.0] - 2017-1-12
12+
13+
### Fixed
14+
- Removed foreman as a dependency. [#678](https://github.com/shakacode/react_on_rails/pull/678) by [x2es](https://github.com/x2es).
15+
16+
### Added
17+
- Automatically generate __i18n__ javascript files for `react-intl` when the serve starts up. [#642](https://github.com/shakacode/react_on_rails/pull/642) by [JasonYCHuang](https://github.com/JasonYCHuang).
18+
19+
## [6.3.5] - 2017-1-6
20+
### Fixed
21+
- The redux generator now creates a HelloWorld component that uses redux rather than local state. [#669](https://github.com/shakacode/react_on_rails/issues/669) by [justin808](https://github.com/justin808).
822

923
## [6.3.4] - 2016-12-25
1024
##### Fixed
@@ -413,7 +427,9 @@ Best done with Object destructing:
413427
##### Fixed
414428
- Fix several generator related issues.
415429

416-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.3.4...master
430+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.4.0...master
431+
[6.4.0]: https://github.com/shakacode/react_on_rails/compare/6.3.5...6.4.0
432+
[6.3.5]: https://github.com/shakacode/react_on_rails/compare/6.3.4...6.3.5
417433
[6.3.4]: https://github.com/shakacode/react_on_rails/compare/6.3.3...6.3.4
418434
[6.3.3]: https://github.com/shakacode/react_on_rails/compare/6.3.2...6.3.3
419435
[6.3.2]: https://github.com/shakacode/react_on_rails/compare/6.3.1...6.3.2

CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ npm install -g phantomjs
126126

127127
Note this *must* be installed globally for the dummy test project rspec runner to see it properly.
128128

129-
### NPM link
130-
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:
129+
### Local Node Package
130+
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 teat app's root directory and run this command below which runs something like [this script](spec/dummy/package.json#L14)
131131

132132
```sh
133-
npm run node_package
133+
npm run install-react-on-rails
134134
```
135135

136136
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.
@@ -141,6 +141,7 @@ From now on, the example and dummy apps will use your local node_package folder
141141
resolve: {
142142
alias: {
143143
react: path.resolve('./node_modules/react'),
144+
'react-dom': path.resolve('./node_modules/react-dom'),
144145
},
145146
},
146147
```
@@ -182,11 +183,11 @@ npm run test
182183

183184
```sh
184185
cd <top level>
185-
node_package/scripts/ci
186+
npm run check
186187
```
187188

188189
### Starting the Dummy App
189-
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.
190+
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 `npm run build`. Since the react-on-rails package should be sym linked, you don't have to `npm i react-on-rails` after every change.
190191

191192
### RSpec Testing
192193
Run `rake` for testing the gem and `spec/dummy`. Otherwise, the `rspec` command only works for testing within the sample apps, like `spec/dummy`.
@@ -217,7 +218,7 @@ The main installer can be run with ```rails generate react_on_rails:install```
217218
The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator_testing_script.md](generator_testing_script.md) for a script on how to run the generator on a fresh project.
218219

219220
### Linting
220-
All linting is performed from the docker container for CI. You will need docker and docker-compose installed locally to lint code changes via the lint container. You can lint locally by running `node_package/scripts/lint`
221+
All linting is performed from the docker container for CI. You will need docker and docker-compose installed locally to lint code changes via the lint container. You can lint locally by running `npm run lint && npm run flow`
221222

222223
* [Install Docker Toolbox for Mac](https://www.docker.com/toolbox)
223224
* [Install Docker Compose for Linux](https://docs.docker.com/compose/install/)

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gem "mini_racer"
2525
if ENV["ENABLE_TURBOLINKS_5"].nil? || ENV["ENABLE_TURBOLINKS_5"].strip.empty?
2626
gem "turbolinks", "2.5.3"
2727
else
28-
gem "turbolinks", "~> 5.0.0.beta"
28+
gem "turbolinks", "~> 5.0"
2929
end
3030
gem "uglifier", ">= 2.7.2"
3131
gem "web-console", "~> 2.0", group: :development

README.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
[![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Dependency Status](https://gemnasium.com/shakacode/react_on_rails.svg)](https://gemnasium.com/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master)
1+
[![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Codeship Status for shakacode/react_on_rails](https://app.codeship.com/projects/cec6c040-971f-0134-488f-0a5146246bd8/status?branch=master)](https://app.codeship.com/projects/187011) [![Dependency Status](https://gemnasium.com/shakacode/react_on_rails.svg)](https://gemnasium.com/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master)
22

33
**For a complete example of this gem, see our live demo at [www.reactrails.com](http://www.reactrails.com). ([Source Code](https://github.com/shakacode/react-webpack-rails-tutorial))**
44

5-
Aloha from Justin Gordon ([bio](http://www.railsonmaui.com/about)) and the [ShakaCode](http://www.shakacode.com) Team! We're actively looking for new projects involving React, React-Native, and Rails. Please contact me at [[email protected]](mailto:[email protected]) if we could potentially help you in any way. Besides consulting on bigger projects, [ShakaCode](http://www.shakacode.com) is doing ScreenHero plus Slack/Github based coaching for React on Rails. See our blog post [Can ShakaCode Help You?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) for more information.
5+
Aloha from Justin Gordon ([bio](http://www.railsonmaui.com/about)) and the [ShakaCode](http://www.shakacode.com) Team! We're actively looking for new projects involving React, React-Native, and Rails. Please [contact me](mailto:[email protected]) if we could potentially help you in any way. Besides consulting on bigger projects, [ShakaCode](http://www.shakacode.com) is doing ScreenHero plus Slack/Github based coaching for React on Rails. See our blog post [Can ShakaCode Help You?](https://blog.shakacode.com/can-shakacode-help-you-4a5b1e5a8a63#.jex6tg9w9) for more information.
66

7-
We're offering a free half-hour project consultation, on anything from React on Rails to any aspect of web application development for both consumer and enterprise products. In addition to React.js and Rails, we're doing React-Native iOS and Android apps!
7+
I'm offering a free half-hour project consultation, on anything from React on Rails to any aspect of web application development for both consumer and enterprise products. In addition to React.js and Rails, we're doing React-Native iOS and Android apps!
88

99
Whether you have a new project or need help on an existing project, feel free to contact me directly at [[email protected]](mailto:[email protected]) and thanks in advance for any referrals!
1010

1111
Your support keeps this project going.
1212

13-
(Want to become a contributor? [Contact us](mailto:[email protected]) for an Slack team invite! Also, see ["easy" issues](https://github.com/shakacode/react_on_rails/labels/easy) and [issues for the full tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy).)
13+
(Want to become a contributor? [Contact us](mailto:[email protected]) for a Slack team invite! Also, see ["easy" issues](https://github.com/shakacode/react_on_rails/labels/easy) and [issues for the full tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/issues?q=is%3Aissue+is%3Aopen+label%3Aeasy
1414

1515
Follow [@ShakaCode](https://twitter.com/shakacode) for notications of new releases.
1616

@@ -50,6 +50,7 @@ React on Rails integrates Facebook's [React](https://github.com/facebook/react)
5050
- [Installation Summary](#installation-summary)
5151
- [Initializer Configuration: config/initializers/react_on_rails.rb](#initializer-configuration)
5252
- [Including your React Component in your Rails Views](#including-your-react-component-in-your-rails-views)
53+
- [I18n](#i18n)
5354
+ [How it Works](#how-it-works)
5455
- [Client-Side Rendering vs. Server-Side Rendering](#client-side-rendering-vs-server-side-rendering)
5556
- [Building the Bundles](#building-the-bundles)
@@ -120,6 +121,8 @@ We're definitely not doing that. With react_on_rails, webpack is mainly generati
120121

121122
6. Start your Rails server:
122123

124+
with foreman installed (`gem install foreman`)
125+
123126
```bash
124127
foreman start -f Procfile.dev
125128
```
@@ -168,7 +171,15 @@ Configure the `config/initializers/react_on_rails.rb`. You can adjust some neces
168171
// inside your React component
169172
this.props.name // "Stranger"
170173
```
171-
174+
175+
### I18n
176+
177+
You can enable the i18n functionality with [react-intl](https://github.com/yahoo/react-intl).
178+
179+
React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.js` files for `react-intl`.
180+
181+
See the [How to add I18n](docs/basics/i18n.md) for a summary of adding I18n.
182+
172183
## NPM
173184
All JavaScript in React On Rails is loaded from npm: [react-on-rails](https://www.npmjs.com/package/react-on-rails). To manually install this (you did not use the generator), assuming you have a standard configuration, run this command:
174185
@@ -201,7 +212,9 @@ In the following screenshot you can see the 3 parts of React on Rails rendering:
201212
### Building the Bundles
202213
Each time you change your client code, you will need to re-generate the bundles (the webpack-created JavaScript files included in application.js). The included Foreman `Procfile.dev` will take care of this for you by watching your JavaScript code files for changes. Simply run `foreman start -f Procfile.dev`.
203214
204-
On Heroku deploys, the `lib/assets.rake` file takes care of running webpack during deployment. If you have used the provided generator, these bundles will automatically be added to your `.gitignore` in order to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator.
215+
On production deployments that use asset precompilation, such as Heroku deployments, React on Rails, by default, will automatically run webpack to build your JavaScript bundles. You can see the source code for what gets added to your precompilation [here](https://github.com/shakacode/react_on_rails/tree/master/lib/tasks/assets.rake). For more information on this topic, see [the doc on Heroku deployment](https://github.com/shakacode/react_on_rails/tree/master/docs/additional-reading/heroku-deployment.md#more-details-on-precompilation-using-webpack-to-create-javascript-assets).
216+
217+
If you have used the provided generator, these bundles will automatically be added to your `.gitignore` to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator.
205218
206219
### Rails Context
207220
When you use a "generator function" to create react components or you used shared redux stores, you get 2 params passed to your function:
@@ -241,11 +254,6 @@ The `railsContext` has: (see implementation in file [react_on_rails_helper.rb](a
241254
pathname: uri.path, # /posts
242255
search: uri.query, # id=30&limit=5
243256

244-
# Locale settings
245-
i18nLocale: I18n.locale,
246-
i18nDefaultLocale: I18n.default_locale,
247-
httpAcceptLanguage: request.env["HTTP_ACCEPT_LANGUAGE"],
248-
249257
# Other
250258
serverSide: boolean # Are we being called on the server or client? NOTE, if you conditionally
251259
# render something different on the server than the client, then React will only show the
@@ -257,9 +265,6 @@ The `railsContext` has: (see implementation in file [react_on_rails_helper.rb](a
257265
##### Needing the current url path for server rendering
258266
Suppose you want to display a nav bar with the current navigation link highlighted by the URL. When you server render the code, you will need to know the current URL/path if that is what you want your logic to be based on. The new `railsContext` has this information so the application of an "active" class can be done server side.
259267

260-
##### Needing the I18n.locale
261-
Suppose you want to server render your react components with localization applied given the current Rails locale. The `railsContext` contains the I18n.locale.
262-
263268
##### Configuring different code for server side rendering
264269
Suppose you want to turn off animation when doing server side rendering. The `serverSide` value is just what you need.
265270

Rakefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Rake will automatically load any *.rake files inside of the "rakelib" folder
22
# See rakelib/
3-
require "coveralls/rake/task"
4-
Coveralls::RakeTask.new
3+
tasks = %w(run_rspec lint)
4+
if ENV["USE_COVERALLS"] == "TRUE"
5+
require "coveralls/rake/task"
6+
Coveralls::RakeTask.new
7+
tasks << "coveralls:push"
8+
end
59

610
desc "Run all tests and linting"
7-
task default: ["run_rspec", "lint", "coveralls:push"]
11+
task default: tasks
812

913
desc "All actions but no examples. Good for local developer run."
1014
task all_but_examples: ["run_rspec:all_but_examples", "lint"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Foreman Issues
2+
3+
## It is not recomended to include foreman into Gemfile
4+
5+
See: https://github.com/ddollar/foreman
6+
7+
> Ruby users should take care not to install foreman in their project's Gemfile.
8+
9+
## Known issues
10+
11+
* With `foreman 0.82.0` npm `react-s3-uploader` was failing to finish upload file to S3 when server was started by `foreman -f Procfile.dev`,
12+
at the same time the same code works fine when ruby server started by `bundle exec rails s`.
13+
14+
* The same Procfile with different versions of `foreman` in combination with different versions of `bundler` may produce different output of `ps aux`.
15+
This may brake bash tools which rely on `ps` output.

docs/basics/i18n.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# How to add I18n
2+
3+
Here's a summary of adding the I18n functionality.
4+
5+
You can refer to [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for a complete example.
6+
7+
1. Add `react-intl` & `intl` to `client/package.json`, and remember to `bundle && npm install`.
8+
9+
```js
10+
"dependencies": {
11+
...
12+
"intl": "^1.2.5",
13+
"react-intl": "^2.1.5",
14+
...
15+
}
16+
```
17+
18+
2. In `client/webpack.client.base.config.js`, set `react-intl` as an entry point.
19+
20+
```js
21+
module.exports = {
22+
...
23+
entry: {
24+
...
25+
vendor: [
26+
...
27+
'react-intl',
28+
],
29+
...
30+
```
31+
32+
3. `react-intl` requires locale files in json format. React on Rails will help you to generate or update `translations.js` & `default.js` automatically after you configured the following settings.
33+
34+
> `translations.js`: All your locales in json format.
35+
>
36+
> `default.js`: Default settings in json format.
37+
>
38+
> You can add them to `.gitignore` and `.eslintignore`.
39+
40+
Update settings in `config/initializers/react_on_rails.rb` to what you need:
41+
42+
```ruby
43+
# Replace the following line to the location where you keep translation.js & default.js.
44+
config.i18n_dir = Rails.root.join("PATH_TO", "YOUR_JS_I18N_FOLDER")
45+
```
46+
47+
Add following lines to `config/application.rb`, this will help you to generate `translations.js` & `default.js` automatically when you starts the server.
48+
49+
```js
50+
module YourModule
51+
class Application < Rails::Application
52+
...
53+
config.after_initialize do
54+
ReactOnRails::LocalesToJs.new
55+
end
56+
end
57+
end
58+
```
59+
60+
5. In React, you need to initialize `react-intl`, and set parameters for it.
61+
62+
```js
63+
...
64+
import { addLocaleData } from 'react-intl';
65+
import en from 'react-intl/locale-data/en';
66+
import de from 'react-intl/locale-data/de';
67+
import { translations } from 'path_to/i18n/translations';
68+
import { defaultLocale } from 'path_to/i18n/default';
69+
...
70+
// Initizalize all locales for react-intl.
71+
addLocaleData([...en, ...de]);
72+
...
73+
// set locale and messages for IntlProvider.
74+
const locale = method_to_get_current_locale() || defaultLocale;
75+
const messages = translations[locale];
76+
...
77+
return (
78+
<IntlProvider locale={locale} key={locale} messages={messages}>
79+
<CommentScreen {...{ actions, data }} />
80+
</IntlProvider>
81+
)
82+
```
83+
```js
84+
// In your component.
85+
import { defaultMessages } from 'path_to/i18n/default';
86+
...
87+
return (
88+
{ formatMessage(defaultMessages.yourLocaleKeyInCamelCase) }
89+
)
90+
```

lib/generators/react_on_rails/base_generator.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def create_react_directories
6565
def copy_base_files
6666
base_path = "base/base/"
6767
base_files = %w(app/controllers/hello_world_controller.rb
68-
client/app/bundles/HelloWorld/components/HelloWorld.jsx
6968
client/.babelrc
7069
client/webpack.config.js
7170
client/REACT_ON_RAILS_CLIENT_README.md)

lib/generators/react_on_rails/install_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def installation_prerequisites_met?
6464
end
6565

6666
def missing_npm?
67-
return false unless `which npm`.blank?
67+
return false unless ReactOnRails::Utils.running_on_windows? ? `where npm`.blank? : `which npm`.blank?
6868
error = "npm is required. Please install it before continuing. "
6969
error << "https://www.npmjs.com/"
7070
GeneratorMessages.add_error(error)
7171
true
7272
end
7373

7474
def missing_node?
75-
return false unless `which node`.blank?
75+
return false unless ReactOnRails::Utils.running_on_windows? ? `where node`.blank? : `which node`.blank?
7676
error = "** nodejs is required. Please install it before continuing. "
7777
error << "https://nodejs.org/en/"
7878
GeneratorMessages.add_error(error)

0 commit comments

Comments
 (0)