react_on_rails 1.1.1 → 1.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -0
  4. data/.travis.yml +2 -8
  5. data/Dockerfile_tests +1 -1
  6. data/Gemfile +68 -2
  7. data/README.md +21 -15
  8. data/Rakefile +3 -109
  9. data/app/assets/javascripts/react_on_rails.js +10 -0
  10. data/docker-compose.yml +0 -6
  11. data/docs/additional_reading/webpack.md +46 -0
  12. data/docs/generator_testing.md +20 -0
  13. data/lib/generators/react_on_rails/base_generator.rb +49 -9
  14. data/lib/generators/react_on_rails/bootstrap_generator.rb +14 -29
  15. data/lib/generators/react_on_rails/dev_tests_generator.rb +30 -0
  16. data/lib/generators/react_on_rails/install_generator.rb +14 -3
  17. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +2 -3
  18. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +26 -23
  19. data/lib/generators/react_on_rails/templates/base/base/client/{webpack.client.hot.config.js → webpack.client.hot.config.js.tt} +3 -1
  20. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/{assets.rake → assets.rake.tt} +2 -0
  21. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +1 -1
  22. data/lib/generators/react_on_rails/templates/dev_tests/.rspec +2 -0
  23. data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +25 -0
  24. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +57 -0
  25. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +21 -0
  26. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +95 -0
  27. data/lib/react_on_rails/version.rb +1 -1
  28. data/rakelib/docker.rake +33 -0
  29. data/rakelib/dummy_apps.rake +29 -0
  30. data/rakelib/example_type.rb +160 -0
  31. data/rakelib/examples.rake +103 -0
  32. data/rakelib/examples_config.yml +19 -0
  33. data/rakelib/lint.rake +37 -0
  34. data/rakelib/run_rspec.rake +65 -0
  35. data/rakelib/task_helpers.rb +44 -0
  36. data/ruby-lint.yml +1 -0
  37. metadata +22 -9
  38. data/Dockerfile_ci +0 -12
  39. data/docs/generator_testing_script.md +0 -49
  40. data/lib/generators/react_on_rails/templates/client/README.md +0 -97
@@ -0,0 +1,19 @@
1
+ example_type_data:
2
+ -
3
+ name: basic
4
+ generator_options: ""
5
+ -
6
+ name: basic-server-rendering
7
+ generator_options: --server-rendering
8
+ -
9
+ name: redux
10
+ generator_options: --redux --server-rendering
11
+ -
12
+ name: redux-server-rendering
13
+ generator_options: --redux --server-rendering
14
+ -
15
+ name: heroku-deployment
16
+ generator_options: --heroku-deployment
17
+ -
18
+ name: skip-bootstrap
19
+ generator_options: --skip-bootstrap
data/rakelib/lint.rake ADDED
@@ -0,0 +1,37 @@
1
+ require_relative "task_helpers"
2
+ include ReactOnRails::TaskHelpers
3
+
4
+ namespace :lint do
5
+ desc "Run Rubocop as shell"
6
+ task :rubocop do
7
+ sh_in_dir(gem_root, "rubocop .")
8
+ end
9
+
10
+ desc "Run ruby-lint as shell"
11
+ task :ruby do
12
+ sh_in_dir(gem_root, "ruby-lint app spec lib")
13
+ end
14
+
15
+ desc "Run scss-lint as shell"
16
+ task :scss do
17
+ sh_in_dir(gem_root, "scss-lint spec/dummy/app/assets/stylesheets/")
18
+ end
19
+
20
+ desc "Run eslint as shell"
21
+ task :eslint do
22
+ sh_in_dir(gem_root, "eslint . --ext .jsx and .js")
23
+ end
24
+
25
+ desc "Run jscs from shell"
26
+ task :jscs do
27
+ sh_in_dir(gem_root, "jscs -e -v .")
28
+ end
29
+
30
+ desc "Run all eslint, jscs, rubocop linters. Skip ruby-lint and scss"
31
+ task lint: [:eslint, :jscs, :rubocop] do
32
+ puts "Completed all linting"
33
+ end
34
+ end
35
+
36
+ desc "Runs all linters. Run `rake -D lint` to see all available lint options"
37
+ task lint: ["lint:lint"]
@@ -0,0 +1,65 @@
1
+ require "coveralls/rake/task"
2
+ require "pathname"
3
+
4
+ require_relative "task_helpers"
5
+ require_relative "example_type"
6
+
7
+ include ReactOnRails::TaskHelpers
8
+
9
+ namespace :run_rspec do
10
+ desc "Run RSpec for top level only"
11
+ task :gem do
12
+ run_tests_in("", rspec_args: "spec/react_on_rails")
13
+ end
14
+
15
+ desc "Run RSpec for spec/dummy only"
16
+ task dummy: ["dummy_apps:dummy_app"] do
17
+ run_tests_in("spec/dummy", env_vars: "DRIVER=selenium_firefox")
18
+ end
19
+
20
+ desc "Run RSpec for spec/dummy_react_013 only"
21
+ task dummy_react_013: ["dummy_apps:dummy_react_013_app"] do
22
+ run_tests_in("spec/dummy-react-013", env_vars: "DRIVER=selenium_firefox")
23
+ end
24
+
25
+ # Dynamically define Rake tasks for each example app found in the examples directory
26
+ ExampleType.all.each do |example_type|
27
+ desc "Runs RSpec for #{example_type.name_pretty} only"
28
+ task example_type.rspec_task_name_short => example_type.prepare_task_name do
29
+ run_tests_in("#{File.basename(examples_dir)}/#{example_type.name}") # have to use relative path
30
+ end
31
+ end
32
+
33
+ desc "Runs Rspec for example apps only"
34
+ task examples: "examples:prepare_all" do
35
+ ExampleType.all.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
36
+ end
37
+
38
+ desc "(HACK) Run RSpec on spec/empty_spec in order to have SimpleCov generate a coverage report from cache"
39
+ task :empty do
40
+ sh %(COVERAGE=true rspec spec/empty_spec.rb)
41
+ end
42
+
43
+ Coveralls::RakeTask.new
44
+
45
+ task run_rspec: [:gem, :dummy, :dummy_react_013, :examples, :empty, "coveralls:push"] do
46
+ puts "Completed all RSpec tests"
47
+ end
48
+ end
49
+
50
+ desc "Runs all tests. Run `rake -D run_rspec` to see all available test options"
51
+ task run_rspec: ["run_rspec:run_rspec"]
52
+
53
+ private
54
+
55
+ # Runs rspec in the given directory (if string is passed, assumed to be relative
56
+ # to root of the gem.
57
+ # TEST_ENV_COMMAND_NAME is used to make SimpleCov.command_name unique in order to
58
+ # prevent a name collision. Defaults to the given directory's name.
59
+ def run_tests_in(dir, options = {})
60
+ dir = Pathname.new(File.join(gem_root, dir)) if dir.is_a?(String)
61
+ command_name = options.fetch(:command_name, dir.basename)
62
+ rspec_args = options.fetch(:rspec_args, "")
63
+ env_vars = %(#{options.fetch(env_vars, '')} COVERAGE=true TEST_ENV_COMMAND_NAME="#{command_name}")
64
+ sh_in_dir(dir, "#{env_vars} bundle exec rspec #{rspec_args}")
65
+ end
@@ -0,0 +1,44 @@
1
+ module ReactOnRails
2
+ module TaskHelpers
3
+ # Returns the root folder of the react_on_rails gem
4
+ def gem_root
5
+ File.expand_path("../../.", __FILE__)
6
+ end
7
+
8
+ # Returns the folder where examples are located
9
+ def examples_dir
10
+ File.join(gem_root, "examples")
11
+ end
12
+
13
+ def dummy_app_dirs
14
+ %w(spec/dummy spec/dummy-react-013).map { |rel_dir| File.join(gem_root, rel_dir) }
15
+ end
16
+
17
+ # Executes a string or an array of strings in a shell in the given directory
18
+ def sh_in_dir(dir, shell_commands)
19
+ shell_commands = [shell_commands] if shell_commands.is_a?(String)
20
+ shell_commands.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
21
+ end
22
+
23
+ def bundle_install_in(dir)
24
+ sh_in_dir(dir, "bundle install")
25
+ end
26
+
27
+ # Runs bundle exec using that directory's Gemfile
28
+ def bundle_exec(dir:, args:, env_vars: "")
29
+ sh_in_dir(dir, "#{env_vars} #{args}")
30
+ end
31
+
32
+ def generators_source_dir
33
+ File.join(gem_root, "lib/generators/react_on_rails")
34
+ end
35
+
36
+ def symbolize_keys(hash)
37
+ hash.each_with_object({}) do |(key, value), new_hash|
38
+ new_key = key.is_a?(String) ? key.to_sym : key
39
+ new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
40
+ new_hash[new_key] = new_value
41
+ end
42
+ end
43
+ end
44
+ end
data/ruby-lint.yml CHANGED
@@ -11,6 +11,7 @@ ignore_paths:
11
11
  - client
12
12
  - node_modules
13
13
  - coverage
14
+ - examples
14
15
 
15
16
  analysis_classes:
16
17
  # - argument_amount
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: 1.1.1
4
+ version: 1.2.0.rc1
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-11-27 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -140,7 +140,6 @@ files:
140
140
  - ".rubocop.yml"
141
141
  - ".scss-lint.yml"
142
142
  - ".travis.yml"
143
- - Dockerfile_ci
144
143
  - Dockerfile_tests
145
144
  - Gemfile
146
145
  - README.md
@@ -157,17 +156,19 @@ files:
157
156
  - docs/additional_reading/react_router.md
158
157
  - docs/additional_reading/server_rendering_tips.md
159
158
  - docs/additional_reading/tips.md
159
+ - docs/additional_reading/webpack.md
160
160
  - docs/code_of_conduct.md
161
161
  - docs/coding-style/linters.md
162
162
  - docs/coding-style/style.md
163
163
  - docs/contributing.md
164
- - docs/generator_testing_script.md
164
+ - docs/generator_testing.md
165
165
  - docs/install_and_releasing.md
166
166
  - docs/sample_generated_js/README.md
167
167
  - docs/sample_generated_js/client-generated.js
168
168
  - docs/sample_generated_js/server-generated.js
169
169
  - lib/generators/react_on_rails/base_generator.rb
170
170
  - lib/generators/react_on_rails/bootstrap_generator.rb
171
+ - lib/generators/react_on_rails/dev_tests_generator.rb
171
172
  - lib/generators/react_on_rails/generator_helper.rb
172
173
  - lib/generators/react_on_rails/heroku_deployment_generator.rb
173
174
  - lib/generators/react_on_rails/install_generator.rb
@@ -187,10 +188,10 @@ files:
187
188
  - lib/generators/react_on_rails/templates/base/base/client/package.json.tt
188
189
  - lib/generators/react_on_rails/templates/base/base/client/server.js
189
190
  - lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt
190
- - lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js
191
+ - lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt
191
192
  - lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js
192
193
  - lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb
193
- - lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake
194
+ - lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
194
195
  - lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt
195
196
  - lib/generators/react_on_rails/templates/base/base/package.json
196
197
  - lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverGlobals.jsx
@@ -200,7 +201,11 @@ files:
200
201
  - lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss
201
202
  - lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss
202
203
  - lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js
203
- - lib/generators/react_on_rails/templates/client/README.md
204
+ - lib/generators/react_on_rails/templates/dev_tests/.rspec
205
+ - lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb
206
+ - lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb
207
+ - lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb
208
+ - lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb
204
209
  - lib/generators/react_on_rails/templates/heroku_deployment/.buildpacks
205
210
  - lib/generators/react_on_rails/templates/heroku_deployment/Procfile
206
211
  - lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb
@@ -232,6 +237,14 @@ files:
232
237
  - lib/react_on_rails/prerender_error.rb
233
238
  - lib/react_on_rails/server_rendering_pool.rb
234
239
  - lib/react_on_rails/version.rb
240
+ - rakelib/docker.rake
241
+ - rakelib/dummy_apps.rake
242
+ - rakelib/example_type.rb
243
+ - rakelib/examples.rake
244
+ - rakelib/examples_config.yml
245
+ - rakelib/lint.rake
246
+ - rakelib/run_rspec.rake
247
+ - rakelib/task_helpers.rb
235
248
  - react_on_rails.gemspec
236
249
  - ruby-lint.yml
237
250
  homepage: https://github.com/shakacode/react_on_rails
@@ -249,9 +262,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
262
  version: '0'
250
263
  required_rubygems_version: !ruby/object:Gem::Requirement
251
264
  requirements:
252
- - - ">="
265
+ - - ">"
253
266
  - !ruby/object:Gem::Version
254
- version: '0'
267
+ version: 1.3.1
255
268
  requirements: []
256
269
  rubyforge_project:
257
270
  rubygems_version: 2.5.0
data/Dockerfile_ci DELETED
@@ -1,12 +0,0 @@
1
- FROM dylangrafmyre/docker-ci
2
-
3
- WORKDIR /app/
4
-
5
- COPY ["/lib/react_on_rails/version.rb", "/app/lib/react_on_rails/"]
6
- COPY ["Gemfile", "Gemfile.lock", "react_on_rails.gemspec", "/app/"]
7
- COPY ["/spec/dummy/Gemfile", "/spec/dummy/Gemfile.lock", "/app/spec/dummy/"]
8
- RUN bundle install --gemfile=spec/dummy/Gemfile
9
-
10
- ENV DISPLAY :99
11
- ENTRYPOINT service xvfd start \
12
- && rake ci
@@ -1,49 +0,0 @@
1
- Per running steps:
2
-
3
- From directory of `react_on_rails`, with a test app named "react_on_rails_gen"
4
-
5
- ```bash
6
- cd ..
7
- rails new react_on_rails_gen
8
- cd react_on_rails_gen
9
- git init
10
- git add .
11
- git commit -m "Rails new plus react_on_rails"
12
- ```
13
-
14
- Edit the Gemfile, adding these 2 lines:
15
-
16
- ```ruby
17
- gem 'react_on_rails', path: '../react_on_rails'
18
- ```
19
-
20
- Note the relative path to the react_on_rails gem.
21
-
22
- ```bash
23
- bundle
24
- git commit -am "added react_on_rails gem"
25
- ```
26
-
27
- You can now mess around with the generator:
28
-
29
- ```bash
30
- # See available options
31
- rails generate react_on_rails:install --help
32
- # Actual install, for example, with Redux
33
- rails generate react_on_rails:install --redux
34
- ```
35
-
36
- If you do actually run the generator, then you can see the changes that the generator made, ready for a commit.
37
-
38
- Then run:
39
-
40
- ```bash
41
- cd client
42
- npm install
43
- cd ..
44
- foreman start -f Procfile.dev
45
- ```
46
-
47
- Then visit `localhost:3000/hello_world` to see it.
48
-
49
- That's it!
@@ -1,97 +0,0 @@
1
- Example NPM Package
2
- ===========================
3
- We've included an example package.json from https://github.com/shakacode/react-webpack-rails-tutorial which should get you started with your React project.
4
-
5
- Starting the node.js server:
6
- ```
7
- npm start
8
- ```
9
-
10
- Building client javascript files for production:
11
- ```
12
- npm run build:client
13
- ```
14
-
15
- Building server javascript files for production:
16
- ```
17
- npm run build:server
18
- ```
19
-
20
- Building client javascript files for development:
21
- ```
22
- npm run build:dev:client
23
- ```
24
-
25
- Building server javascript files for development:
26
- ```
27
- npm run build:dev:server
28
- ```
29
-
30
- Running all linters:
31
- ```
32
- npm run lint
33
- ```
34
-
35
- Running eslint:
36
- ```
37
- npm run eslint
38
- ```
39
-
40
- Running jscs:
41
- ```
42
- npm run jscs
43
- ```
44
-
45
- dependencies vs devDependencies
46
- ===========================
47
- Anything needed for heroku deployment needs to go in "dependencies", and anything not needed for heroku deployment should go in "devDependencies".
48
-
49
-
50
- Updating Node Dependencies
51
- ===========================
52
-
53
- ```
54
- npm install -g npm-check-updates
55
- ```
56
-
57
- Then run this to update the dependencies (starting at the top level).
58
-
59
- ```
60
- # Make sure you are in the top directory, then run:
61
- cd client
62
- rm npm-shrinkwrap.json
63
- npm-check-updates -u
64
- npm install
65
- npm prune
66
- npm shrinkwrap
67
- ```
68
-
69
- Then confirm that the hot reload server and the rails server both work fine. You
70
- may have to delete `node_modules` and `npm-shrinkwrap.json` and then run `npm
71
- shrinkwrap`.
72
-
73
- Note: `npm prune` is required before running `npm shrinkwrap` to remove dependencies that are no longer needed after doing updates.
74
-
75
-
76
- Adding Node Modules
77
- =====================================
78
- Suppose you want to add a dependency to "module_name"....
79
-
80
- Before you do so, consider:
81
-
82
- 1. Do we really need the module and the extra JS code?
83
- 2. Is the module well maintained?
84
-
85
- ```bash
86
- cd client
87
- npm install --save module_name@version
88
- # or
89
- # npm install --save_dev module_name@version
90
- rm npm-shrinkwrap.json
91
- npm shrinkwrap
92
- ```
93
-
94
- Setting Up a Basic REST API
95
- =====================================
96
- See server.js in our tutorial at
97
- https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/server.js