-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathrails-webpacker.rb
More file actions
117 lines (87 loc) · 3.09 KB
/
rails-webpacker.rb
File metadata and controls
117 lines (87 loc) · 3.09 KB
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
51
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Legacy Hyperloop
# ----------------------------------- Commit so we have good history of these changes
git :init
git add: "."
git commit: "-m 'Initial commit: Rails base'"
# ----------------------------------- Add the gems
gem 'webpacker'
gem 'hyperloop', ">=0.9.1", "<1.0.0"
gem 'opal_hot_reloader', github: 'hyperstack-org/opal-hot-reloader'
gem_group :development do
gem 'foreman'
end
# ----------------------------------- Create the folders
run 'mkdir app/hyperloop'
run 'mkdir app/hyperloop/components'
run 'mkdir app/hyperloop/stores'
run 'mkdir app/hyperloop/models'
run 'mkdir app/hyperloop/operations'
# ----------------------------------- Add .keep files
run 'touch app/hyperloop/components/.keep'
run 'touch app/hyperloop/stores/.keep'
run 'touch app/hyperloop/models/.keep'
run 'touch app/hyperloop/operations/.keep'
# ----------------------------------- Create the Hyperloop config
file 'config/initializers/hyperloop.rb', <<-CODE
Hyperloop.configuration do |config|
# config.transport = :action_cable
config.import 'reactrb/auto-import'
config.import 'opal_hot_reloader'
config.cancel_import 'react/react-source-browser' # bring your own React and ReactRouter via Yarn/Webpacker
end
CODE
# ----------------------------------- Add NPM modules
run 'yarn add react'
run 'yarn add react-dom'
run 'yarn add react-router'
# ----------------------------------- Create hyperstack.js
file 'app/javascript/packs/hyperstack.js', <<-CODE
// Import all the modules
import React from 'react';
import ReactDOM from 'react-dom';
// for opal/hyperloop modules to find React and others they must explicitly be saved
// to the global space, otherwise webpack will encapsulate them locally here
global.React = React;
global.ReactDOM = ReactDOM;
CODE
# ----------------------------------- View template
inject_into_file 'app/views/layouts/application.html.erb', before: %r{<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>} do
<<-CODE
<%= javascript_pack_tag 'hyperstack' %>
CODE
end
# ----------------------------------- application.js
inject_into_file 'app/assets/javascripts/application.js', before: %r{//= require_tree .} do
<<-CODE
//= require jquery
//= require jquery_ujs
//= require hyperloop-loader
CODE
end
# ----------------------------------- Procfile
file 'Procfile', <<-CODE
web: bundle exec puma
hot: opal-hot-reloader -p 25222 -d app/hyperloop/
CODE
# ----------------------------------- OpalHotReloader client
file 'app/hyperloop/components/hot_loader.rb', <<-CODE
require 'opal_hot_reloader'
OpalHotReloader.listen(25222, false)
CODE
# ----------------------------------- Mount point
route "mount Hyperloop::Engine => '/hyperloop'"
# ----------------------------------- Hello World
route "root 'hyperloop#HelloWorld'"
file 'app/hyperloop/components/hello_world.rb', <<-CODE
class HelloWorld < Hyperloop::Component
render do
H1 { "Hello world from Legacy Hyperloop!" }
end
end
CODE
# ----------------------------------- Commit Hyperloop setup
after_bundle do
run 'bundle exec rails webpacker:install'
git add: "."
git commit: "-m 'Hyperstack config complete'"
end