react_on_rails 2.0.0.beta.1 → 2.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.dockerignore +2 -0
  4. data/.eslintignore +7 -0
  5. data/.eslintrc +19 -0
  6. data/.gitignore +28 -0
  7. data/.jscsrc +27 -0
  8. data/.npmignore +20 -0
  9. data/.rspec +2 -0
  10. data/.rubocop.yml +70 -0
  11. data/.scss-lint.yml +205 -0
  12. data/.travis.yml +43 -0
  13. data/CHANGELOG.md +34 -0
  14. data/Dockerfile_tests +12 -0
  15. data/Gemfile +40 -0
  16. data/README.md +365 -0
  17. data/Rakefile +5 -0
  18. data/app/helpers/react_on_rails_helper.rb +215 -0
  19. data/docker-compose.yml +11 -0
  20. data/docs/LICENSE +21 -0
  21. data/docs/additional_reading/heroku_deployment.md +23 -0
  22. data/docs/additional_reading/manual_installation.md +118 -0
  23. data/docs/additional_reading/node_dependencies_and_npm.md +29 -0
  24. data/docs/additional_reading/optional_configuration.md +33 -0
  25. data/docs/additional_reading/react-and-redux.md +36 -0
  26. data/docs/additional_reading/react_router.md +45 -0
  27. data/docs/additional_reading/server_rendering_tips.md +11 -0
  28. data/docs/additional_reading/tips.md +10 -0
  29. data/docs/additional_reading/webpack.md +46 -0
  30. data/docs/code_of_conduct.md +13 -0
  31. data/docs/coding-style/linters.md +64 -0
  32. data/docs/coding-style/style.md +42 -0
  33. data/docs/contributing.md +157 -0
  34. data/docs/generator_testing.md +20 -0
  35. data/docs/releasing.md +29 -0
  36. data/lib/generators/USAGE +99 -0
  37. data/lib/generators/react_on_rails/base_generator.rb +191 -0
  38. data/lib/generators/react_on_rails/bootstrap_generator.rb +89 -0
  39. data/lib/generators/react_on_rails/dev_tests_generator.rb +39 -0
  40. data/lib/generators/react_on_rails/generator_helper.rb +50 -0
  41. data/lib/generators/react_on_rails/heroku_deployment_generator.rb +30 -0
  42. data/lib/generators/react_on_rails/install_generator.rb +99 -0
  43. data/lib/generators/react_on_rails/js_linters_generator.rb +19 -0
  44. data/lib/generators/react_on_rails/react_no_redux_generator.rb +40 -0
  45. data/lib/generators/react_on_rails/react_with_redux_generator.rb +51 -0
  46. data/lib/generators/react_on_rails/ruby_linters_generator.rb +33 -0
  47. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +4 -0
  48. data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +16 -0
  49. data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +5 -0
  50. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +4 -0
  51. data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +3 -0
  52. data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +3 -0
  53. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt +5 -0
  54. data/lib/generators/react_on_rails/templates/base/base/client/index.jade +15 -0
  55. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +104 -0
  56. data/lib/generators/react_on_rails/templates/base/base/client/server.js +64 -0
  57. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt +62 -0
  58. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +69 -0
  59. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +42 -0
  60. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +26 -0
  61. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt +26 -0
  62. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt +88 -0
  63. data/lib/generators/react_on_rails/templates/base/base/package.json +31 -0
  64. data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx +4 -0
  65. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +39 -0
  66. data/lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss +63 -0
  67. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +10 -0
  68. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss +8 -0
  69. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss +19 -0
  70. data/lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js +89 -0
  71. data/lib/generators/react_on_rails/templates/dev_tests/.rspec +2 -0
  72. data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +25 -0
  73. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +57 -0
  74. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +21 -0
  75. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +95 -0
  76. data/lib/generators/react_on_rails/templates/heroku_deployment/.buildpacks +2 -0
  77. data/lib/generators/react_on_rails/templates/heroku_deployment/Procfile +1 -0
  78. data/lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb +15 -0
  79. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintignore +1 -0
  80. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +48 -0
  81. data/lib/generators/react_on_rails/templates/js_linters/client/.jscsrc +18 -0
  82. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +39 -0
  83. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +33 -0
  84. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +8 -0
  85. data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +8 -0
  86. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +8 -0
  87. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +48 -0
  88. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +8 -0
  89. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +43 -0
  90. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +19 -0
  91. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +14 -0
  92. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +19 -0
  93. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +35 -0
  94. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +20 -0
  95. data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +19 -0
  96. data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +26 -0
  97. data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +205 -0
  98. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/brakeman.rake +17 -0
  99. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/ci.rake +33 -0
  100. data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml +20 -0
  101. data/lib/react_on_rails.rb +6 -0
  102. data/lib/react_on_rails/configuration.rb +60 -0
  103. data/lib/react_on_rails/engine.rb +7 -0
  104. data/lib/react_on_rails/prerender_error.rb +31 -0
  105. data/lib/react_on_rails/server_rendering_pool.rb +110 -0
  106. data/lib/react_on_rails/version.rb +3 -0
  107. data/package.json +76 -0
  108. data/rakelib/docker.rake +33 -0
  109. data/rakelib/dummy_apps.rake +20 -0
  110. data/rakelib/example_type.rb +160 -0
  111. data/rakelib/examples.rake +103 -0
  112. data/rakelib/examples_config.yml +19 -0
  113. data/rakelib/lint.rake +37 -0
  114. data/rakelib/node_package.rake +11 -0
  115. data/rakelib/run_rspec.rake +65 -0
  116. data/rakelib/task_helpers.rb +44 -0
  117. data/react_on_rails.gemspec +31 -0
  118. data/ruby-lint.yml +24 -0
  119. metadata +119 -2
@@ -0,0 +1,29 @@
1
+ # Install and Release
2
+
3
+ We're now releasing this as a combined ruby gem plus npm package. We will keep the version numbers in sync.
4
+
5
+ ## Testing the Gem before Release from a Rails App
6
+ See [Contributing](../contributing.md)
7
+
8
+ ## Releaseing 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
23
+ ```
24
+
25
+
26
+ ## Releasing a npm version
27
+ Be sure to keep the version number the same as the ruby gem!
28
+
29
+ Use the npm package `release-it`
@@ -0,0 +1,99 @@
1
+ Description:
2
+
3
+ The react_on_rails:install generator combined with the example pull requests of
4
+ generator runs will get you up and running efficiently. There's a fair bit of
5
+ setup involved when ~with~ integrating Webpack with Rails. Defaults for options
6
+ are such that the default is for the flag to be off. For example, the default for
7
+ `-R` is that redux is off, and the default of -b means that skip-bootstrap is off.
8
+
9
+ * Redux
10
+
11
+ Passing the --redux generator option causes the generated Hello World example
12
+ to integrate the Redux state container framework. The necessary node modules
13
+ will be automatically included for you.
14
+
15
+ The generator uses the organizational `paradigm of "bundles"`. These are like
16
+ application domains and are used for grouping your code into webpack bundles
17
+ in case you decide to create different bundles for deployment. This is also
18
+ useful for separating out logical parts of your application. We recommend that
19
+ that each bundle will have it's own Redux store. If you have code that you
20
+ want to reuse across bundles, such as middleware or common utilities, place them
21
+ under `/client/app/lib`. You can then import them in your client code:
22
+ `import MyModule from 'lib/MyModule'`; since we have configured webpack to
23
+ automatically resolve the word lib to point to this folder.
24
+
25
+ * Using Images and Fonts
26
+
27
+ The generator has amended the folders created in `client/assets/` to Rails's
28
+ asset path. We recommend that if you have any existing assets that you want
29
+ to use with your client code, you should move them to these folders and use
30
+ webpack as normal. This allows webpack's development server to have access
31
+ to your assets, as it will not be able to see any assets in the default Rails
32
+ directories which are above the `/client` directory.
33
+
34
+ Alternatively, if you have many existing assets and don't wish to move them,
35
+ you could consider creating symlinks from `client/assets` that point to your
36
+ Rails assets folders inside of `app/assets/`. The assets there will then be
37
+ visible to both Rails and webpack.
38
+
39
+ * Bootstrap Integration
40
+
41
+ React on Rails ships with Twitter Bootstrap already integrated into the build.
42
+ Note that the generator removes require_tree in both the application.js and
43
+ application.css.scss files. This is to ensure the correct load order for the
44
+ bootstrap integration, and is usually a good idea in general. You will therefore
45
+ need to explicitly require your files.
46
+
47
+ How the Bootstrap library is loaded depends upon whether one is using the Rails
48
+ server or the HMR development server.
49
+
50
+ 1. Bootstrap via Rails Server
51
+
52
+ The Rails server loads bootstrap-sprockets, provided
53
+ by the bootstrap-sass ruby gem (added automatically to your Gemfile by
54
+ the generator), via the `app/assets/stylesheets/_bootstrap-custom.scss`
55
+ partial.
56
+
57
+ This allows for using Bootstrap in your regular Rails stylesheets. If you
58
+ wish to customize any of the Bootstrap variables, you can do so via the
59
+ `client/assets/stylesheets/_pre-bootstrap.scss` partial.
60
+
61
+ 2. Bootstrap via Webpack Dev Server
62
+
63
+ The webpack dev server does not go through Rails but instead loads bootstrap
64
+ via the `bootstrap-sass-loader` webpack loader. You can configure the loader
65
+ via the `client/bootstrap-sass-config.js` file.
66
+
67
+ 3. Keeping Custom Bootstrap Configurations Synced
68
+
69
+ Because the webpack dev server and Rails each load Bootstrap via a different
70
+ file (explained in the two sections immediately above), any changes to
71
+ the way components are loaded in one file must also be made to the other
72
+ file in order to keep styling consistent between the two. For example,
73
+ if an import is excluded in _bootstrap-custom.scss, the same import should
74
+ be excluded in `bootstrap-sass-config.js` so that styling in the Rails
75
+ server and the webpack dev server will be the same.
76
+
77
+ 4. Skip Bootstrap Integration
78
+
79
+ Bootstrap integration is enabled by default, but can be disabled by passing
80
+ the --skip-bootstrap flag (alias -b). When you don't need Bootstrap in your
81
+ existing project, just skip it as needed.
82
+
83
+ * JavaScript Linters
84
+
85
+ JavaScript linters are enabled by default, but can be disabled by passing the
86
+ --skip-js-linters flag (alias j), and those that run in Node have been add to
87
+ `client/package.json` under devDependencies.
88
+
89
+ * Ruby Linters
90
+
91
+ Ruby linters are disabled by default, but can be enabled by passing the
92
+ `--ruby-linters` flag when generating. These linters have been added to your
93
+ Gemfile in addition to the the appropriate Rake tasks.
94
+
95
+ We really love using all the linters! Give them a try.
96
+
97
+ More Details:
98
+
99
+ `https://github.com/shakacode/react_on_rails#generator`
@@ -0,0 +1,191 @@
1
+ require "rails/generators"
2
+ require File.expand_path("../generator_helper", __FILE__)
3
+
4
+ include GeneratorHelper
5
+
6
+ module ReactOnRails
7
+ module Generators
8
+ class BaseGenerator < Rails::Generators::Base # rubocop:disable Metrics/ClassLength
9
+ hide!
10
+ source_root(File.expand_path("../templates", __FILE__))
11
+
12
+ # --redux
13
+ class_option :redux,
14
+ type: :boolean,
15
+ default: false,
16
+ desc: "Install Redux gems and Redux version of Hello World Example",
17
+ aliases: "-R"
18
+ # --server-rendering
19
+ class_option :server_rendering,
20
+ type: :boolean,
21
+ default: false,
22
+ desc: "Configure for server-side rendering of webpack JavaScript",
23
+ aliases: "-S"
24
+ # --skip-js-linters
25
+ class_option :skip_js_linters,
26
+ type: :boolean,
27
+ default: false,
28
+ desc: "Skip installing JavaScript linting files",
29
+ aliases: "-j"
30
+ # --ruby-linters
31
+ class_option :ruby_linters,
32
+ type: :boolean,
33
+ default: false,
34
+ desc: "Install ruby linting files, tasks, and configs",
35
+ aliases: "-L"
36
+
37
+ # --skip-bootstrap
38
+ class_option :skip_bootstrap,
39
+ type: :boolean,
40
+ default: false,
41
+ desc: "Skip integrating Bootstrap and don't initialize files and regarding configs",
42
+ aliases: "-b"
43
+
44
+ def add_hello_world_route
45
+ route "get 'hello_world', to: 'hello_world#index'"
46
+ end
47
+
48
+ def create_client_assets_directories
49
+ empty_directory("client/assets")
50
+ empty_directory("client/assets/stylesheets")
51
+ empty_directory_with_keep_file("client/assets/fonts")
52
+ empty_directory_with_keep_file("client/assets/images")
53
+ end
54
+
55
+ def update_git_ignore
56
+ data = <<-DATA.strip_heredoc
57
+ # React on Rails
58
+ npm-debug.log
59
+ node_modules
60
+
61
+ # Generated js bundles
62
+ /app/assets/javascripts/generated/*
63
+ DATA
64
+
65
+ dest_file_exists?(".gitignore") ? append_to_file(".gitignore", data) : puts_setup_file_error(".gitignore", data)
66
+ end
67
+
68
+ def update_application_js
69
+ data = <<-DATA.strip_heredoc
70
+ // DO NOT REQUIRE jQuery or jQuery-ujs in this file!
71
+ // DO NOT REQUIRE TREE!
72
+
73
+ // CRITICAL that generated/vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks
74
+ // since it is exposing jQuery and jQuery-ujs
75
+
76
+ //= require generated/vendor-bundle
77
+ //= require generated/app-bundle
78
+
79
+ DATA
80
+
81
+ app_js_path = "app/assets/javascripts/application.js"
82
+ found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?(app_js_path + ".coffee")
83
+ if found_app_js
84
+ prepend_to_file(found_app_js, data)
85
+ else
86
+ create_file(app_js_path, data)
87
+ end
88
+ end
89
+
90
+ def strip_application_js_of_incompatible_sprockets_statements
91
+ application_js = File.join(destination_root, "app/assets/javascripts/application.js")
92
+ gsub_file(application_js, "//= require jquery_ujs", "// require jquery_ujs")
93
+ gsub_file(application_js, %r{//= require jquery$}, "// require jquery")
94
+ gsub_file(application_js, %r{//= require_tree \.$}, "// require_tree .")
95
+ end
96
+
97
+ def strip_application_js_of_double_blank_lines
98
+ application_js = File.join(destination_root, "app/assets/javascripts/application.js")
99
+ gsub_file(application_js, /^\n^\n/, "\n")
100
+ end
101
+
102
+ def create_react_directories
103
+ dirs = %w(components containers startup)
104
+ dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
105
+ end
106
+
107
+ def copy_base_files
108
+ base_path = "base/base/"
109
+ %w(app/controllers/hello_world_controller.rb
110
+ config/initializers/react_on_rails.rb
111
+ client/.babelrc
112
+ client/index.jade
113
+ client/server.js
114
+ client/webpack.client.rails.config.js
115
+ REACT_ON_RAILS.md
116
+ client/REACT_ON_RAILS_CLIENT_README.md
117
+ package.json).each { |file| copy_file(base_path + file, file) }
118
+ end
119
+
120
+ def template_base_files
121
+ base_path = "base/base/"
122
+ %w(Procfile.dev
123
+ app/views/hello_world/index.html.erb
124
+ client/webpack.client.base.config.js
125
+ client/webpack.client.hot.config.js
126
+ client/package.json).each { |file| template(base_path + file + ".tt", file) }
127
+ end
128
+
129
+ def add_base_gems_to_gemfile
130
+ return unless options.server_rendering?
131
+ append_to_file("Gemfile", "\ngem 'therubyracer', platforms: :ruby\n")
132
+ end
133
+
134
+ def template_client_registration_file
135
+ filename = "clientRegistration.jsx"
136
+ location = "client/app/bundles/HelloWorld/startup"
137
+ template("base/base/#{location}/clientRegistration.jsx.tt", "#{location}/#{filename}")
138
+ end
139
+
140
+ def install_server_rendering_files_if_enabled
141
+ return unless options.server_rendering?
142
+ base_path = "base/server_rendering/"
143
+ %w(client/webpack.server.rails.config.js
144
+ client/app/bundles/HelloWorld/startup/serverRegistration.jsx).each do |file|
145
+ copy_file(base_path + file, file)
146
+ end
147
+ end
148
+
149
+ def template_linter_files_if_appropriate
150
+ return if !options.ruby_linters? && options.skip_js_linters?
151
+ template("base/base/lib/tasks/linters.rake.tt", "lib/tasks/linters.rake")
152
+ end
153
+
154
+ def template_assets_rake_file
155
+ template("base/base/lib/tasks/assets.rake.tt", "lib/tasks/assets.rake")
156
+ end
157
+
158
+ def append_to_assets_initializer
159
+ data = <<-DATA.strip_heredoc
160
+ # Add client/assets/ folders to asset pipeline's search path.
161
+ # If you do not want to move existing images and fonts from your Rails app
162
+ # you could also consider creating symlinks there that point to the original
163
+ # rails directories. In that case, you would not add these paths here.
164
+ Rails.application.config.assets.paths << Rails.root.join("client", "assets", "stylesheets")
165
+ Rails.application.config.assets.paths << Rails.root.join("client", "assets", "images")
166
+ Rails.application.config.assets.paths << Rails.root.join("client", "assets", "fonts")
167
+ Rails.application.config.assets.precompile += %w( generated/server-bundle.js )
168
+ DATA
169
+ assets_intializer = File.join(destination_root, "config/initializers/assets.rb")
170
+ if File.exist?(assets_intializer)
171
+ append_to_file(assets_intializer, data)
172
+ else
173
+ create_file(assets_intializer, data)
174
+ end
175
+ end
176
+
177
+ # rename to application.scss from application.css or application.css.scss
178
+ def force_application_scss_naming_if_necessary
179
+ base_path = "app/assets/stylesheets/"
180
+ application_css = "#{base_path}application.css"
181
+ application_css_scss = "#{base_path}application.css.scss"
182
+
183
+ bad_name = dest_file_exists?(application_css) || dest_file_exists?(application_css_scss)
184
+ return unless bad_name
185
+
186
+ new_name = File.join(destination_root, "#{base_path}application.scss")
187
+ File.rename(bad_name, new_name)
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,89 @@
1
+ require "rails/generators"
2
+ require File.expand_path("../generator_helper", __FILE__)
3
+ include GeneratorHelper
4
+
5
+ module ReactOnRails
6
+ module Generators
7
+ class BootstrapGenerator < Rails::Generators::Base
8
+ hide!
9
+ source_root(File.expand_path("../templates", __FILE__))
10
+
11
+ def copy_bootstrap_files
12
+ base_path = "bootstrap/"
13
+ %w(app/assets/stylesheets/_bootstrap-custom.scss
14
+ client/assets/stylesheets/_post-bootstrap.scss
15
+ client/assets/stylesheets/_pre-bootstrap.scss
16
+ client/assets/stylesheets/_react-on-rails-sass-helper.scss
17
+ client/bootstrap-sass.config.js).each { |file| copy_file(base_path + file, file) }
18
+ end
19
+
20
+ # if there still is not application.scss, just create one
21
+ def create_application_scss_if_necessary
22
+ path = File.join(destination_root, "app/assets/stylesheets/application.scss")
23
+ return if File.exist?(path)
24
+ File.open(path, "w") { |f| f.puts "// Created by React on Rails gem\n\n" }
25
+ end
26
+
27
+ def prepend_to_application_scss
28
+ data = <<-DATA.strip_heredoc
29
+ // DO NOT REQUIRE TREE! It will interfere with load order!
30
+
31
+ // Account for differences between Rails and Webpack Sass code.
32
+ $rails: true;
33
+
34
+ // Included from bootstrap-sprockets gem and loaded in app/assets/javascripts/application.rb
35
+ @import 'bootstrap-sprockets';
36
+
37
+ // Customizations - needs to be imported after bootstrap-sprocket but before bootstrap-custom!
38
+ // The _pre-bootstrap.scss file is located under
39
+ // client/assets/stylesheets, which has been added to the Rails asset
40
+ // pipeline search path. See config/application.rb.
41
+ @import 'pre-bootstrap';
42
+
43
+ // These scss files are located under client/assets/stylesheets
44
+ // (which has been added to the Rails asset pipeline search path in config/application.rb).
45
+ @import 'bootstrap-custom';
46
+
47
+ // This must come after all the boostrap styles are loaded so that these styles can override those.
48
+ @import 'post-bootstrap';
49
+
50
+ DATA
51
+
52
+ application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
53
+
54
+ if File.exist?(application_scss)
55
+ append_to_file(application_scss, data)
56
+ else
57
+ puts_setup_file_error(application_scss, data)
58
+ end
59
+ end
60
+
61
+ def strip_application_scss_of_incompatible_sprockets_statements
62
+ application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
63
+ gsub_file(application_scss, "*= require_tree .", "")
64
+ gsub_file(application_scss, "*= require_self", "")
65
+ end
66
+
67
+ def add_bootstrap_sprockets_to_gemfile
68
+ append_to_file("Gemfile", "gem 'bootstrap-sass'\n")
69
+ end
70
+
71
+ def add_bootstrap_sprockets_to_application_js
72
+ data = <<-DATA.strip_heredoc
73
+
74
+ // bootstrap-sprockets depends on generated/vendor-bundle for jQuery.
75
+ //= require bootstrap-sprockets
76
+
77
+ DATA
78
+
79
+ app_js_path = "app/assets/javascripts/application.js"
80
+ found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?(app_js_path + ".coffee")
81
+ if found_app_js
82
+ append_to_file(found_app_js, data)
83
+ else
84
+ create_file(app_js_path, data)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,39 @@
1
+ require "rails/generators"
2
+ require_relative "generator_helper"
3
+ include GeneratorHelper
4
+
5
+ module ReactOnRails
6
+ module Generators
7
+ class DevTestsGenerator < Rails::Generators::Base
8
+ hide!
9
+ source_root(File.expand_path("../templates/dev_tests", __FILE__))
10
+
11
+ def copy_rspec_files
12
+ %w(spec/spec_helper.rb
13
+ spec/rails_helper.rb
14
+ spec/simplecov_helper.rb
15
+ .rspec).each { |file| copy_file(file) }
16
+ end
17
+
18
+ def copy_tests
19
+ %w(spec/features/hello_world_spec.rb).each { |file| copy_file(file) }
20
+ end
21
+
22
+ # We want to use the node module in the local build, not the one published to NPM
23
+ def change_package_json_to_use_local_react_on_rails_module
24
+ package_json = File.join(destination_root, "client", "package.json")
25
+ old_contents = File.read(package_json)
26
+ new_contents = old_contents.gsub(/"react-on-rails": ".+",/,
27
+ '"react-on-rails": "../../..",')
28
+ File.open(package_json, "w+") { |f| f.puts new_contents }
29
+ end
30
+
31
+ def add_test_related_gems_to_gemfile
32
+ gem("rspec-rails", group: :test)
33
+ gem("capybara", group: :test)
34
+ gem("selenium-webdriver", group: :test)
35
+ gem("coveralls", require: false)
36
+ end
37
+ end
38
+ end
39
+ end