Class: WebpackRailsReact::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/webpack_rails_react/install_generator.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_foreman_to_gemfileObject



10
11
12
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 10

def add_foreman_to_gemfile
  gem 'foreman'
end

#add_to_gitignoreObject



91
92
93
94
95
96
97
98
99
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 91

def add_to_gitignore
  append_to_file ".gitignore" do
    "    # Added by webpack-rails\n    /node_modules\n    /public/webpack\n    EOF\n  end\nend\n".strip_heredoc

#copy_package_jsonObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 18

def copy_package_json
  copy_file "package.json", "package.json"

  if options[:router]
    insert_into_file './package.json', after: /dependencies\": {\n/ do
      "\"react-router\": \"^2.4.1\",\n      RUBY\n    end\n  end\n\n  if options[:redux]\n    insert_into_file './package.json', after: /dependencies\\\": {\\n/ do\n      <<-'RUBY'\n\"react-redux\": \"^4.4.5\",\n\"redux\": \"^3.5.2\",\n\"redux-thunk\": \"^2.1.0\",\n      RUBY\n    end\n  end\n\n  if options[:router] && options[:redux]\n      insert_into_file './package.json', after: /dependencies\\\": {\\n/ do\n      <<-'RUBY'\n\"react-router-redux\": \"^4.0.5\",\n      RUBY\n     end\n  end\nend\n"

#copy_procfileObject



14
15
16
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 14

def copy_procfile
  copy_file "Procfile", "Procfile"
end

#copy_webpack_confObject



48
49
50
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 48

def copy_webpack_conf
  copy_file "webpack.config.js", "config/webpack.config.js"
end

#create_webpack_application_jsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 52

def create_webpack_application_js
  empty_directory "webpack"

  if options[:router] && options[:redux]
    copy_file "boilerplate/router_redux/application.js", "webpack/application.js"
    copy_file "boilerplate/routes.js", "webpack/routes.js"
    copy_file "boilerplate/router_redux/store.js", "webpack/store.js"
    copy_file "boilerplate/router_redux/reducers.js", "webpack/reducers/index.js"
    create_file "webpack/actions.js"
    copy_file "boilerplate/router/App.js", "webpack/containers/App.js"
  elsif options[:router]
    copy_file "boilerplate/router/application.js", "webpack/application.js"
    copy_file "boilerplate/routes.js", "webpack/routes.js"
    copy_file "boilerplate/router/App.js", "webpack/containers/App.js"
  elsif options[:redux]
    copy_file "boilerplate/redux/application.js", "webpack/application.js"
    copy_file "boilerplate/redux/store.js", "webpack/store.js"
    copy_file "boilerplate/redux/reducers.js", "webpack/reducers/index.js"
    create_file "webpack/actions.js"
    copy_file "boilerplate/App.js", "webpack/containers/App.js"
  else
    copy_file "boilerplate/application.js", "webpack/application.js"
    copy_file "boilerplate/App.js", "webpack/containers/App.js"
  end

  empty_directory "webpack/components"

  insert_into_file 'app/views/layouts/application.html.erb', before: /<\/body>/ do
      "<%= javascript_include_tag *webpack_asset_paths('application') %>\n      RUBY\n  end\n  insert_into_file 'app/views/layouts/application.html.erb', before: /<\\/head>/ do\n      <<-'RUBY'\n<script src=\"http://localhost:3808/webpack-dev-server.js\"></script>\n      RUBY\n  end\nend\n"

#run_bundle_installObject



105
106
107
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 105

def run_bundle_install
  run "bundle install" if yes?("Would you like us to run 'bundle install' for you?")
end

#run_npm_installObject



101
102
103
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 101

def run_npm_install
  run "npm install" if yes?("Would you like us to run 'npm install' for you?")
end

#whats_nextObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/generators/webpack_rails_react/install_generator.rb', line 109

def whats_next
  puts "\n    We've set up the basics of webpack-rails-react for you, but you'll still\n    need to:\n\n      1. Add an element with an id of 'app' to your layout\n      2. To disable hot module replacement remove <script src=\"http://localhost:3808/webpack-dev-server.js\"></script> from layout\n      3. Run 'foreman start' to run the webpack-dev-server and rails server\n\n    See the README.md for this gem at\n    https://github.com/wdjungst/webpack-rails-react/blob/master/README.md\n    for more info.\n\n    Thanks for using webpack-rails-react!\n\n  EOF\nend\n".strip_heredoc