-
-
Notifications
You must be signed in to change notification settings - Fork 627
/
react_with_redux_generator.rb
50 lines (43 loc) · 1.89 KB
/
react_with_redux_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
47
48
49
50
require "rails/generators"
module ReactOnRails
module Generators
class ReactWithReduxGenerator < Rails::Generators::Base
Rails::Generators.hide_namespace(namespace)
source_root(File.expand_path("../templates", __FILE__))
# --server-rendering
class_option :server_rendering,
type: :boolean,
default: false,
desc: "Configure for server-side rendering of webpack JavaScript",
aliases: "-S"
def create_redux_directories
dirs = %w(actions constants reducers store)
dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
empty_directory("client/app/lib/middlewares")
end
def copy_base_redux_files
base_path = "redux/base/"
%w(client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx
client/app/bundles/HelloWorld/containers/HelloWorld.jsx
client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
client/app/bundles/HelloWorld/reducers/index.jsx
client/app/bundles/HelloWorld/store/helloWorldStore.jsx
client/app/lib/middlewares/loggerMiddleware.js).each do |file|
copy_file(base_path + file, file)
end
end
def copy_server_rendering_redux_files
return unless options.server_rendering?
base_path = "redux/server_rendering/"
file = "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
copy_file(base_path + file, file)
end
def template_appropriate_version_of_hello_world_app_client
filename = "HelloWorldAppClient.jsx"
location = "client/app/bundles/HelloWorld/startup"
template("redux/base/#{location}/HelloWorldAppClient.jsx.tt", "#{location}/#{filename}")
end
end
end
end