react_on_rails 1.0.0.pre → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +2 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +1 -0
  5. data/.gitignore +4 -0
  6. data/.jscsrc +2 -2
  7. data/.rubocop.yml +2 -0
  8. data/.scss-lint.yml +3 -3
  9. data/.travis.yml +31 -18
  10. data/Dockerfile_ci +12 -0
  11. data/Dockerfile_tests +12 -0
  12. data/{LICENSE.txt → LICENSE} +0 -0
  13. data/README.md +170 -290
  14. data/Rakefile +20 -7
  15. data/app/helpers/react_on_rails_helper.rb +5 -5
  16. data/docker-compose.yml +12 -0
  17. data/docs/Contributing.md +26 -2
  18. data/docs/gen-notes/react_syntax.md +3 -0
  19. data/docs/gen-notes/reducers.md +31 -0
  20. data/docs/generator_testing_script.md +50 -0
  21. data/docs/linters.md +8 -0
  22. data/docs/manual_configuration.md +202 -0
  23. data/docs/node_dependencies_and_npm.md +29 -0
  24. data/lib/generators/react_on_rails/base_generator.rb +116 -0
  25. data/lib/generators/react_on_rails/bootstrap_generator.rb +84 -0
  26. data/lib/generators/react_on_rails/generator_helper.rb +48 -0
  27. data/lib/generators/react_on_rails/heroku_deployment_generator.rb +22 -0
  28. data/lib/generators/react_on_rails/install_generator.rb +86 -0
  29. data/lib/generators/react_on_rails/linters_generator.rb +38 -0
  30. data/lib/generators/react_on_rails/react_no_redux_generator.rb +37 -0
  31. data/lib/generators/react_on_rails/react_with_redux_generator.rb +61 -0
  32. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +4 -0
  33. data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +16 -0
  34. data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +5 -0
  35. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +6 -0
  36. data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +3 -0
  37. data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +3 -0
  38. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientGlobals.jsx +4 -0
  39. data/lib/generators/react_on_rails/templates/base/base/client/index.jade +15 -0
  40. data/lib/generators/react_on_rails/templates/base/base/client/npm-shrinkwrap.json +2907 -0
  41. data/lib/generators/react_on_rails/templates/base/base/client/server.js +58 -0
  42. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js +58 -0
  43. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js +65 -0
  44. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +45 -0
  45. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +30 -0
  46. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake +26 -0
  47. data/lib/generators/react_on_rails/templates/base/base/package.json +31 -0
  48. data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverGlobals.jsx +3 -0
  49. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +37 -0
  50. data/lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss +63 -0
  51. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +10 -0
  52. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss +8 -0
  53. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss +19 -0
  54. data/lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js +89 -0
  55. data/lib/generators/react_on_rails/templates/client/README.md +97 -0
  56. data/lib/generators/react_on_rails/templates/heroku_deployment/.buildpacks +2 -0
  57. data/lib/generators/react_on_rails/templates/heroku_deployment/Procfile +1 -0
  58. data/lib/generators/react_on_rails/templates/linters/client/.eslintignore +1 -0
  59. data/lib/generators/react_on_rails/templates/linters/client/.eslintrc +17 -0
  60. data/lib/generators/react_on_rails/templates/linters/client/.jscsrc +7 -0
  61. data/lib/generators/react_on_rails/templates/linters/lib/tasks/brakeman.rake +17 -0
  62. data/lib/generators/react_on_rails/templates/linters/lib/tasks/ci.rake +33 -0
  63. data/lib/generators/react_on_rails/templates/linters/lib/tasks/linters.rake +81 -0
  64. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +39 -0
  65. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +33 -0
  66. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx +11 -0
  67. data/lib/generators/react_on_rails/templates/no_redux/base/client/package.json.tt +75 -0
  68. data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +11 -0
  69. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +8 -0
  70. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +48 -0
  71. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +8 -0
  72. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +43 -0
  73. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +21 -0
  74. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +14 -0
  75. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx +20 -0
  76. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +35 -0
  77. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +25 -0
  78. data/lib/generators/react_on_rails/templates/redux/base/client/package.json.tt +82 -0
  79. data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +21 -0
  80. data/lib/react_on_rails.rb +1 -7
  81. data/lib/react_on_rails/configuration.rb +14 -5
  82. data/lib/react_on_rails/engine.rb +7 -0
  83. data/lib/react_on_rails/server_rendering_pool.rb +14 -1
  84. data/lib/react_on_rails/version.rb +1 -1
  85. data/react_on_rails.gemspec +2 -2
  86. data/ruby-lint.yml +1 -0
  87. metadata +75 -11
  88. data/Dockerfile +0 -14
  89. data/docs/README.md +0 -1
@@ -0,0 +1,29 @@
1
+ # Node Dependencies and NPM
2
+ ## Updating
3
+ After installing the files, you may want to update the node dependencies. This is analogous to updating gem versions:
4
+
5
+ ```bash
6
+ cd client
7
+ npm install -g npm-check-updates
8
+ rm npm-shrinkwrap.json
9
+ npm-check-updates -u
10
+ npm install
11
+ npm prune
12
+ npm shrinkwrap
13
+ ```
14
+
15
+ Confirm that the hot replacement dev server and the Rails server both work. You may have to delete `node_modules` and `npm-shrinkwrap.json` and then run `npm shrinkwrap`.
16
+
17
+ *Note: `npm prune` is required before running `npm shrinkwrap` to remove dependencies that are no longer needed after doing updates.*
18
+
19
+ ## Adding New Dependencies
20
+ Typically, you can add your Node dependencies as you normally would. Occasionally, adding a new dependency may require removing and re-running `npm shrinkwrap`:
21
+
22
+ ```bash
23
+ cd client
24
+ npm install --save module_name@version
25
+ # or
26
+ # npm install --save_dev module_name@version
27
+ rm npm-shrinkwrap.json
28
+ npm shrinkwrap
29
+ ```
@@ -0,0 +1,116 @@
1
+ require "rails/generators"
2
+ require File.expand_path("../generator_helper", __FILE__)
3
+ include GeneratorHelper
4
+
5
+ module ReactOnRails
6
+ module Generators
7
+ class BaseGenerator < Rails::Generators::Base
8
+ hide!
9
+ source_root(File.expand_path("../templates", __FILE__))
10
+
11
+ # --server-rendering
12
+ class_option :server_rendering,
13
+ type: :boolean,
14
+ default: false,
15
+ desc: "Configure for server-side rendering of webpack JavaScript",
16
+ aliases: "-S"
17
+
18
+ def add_hello_world_route
19
+ route "get 'hello_world', to: 'hello_world#index'"
20
+ end
21
+
22
+ def create_client_assets_directories
23
+ empty_directory("client/assets")
24
+ empty_directory("client/assets/stylesheets")
25
+ empty_directory_with_keep_file("client/assets/fonts")
26
+ empty_directory_with_keep_file("client/assets/images")
27
+ end
28
+
29
+ def update_git_ignore
30
+ data = <<-DATA.strip_heredoc
31
+ # React on Rails
32
+ npm-debug.log
33
+ node_modules
34
+
35
+ # Generated js bundles
36
+ /app/assets/javascripts/generated/*
37
+ DATA
38
+
39
+ dest_file_exists?(".gitignore") ? append_to_file(".gitignore", data) : puts_setup_file_error(".gitignore", data)
40
+ end
41
+
42
+ def update_application_js
43
+ data = <<-DATA.strip_heredoc
44
+ // DO NOT REQUIRE jQuery or jQuery-ujs in this file!
45
+ // DO NOT REQUIRE TREE!
46
+
47
+ // CRITICAL that generated/vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks
48
+ // since it is exposing jQuery and jQuery-ujs
49
+ //= require react_on_rails
50
+
51
+ //= require generated/vendor-bundle
52
+ //= require generated/app-bundle
53
+
54
+ // bootstrap-sprockets depends on generated/vendor-bundle for jQuery.
55
+ //= require bootstrap-sprockets
56
+ DATA
57
+
58
+ application_js_path = "app/assets/javascripts/application.js"
59
+ application_js = dest_file_exists?(application_js_path) || dest_file_exists?(application_js_path + ".coffee")
60
+ if application_js
61
+ prepend_to_file(application_js, data)
62
+ else
63
+ puts_setup_file_error("#{application_js} or #{application_js}.coffee", data)
64
+ end
65
+ end
66
+
67
+ def strip_application_js_of_incompatible_sprockets_statements
68
+ application_js = File.join(destination_root, "app/assets/javascripts/application.js")
69
+ gsub_file(application_js, "//= require jquery_ujs", "")
70
+ gsub_file(application_js, "//= require jquery", "")
71
+ gsub_file(application_js, "//= require_tree .", "")
72
+ end
73
+
74
+ def strip_application_js_of_double_blank_lines
75
+ application_js = File.join(destination_root, "app/assets/javascripts/application.js")
76
+ gsub_file(application_js, /^\n^\n/, "\n")
77
+ end
78
+
79
+ def create_react_directories
80
+ dirs = %w(components containers startup)
81
+ dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
82
+ end
83
+
84
+ def copy_base_files
85
+ base_path = "base/base/"
86
+ %w(app/controllers/hello_world_controller.rb
87
+ config/initializers/react_on_rails.rb
88
+ client/.babelrc
89
+ client/index.jade
90
+ client/npm-shrinkwrap.json
91
+ client/server.js
92
+ client/webpack.client.base.config.js
93
+ client/webpack.client.hot.config.js
94
+ client/webpack.client.rails.config.js
95
+ client/app/bundles/HelloWorld/startup/clientGlobals.jsx
96
+ lib/tasks/assets.rake
97
+ REACT_ON_RAILS.md
98
+ client/REACT_ON_RAILS_CLIENT_README.md
99
+ package.json).each { |file| copy_file(base_path + file, file) }
100
+ end
101
+
102
+ def template_base_files
103
+ base_path = "base/base/"
104
+ %w(Procfile.dev
105
+ app/views/hello_world/index.html.erb).each { |file| template(base_path + file + ".tt", file) }
106
+ end
107
+
108
+ def install_server_rendering_files_if_enabled
109
+ return unless options.server_rendering?
110
+ base_path = "base/server_rendering/"
111
+ %w(client/webpack.server.rails.config.js
112
+ client/app/bundles/HelloWorld/startup/serverGlobals.jsx).each { |file| copy_file(base_path + file, file) }
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,84 @@
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 append_to_assets_initializer
12
+ data = <<-DATA.strip_heredoc
13
+ # Add client/assets/ folders to asset pipeline's search path.
14
+ # If you do not want to move existing images and fonts from your Rails app
15
+ # you could also consider creating symlinks there that point to the original
16
+ # rails directories. In that case, you would not add these paths here.
17
+ Rails.application.config.assets.paths << Rails.root.join("client", "assets", "stylesheets")
18
+ Rails.application.config.assets.paths << Rails.root.join("client", "assets", "images")
19
+ Rails.application.config.assets.paths << Rails.root.join("client", "assets", "fonts")
20
+
21
+ Rails.application.config.assets.precompile += %w( generated/server-bundle.js )
22
+ DATA
23
+ append_to_file("config/initializers/assets.rb", data)
24
+ end
25
+
26
+ def copy_bootstrap_files
27
+ base_path = "bootstrap/"
28
+ %w(app/assets/stylesheets/_bootstrap-custom.scss
29
+ client/assets/stylesheets/_post-bootstrap.scss
30
+ client/assets/stylesheets/_pre-bootstrap.scss
31
+ client/assets/stylesheets/_react-on-rails-sass-helper.scss
32
+ client/bootstrap-sass.config.js).each { |file| copy_file(base_path + file, file) }
33
+ end
34
+
35
+ def change_application_css_to_scss_if_necessary
36
+ stylesheets_path = File.join(destination_root, "app/assets/stylesheets")
37
+ application_css = File.join(stylesheets_path, "application.css")
38
+ return unless File.exist?(application_css)
39
+ File.rename(application_css, File.join(stylesheets_path, "application.css.scss"))
40
+ end
41
+
42
+ def prepend_to_application_scss
43
+ data = <<-DATA.strip_heredoc
44
+ // DO NOT REQUIRE TREE! It will interfere with load order!
45
+
46
+ // Account for differences between Rails and Webpack Sass code.
47
+ $rails: true;
48
+
49
+ // Included from bootstrap-sprockets gem and loaded in app/assets/javascripts/application.rb
50
+ @import 'bootstrap-sprockets';
51
+
52
+ // Customizations - needs to be imported after bootstrap-sprocket but before bootstrap-custom!
53
+ // The _pre-bootstrap.scss file is located under
54
+ // client/assets/stylesheets, which has been added to the Rails asset
55
+ // pipeline search path. See config/application.rb.
56
+ @import 'pre-bootstrap';
57
+
58
+ // These scss files are located under client/assets/stylesheets
59
+ // (which has been added to the Rails asset pipeline search path in config/application.rb).
60
+ @import 'bootstrap-custom';
61
+
62
+ // This must come after all the boostrap styles are loaded so that these styles can override those.
63
+ @import 'post-bootstrap';
64
+
65
+ DATA
66
+ append_to_file("app/assets/stylesheets/application.css.scss", data)
67
+ end
68
+
69
+ def strip_application_scss_of_incompatible_sprockets_statements
70
+ application_scss = File.join(destination_root, "app/assets/stylesheets/application.css.scss")
71
+ gsub_file(application_scss, "*= require_tree .", "")
72
+ gsub_file(application_scss, "*= require_self", "")
73
+ end
74
+
75
+ def add_bootstrap_sprockets_to_gemfile
76
+ gem("bootstrap-sass")
77
+ end
78
+
79
+ def add_bootstrap_sprockets_to_application_js
80
+ # see base_generator.rb this is done there
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,48 @@
1
+ module GeneratorHelper
2
+ # Takes a relative path from the destination root, such as `.gitignore` or `app/assets/javascripts/application.js`
3
+ def dest_file_exists?(file)
4
+ File.exist?(File.join(destination_root, file)) ? file : nil
5
+ end
6
+
7
+ def dest_dir_exists?(dir)
8
+ Dir.exist?(File.join(destination_root, dir)) ? dir : nil
9
+ end
10
+
11
+ # Takes the missing file and the
12
+ def puts_setup_file_error(file, data)
13
+ puts "** #{file} was not found."
14
+ puts "Please add the following content to your #{file} file:"
15
+ puts "\n#{data}\n"
16
+ end
17
+
18
+ def empty_directory_with_keep_file(destination, config = {})
19
+ empty_directory(destination, config)
20
+ keep_file(destination)
21
+ end
22
+
23
+ def keep_file(destination)
24
+ create_file("#{destination}/.keep") unless options[:skip_keeps]
25
+ end
26
+
27
+ # As opposed to Rails::Generators::Testing.create_link, which creates a link pointing to
28
+ # source_root, this symlinks a file in destination_root to a file also in
29
+ # destination_root.
30
+ def symlink_dest_file_to_dest_file(target, link)
31
+ target_pathname = Pathname.new(File.join(destination_root, target))
32
+ link_pathname = Pathname.new(File.join(destination_root, link))
33
+
34
+ link_directory = link_pathname.dirname
35
+ link_basename = link_pathname.basename
36
+ target_relative_path = target_pathname.relative_path_from(link_directory)
37
+
38
+ `cd #{link_directory} && ln -s #{target_relative_path} #{link_basename}`
39
+ end
40
+
41
+ def copy_file_and_missing_parent_directories(source_file, destination_file = nil)
42
+ destination_file = source_file unless destination_file
43
+ destination_path = Pathname.new(destination_file)
44
+ parent_directories = destination_path.dirname
45
+ empty_directory(parent_directories) unless dest_dir_exists?(parent_directories)
46
+ copy_file source_file, destination_file
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require "rails/generators"
2
+ require File.expand_path("../generator_helper", __FILE__)
3
+ include GeneratorHelper
4
+
5
+ module ReactOnRails
6
+ module Generators
7
+ class HerokuDeploymentGenerator < Rails::Generators::Base
8
+ hide!
9
+ source_root(File.expand_path("../templates", __FILE__))
10
+
11
+ def copy_heroku_deployment_files
12
+ base_path = "heroku_deployment"
13
+ %w(.buildpacks Procfile).each { |file| copy_file("#{base_path}/#{file}", file) }
14
+ end
15
+
16
+ def add_heroku_production_gems
17
+ production_gems = "# For Heroku deployment\ngem 'rails_12factor', group: :production\n"
18
+ append_to_file("Gemfile", production_gems)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,86 @@
1
+ # Install Generator: gem's only public generator
2
+ #
3
+ # Usage:
4
+ # rails generate react_on_rails:install [options]
5
+ #
6
+ # Options:
7
+ # [--redux], [--no-redux]
8
+ # Indicates when to generate with redux
9
+ # [--server-rendering], [--no-server-rendering]
10
+ # Indicates whether ability for server-side rendering of webpack output should be enabled
11
+ # [--skip-linters]
12
+ # Indicates whether linter files and configs should be installed
13
+ #
14
+ require "rails/generators"
15
+
16
+ module ReactOnRails
17
+ module Generators
18
+ class InstallGenerator < Rails::Generators::Base
19
+ # --redux
20
+ class_option :redux,
21
+ type: :boolean,
22
+ default: false,
23
+ desc: "Setup Redux files",
24
+ aliases: "-R"
25
+ # --server-rendering
26
+ class_option :server_rendering,
27
+ type: :boolean,
28
+ default: false,
29
+ desc: "Configure for server-side rendering of webpack JavaScript",
30
+ aliases: "-S"
31
+ # --skip-linters
32
+ class_option :skip_linters,
33
+ type: :boolean,
34
+ default: false,
35
+ desc: "Don't install linter files",
36
+ aliases: "-L"
37
+
38
+ def run_generators
39
+ return unless installation_prerequisites_met?
40
+ warn_if_nvm_is_not_installed
41
+ invoke "react_on_rails:base"
42
+ invoke "react_on_rails:react_no_redux" unless options.redux?
43
+ invoke "react_on_rails:react_with_redux" if options.redux?
44
+ invoke "react_on_rails:linters" unless options.skip_linters?
45
+ invoke "react_on_rails:bootstrap"
46
+ invoke "react_on_rails:heroku_deployment"
47
+ end
48
+
49
+ private
50
+
51
+ # NOTE: other requirements for existing files such as .gitignore or application.
52
+ # js(.coffee) are not checked by this method, but instead produce warning messages
53
+ # and allow the build to continue
54
+ def installation_prerequisites_met?
55
+ !(missing_node? || missing_npm? || uncommitted_changes?)
56
+ end
57
+
58
+ def missing_npm?
59
+ return false unless `which npm`.blank?
60
+ error = "** npm is required. Please install it before continuing."
61
+ error << "https://www.npmjs.com/"
62
+ puts error
63
+ end
64
+
65
+ def missing_node?
66
+ return false unless `which node`.blank?
67
+ error = "** nodejs is required. Please install it before continuing."
68
+ error << "https://nodejs.org/en/"
69
+ puts error
70
+ end
71
+
72
+ def uncommitted_changes?
73
+ return false if ENV["COVERAGE"]
74
+ status = `git status`
75
+ return false if status.include?("nothing to commit, working directory clean")
76
+ error = "** You have uncommitted code. Please commit or stash your changes before continuing"
77
+ puts error
78
+ end
79
+
80
+ def warn_if_nvm_is_not_installed
81
+ return true unless `which nvm`.blank?
82
+ puts "** nvm is advised. Please consider installing it. https://github.com/creationix/nvm"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,38 @@
1
+ require "rails/generators"
2
+
3
+ module ReactOnRails
4
+ module Generators
5
+ class LintersGenerator < Rails::Generators::Base
6
+ hide!
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def add_linter_gems
10
+ linter_gems = <<-GEMS
11
+
12
+ # require: false is necessary for the linters as we only want them loaded
13
+ # when used by the linting rake tasks.
14
+ group :development do
15
+ gem("rubocop", require: false)
16
+ gem("ruby-lint", require: false)
17
+ gem("scss_lint", require: false)
18
+ end
19
+ GEMS
20
+ append_to_file("Gemfile", linter_gems)
21
+ end
22
+
23
+ def copy_linter_config_files
24
+ base_path = "linters/"
25
+ %w(client/.eslintrc
26
+ client/.eslintignore
27
+ client/.jscsrc).each { |file| copy_file(base_path + file, file) }
28
+ end
29
+
30
+ def copy_linting_and_audting_tasks
31
+ base_path = "linters/"
32
+ %w(lib/tasks/brakeman.rake
33
+ lib/tasks/ci.rake
34
+ lib/tasks/linters.rake).each { |file| copy_file(base_path + file, file) }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ require "rails/generators"
2
+ require File.expand_path("../generator_helper", __FILE__)
3
+ include GeneratorHelper
4
+
5
+ module ReactOnRails
6
+ module Generators
7
+ class ReactNoReduxGenerator < Rails::Generators::Base
8
+ hide!
9
+ source_root(File.expand_path("../templates", __FILE__))
10
+
11
+ # --server-rendering
12
+ class_option :server_rendering,
13
+ type: :boolean,
14
+ default: false,
15
+ desc: "Configure for server-side rendering of webpack JavaScript",
16
+ aliases: "-S"
17
+
18
+ def copy_base_files
19
+ base_path = "no_redux/base/"
20
+ %w(client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx
21
+ client/app/bundles/HelloWorld/containers/HelloWorld.jsx
22
+ client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx).each do |file|
23
+ copy_file(base_path + file, file)
24
+ end
25
+ template("#{base_path}client/package.json", "client/package.json")
26
+ end
27
+
28
+ def copy_server_rendering_files_if_appropriate
29
+ return unless options.server_rendering?
30
+ base_path = "no_redux/server_rendering/"
31
+ %w(client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx).each do |file|
32
+ copy_file(base_path + file, file)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end