repack 2.4.6 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -15
- data/example/boilerplate/god_mode/actions/tokenAuth.js +59 -0
- data/example/boilerplate/god_mode/components/Loading.js +8 -12
- data/example/boilerplate/god_mode/containers/TokenApp.js +48 -0
- data/example/boilerplate/god_mode/reducers/auth.js +2 -1
- data/example/boilerplate/god_mode/tokenRoutes.js +27 -0
- data/lib/generators/repack/god_install_generator.rb +212 -0
- data/lib/generators/repack/install_generator.rb +10 -180
- data/lib/generators/repack/redux_install_generator.rb +95 -0
- data/lib/generators/repack/router_install_generator.rb +93 -0
- data/lib/generators/repack/router_redux_install_generator.rb +108 -0
- data/lib/repack/version.rb +1 -1
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dd7db92bd11982cc931f256d49e1322566ade0d
|
4
|
+
data.tar.gz: 19f349e15231d2f36e15bda45777a843007fd590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c8e1d7cbef7d0482f3efec55970a4ee4a8bf0ef061ed2786252dc87d040766018155db42c883a29b141bb977cdc4c1e75b6eda5270d9e2c3c3d9c6fb86982b
|
7
|
+
data.tar.gz: f46ed5f32805e9af22f74698a96a280999cfdb9c543d59be8ba0c7eac057df35eec0e74adcb614fa192c2da1f947aaaa84c360590eaf652615a7410579122c7d
|
data/README.md
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
#
|
1
|
+
# Repack
|
2
2
|
|
3
|
-
**
|
3
|
+
**Repack** gives you tools to integrate Webpack and React in to an existing Ruby on Rails application.
|
4
4
|
|
5
|
-
It will happily co-exist with sprockets but does not use it for production fingerprinting or asset serving. **
|
5
|
+
It will happily co-exist with sprockets but does not use it for production fingerprinting or asset serving. **Repack** is designed with the assumption that if you're using Webpack you treat Javascript as a first-class citizen. This means that you control the webpack config, package.json, and use npm to install Webpack & its plugins.
|
6
6
|
|
7
|
-
In development mode [webpack-dev-server](http://webpack.github.io/docs/webpack-dev-server.html) is used to serve webpacked entry points and offer hot module reloading. In production entry points are built in to `public/client`. **
|
7
|
+
In development mode [webpack-dev-server](http://webpack.github.io/docs/webpack-dev-server.html) is used to serve webpacked entry points and offer hot module reloading. In production entry points are built in to `public/client`. **Repack** uses [stats-webpack-plugin](https://www.npmjs.com/package/stats-webpack-plugin) to translate entry points in to asset paths.
|
8
8
|
|
9
9
|
It was forked from the [Marketplacer](http://www.marketplacer.com) repo: (https://github.com/mipearson/webpack-rails) and support for React / Babel / ES6 was added.
|
10
10
|
|
11
|
-
This gem has been tested against Rails
|
11
|
+
This gem has been tested against Rails 5 and Ruby 2.3.1 Earlier versions of Rails (>= 3.2) and Ruby (>= 1.9) may work, but we haven't tested them.
|
12
12
|
|
13
|
-
## Using
|
13
|
+
## Using Repack
|
14
14
|
|
15
|
-
### Install
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
### Install Options
|
16
|
+
|
17
|
+
1. Basic Install: `bundle exec rails g repack:install` -> Webpack / React
|
18
|
+
2. React / Redux Install: `bundle exec rails g repack:redux_install` -> Webpack / React / Redux Boilerplate
|
19
|
+
3. React / Router Install: `bundle exec rails g repack:router_install` -> Webpack / React / React Router Boilerplate
|
20
|
+
4. React / Router / Redux Install: `bundle exec rails g repack:router_redux_install` -> Webpack / React / Router / Redux Boilerplate
|
21
|
+
5. GOD MODE: `bundle exec rails g repack:god_install` -> Webpack / React / React Router / Redux / Devise / Devise Token Auth / Bootstrap or Materialize Boilerplate.
|
21
22
|
|
22
23
|
### Installation
|
23
24
|
|
24
25
|
1. Add `repack` to your gemfile
|
25
26
|
2. Run `bundle install` to install the gem
|
26
|
-
3.
|
27
|
+
3. See `Install Options` above and use 1 option
|
27
28
|
4. Run `npm run dev_server` (or `yarn run dev_server`) to start `webpack-dev-server`
|
28
29
|
5. Add the webpack entry point to your layout (see next section)
|
29
30
|
6. Edit `client/application.js` and write some code
|
@@ -58,6 +59,7 @@ If you're using the webpack dev server's live reload feature (not the React hot
|
|
58
59
|
* The manifest file is named `manifest.json`
|
59
60
|
|
60
61
|
## View Generator
|
62
|
+
|
61
63
|
1. Generate a controller
|
62
64
|
2. Add at least an index route for the controller
|
63
65
|
3. rails g repack:view name_of_view (should match controller name)
|
@@ -123,6 +125,7 @@ An alternative to adding the post build hook to `package.json` is to add `rake r
|
|
123
125
|
If you're using `[chunkhash]` in your build asset filenames (which you should be, if you want to cache them in production), you'll need to persist built assets between deployments. Consider in-flight requests at the time of deployment: they'll receive paths based on the old `manifest.json`, not the new one.
|
124
126
|
|
125
127
|
## Example Apps
|
128
|
+
|
126
129
|
* [basic](https://github.com/cottonwoodcoding/webpack-rails-react-basic)
|
127
130
|
* [react-router](https://github.com/cottonwoodcoding/webpack-rails-react-router)
|
128
131
|
* [redux](https://github.com/cottonwoodcoding/webpack-rails-react-redux)
|
@@ -134,8 +137,6 @@ If you're using `[chunkhash]` in your build asset filenames (which you should be
|
|
134
137
|
* Integration tests
|
135
138
|
* Port example apps to Repack
|
136
139
|
|
137
|
-
|
138
|
-
|
139
140
|
## Contributing
|
140
141
|
|
141
142
|
Pull requests & issues welcome. Advice & criticism regarding webpack config approach also welcome.
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { browserHistory } from 'react-router';
|
2
|
+
import { setFlash } from './flash';
|
3
|
+
import Auth from 'j-toker';
|
4
|
+
|
5
|
+
const logout = () => {
|
6
|
+
return { type: 'LOGOUT' }
|
7
|
+
}
|
8
|
+
|
9
|
+
const login = (user) => {
|
10
|
+
return { type: 'LOGIN', user }
|
11
|
+
}
|
12
|
+
|
13
|
+
const authErrors = (errors) => {
|
14
|
+
let message = '';
|
15
|
+
let msgType = 'error';
|
16
|
+
errors.forEach( error => {
|
17
|
+
message += `${error} `
|
18
|
+
});
|
19
|
+
return { type: 'SET_FLASH', message, msgType }
|
20
|
+
}
|
21
|
+
|
22
|
+
export const handleLogin = (email, password) => {
|
23
|
+
return(dispatch) => {
|
24
|
+
Auth.emailSignIn({
|
25
|
+
email,
|
26
|
+
password
|
27
|
+
}).then( user => {
|
28
|
+
dispatch(login(user.data));
|
29
|
+
browserHistory.push('/');
|
30
|
+
}).fail( res => {
|
31
|
+
dispatch(authErrors(res.data.errors));
|
32
|
+
});
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
export const handleLogout = () => {
|
37
|
+
return(dispatch) => {
|
38
|
+
Auth.signOut()
|
39
|
+
.then( res => {
|
40
|
+
dispatch(logout());
|
41
|
+
browserHistory.push('/login');
|
42
|
+
});
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
export const handleSignUp = (email, password) => {
|
47
|
+
return(dispatch) => {
|
48
|
+
Auth.emailSignUp({
|
49
|
+
email,
|
50
|
+
password,
|
51
|
+
password_confirmation: password
|
52
|
+
}).then( user => {
|
53
|
+
dispatch(login(user.data));
|
54
|
+
browserHistory.push('/');
|
55
|
+
}).fail( res => {
|
56
|
+
dispatch(authErrors(res.data.errors.full_messages));
|
57
|
+
});
|
58
|
+
}
|
59
|
+
}
|
@@ -1,11 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
|
3
3
|
class Loading extends React.Component {
|
4
|
-
|
5
|
-
|
6
|
-
this.state = { isLoading: false };
|
7
|
-
let destructTimeout;
|
8
|
-
}
|
4
|
+
state = { isLoading: false };
|
5
|
+
destructTimeout;
|
9
6
|
|
10
7
|
componentDidMount() {
|
11
8
|
this.setState({ isLoading: true });
|
@@ -22,18 +19,17 @@ class Loading extends React.Component {
|
|
22
19
|
}
|
23
20
|
|
24
21
|
render() {
|
25
|
-
|
26
|
-
|
27
|
-
} else {
|
28
|
-
clearTimeout(this.destructTimeout);
|
29
|
-
}
|
22
|
+
let { info } = this.props;
|
23
|
+
info = info === undefined ? '' : info
|
30
24
|
|
25
|
+
if(this.state.isLoading)
|
26
|
+
this.selfDestruct();
|
31
27
|
return (
|
32
28
|
<div>
|
33
29
|
{ this.state.isLoading ?
|
34
|
-
<span className="loading">{`Loading ${
|
30
|
+
<span className="loading">{`Loading ${info}`}</span>
|
35
31
|
:
|
36
|
-
<span>{`No ${
|
32
|
+
<span>{`No ${info} found`}</span>
|
37
33
|
}
|
38
34
|
</div>
|
39
35
|
)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { connect } from 'react-redux';
|
3
|
+
import Navbar from '../components/Navbar';
|
4
|
+
import FlashMessage from '../components/FlashMessage';
|
5
|
+
import { clearFlash } from '../actions/flash';
|
6
|
+
import Auth from 'j-toker';
|
7
|
+
|
8
|
+
class App extends React.Component {
|
9
|
+
componentDidMount() {
|
10
|
+
let { dispatch, history } = this.props;
|
11
|
+
|
12
|
+
Auth.configure({
|
13
|
+
apiUrl: '/api'
|
14
|
+
});
|
15
|
+
|
16
|
+
Auth.validateToken()
|
17
|
+
.then( user => {
|
18
|
+
dispatch({ type: 'LOGIN', ...user.data });
|
19
|
+
})
|
20
|
+
.fail( () => {
|
21
|
+
history.push('/login');
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
componentDidUpdate() {
|
26
|
+
let { dispatch, history } = this.props;
|
27
|
+
dispatch(clearFlash());
|
28
|
+
}
|
29
|
+
|
30
|
+
render() {
|
31
|
+
let { auth, children } = this.props;
|
32
|
+
|
33
|
+
return(
|
34
|
+
<div>
|
35
|
+
<Navbar />
|
36
|
+
<div style={{ marginBottom: '30px' }}>
|
37
|
+
<FlashMessage />
|
38
|
+
</div>
|
39
|
+
<div className='container'>
|
40
|
+
{ children }
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
export default connect()(App);
|
48
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { Route, IndexRoute, browserHistory } from 'react-router';
|
3
|
+
import App from './containers/App';
|
4
|
+
import NoMatch from './components/NoMatch';
|
5
|
+
import Login from './components/Login';
|
6
|
+
import SignUp from './components/SignUp';
|
7
|
+
import { UserAuthWrapper } from 'redux-auth-wrapper';
|
8
|
+
import Loading from './components/Loading';
|
9
|
+
|
10
|
+
const UserIsAuthenticated = UserAuthWrapper({
|
11
|
+
authSelector: state => state.auth,
|
12
|
+
predicate: auth => auth.isAuthenticated,
|
13
|
+
authenticatingSelector: state => state.auth.loading,
|
14
|
+
LoadingComponent: Loading
|
15
|
+
});
|
16
|
+
|
17
|
+
export default (
|
18
|
+
<Route>
|
19
|
+
|
20
|
+
<Route path="/" component={App}>
|
21
|
+
<Route path='/login' component={Login} />
|
22
|
+
<Route path='/sign_up' component={SignUp} />
|
23
|
+
</Route>
|
24
|
+
|
25
|
+
<Route path="*" status={404} component={NoMatch} />
|
26
|
+
</Route>
|
27
|
+
)
|
@@ -0,0 +1,212 @@
|
|
1
|
+
module Repack
|
2
|
+
# :nodoc:
|
3
|
+
class GodInstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../../../example", __FILE__)
|
5
|
+
desc "Install everything you need for a basic repack integration with react router / redux / devise / token auth"
|
6
|
+
|
7
|
+
def check_god_mode
|
8
|
+
unless yes?('Is this a new application? (yes \ no)')
|
9
|
+
raise 'GOD MODE is for new apps only. Run again at your own risk!'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_package_json
|
14
|
+
copy_file "package.json", "package.json"
|
15
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
16
|
+
<<-'RUBY'
|
17
|
+
"react-router": "^2.4.1",
|
18
|
+
"react-redux": "^4.4.5",
|
19
|
+
"redux": "^3.5.2",
|
20
|
+
"redux-thunk": "^2.1.0",
|
21
|
+
"react-router-redux": "^4.0.5",
|
22
|
+
"redux-auth-wrapper": "^1.0.0",
|
23
|
+
RUBY
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_webpack_conf
|
28
|
+
copy_file "webpack.config.js", "config/webpack.config.js"
|
29
|
+
if yes?('Are you going to be deploying to heroku? (yes \ no)')
|
30
|
+
puts 'Copying Heroku Webpack Config!'
|
31
|
+
copy_file "webpack.config.heroku.js", "config/webpack.config.heroku.js"
|
32
|
+
puts 'Adding Basic Puma Proc File'
|
33
|
+
copy_file "Procfile", 'Procfile'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_webpack_application_js
|
38
|
+
empty_directory "client"
|
39
|
+
empty_directory "client/containers"
|
40
|
+
empty_directory "client/components"
|
41
|
+
empty_directory "client/__tests__"
|
42
|
+
empty_directory "client/__tests__/__mocks__"
|
43
|
+
copy_file "babelrc", "./.babelrc"
|
44
|
+
copy_file "styleMock.js", "client/__tests__/__mocks__/styleMock.js"
|
45
|
+
copy_file "fileMock.js", "client/__tests__/__mocks__/fileMock.js"
|
46
|
+
end
|
47
|
+
|
48
|
+
def layouts
|
49
|
+
layouts_dir = 'app/views/layouts'
|
50
|
+
|
51
|
+
application_view = "#{layouts_dir}/application.html.erb"
|
52
|
+
|
53
|
+
insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
|
54
|
+
<% if Rails.env.development? %>
|
55
|
+
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
56
|
+
<% end %>
|
57
|
+
RUBY
|
58
|
+
end
|
59
|
+
insert_into_file application_view, before: /<\/body>/ do <<-'RUBY'
|
60
|
+
<%= javascript_include_tag *webpack_asset_paths('application') %>
|
61
|
+
RUBY
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_to_gitignore
|
66
|
+
append_to_file ".gitignore" do
|
67
|
+
<<-EOF.strip_heredoc
|
68
|
+
/node_modules
|
69
|
+
/public/webpack
|
70
|
+
npm-debug.log
|
71
|
+
EOF
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.frontend_config(frontend_gem, sheet_imports, sheet_name = 'application.css', new_sheet_name = 'application.scss')
|
76
|
+
begin
|
77
|
+
gem frontend_gem
|
78
|
+
File.rename "app/assets/stylesheets/#{sheet_name}", "app/assets/stylesheets/#{new_sheet_name}"
|
79
|
+
File.open("app/assets/stylesheets/#{new_sheet_name}", 'w+') do |f|
|
80
|
+
sheet_imports.each do |import|
|
81
|
+
f.write("@import #{import}; \n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
rescue => e
|
85
|
+
puts "Error While Setting Up Frontend Framework: #{e}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def finishing_god_move
|
90
|
+
base_sheet_path = "app/assets/stylesheets"
|
91
|
+
nav_template = ask('Frontend Framework: 1) Materialize, 2) Bootstrap, 3) None').strip
|
92
|
+
case nav_template
|
93
|
+
when '1'
|
94
|
+
sheet_imports = [ 'materialize', 'alert' ]
|
95
|
+
gem 'materialize-sass'
|
96
|
+
if File.exists? "#{base_sheet_path}/application.css"
|
97
|
+
File.rename "#{base_sheet_path}/application.css", "#{base_sheet_path}/application.scss"
|
98
|
+
end
|
99
|
+
File.open("#{base_sheet_path}/application.scss", 'w+') do |f|
|
100
|
+
sheet_imports.each do |import|
|
101
|
+
f.write("@import '#{import}'; \n")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
copy_file "boilerplate/god_mode/components/MaterialNavbar.js", "client/components/Navbar.js"
|
105
|
+
when '2'
|
106
|
+
sheet_imports = [ 'bootstrap-sprockets', 'bootstrap', 'alert' ]
|
107
|
+
gem 'bootstrap-sass'
|
108
|
+
if File.exists? "#{base_sheet_path}/application.css"
|
109
|
+
File.rename "#{base_sheet_path}/application.css", "#{base_sheet_path}/application.scss"
|
110
|
+
end
|
111
|
+
File.open("#{base_sheet_path}/application.scss", 'w+') do |f|
|
112
|
+
sheet_imports.each do |import|
|
113
|
+
f.write("@import '#{import}'; \n")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
copy_file "boilerplate/god_mode/components/BootstrapNavbar.js", "client/components/Navbar.js"
|
117
|
+
when '3'
|
118
|
+
puts 'No Navbar template, all the components are ready for you to implement however you want.'
|
119
|
+
else
|
120
|
+
puts 'Wrong template choice, try again!'
|
121
|
+
finishing_god_move
|
122
|
+
end
|
123
|
+
|
124
|
+
if nav_template == '3'
|
125
|
+
copy_file "boilerplate/god_mode/containers/NoNavApp.js", "client/containers/App.js"
|
126
|
+
else
|
127
|
+
copy_file "boilerplate/god_mode/containers/TokenApp.js", "client/containers/App.js"
|
128
|
+
end
|
129
|
+
|
130
|
+
copy_file "boilerplate/router_redux/application.js", "client/application.js"
|
131
|
+
copy_file "boilerplate/god_mode/tokenRoutes.js", "client/routes.js"
|
132
|
+
copy_file "boilerplate/router_redux/store.js", "client/store.js"
|
133
|
+
copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
|
134
|
+
copy_file "boilerplate/god_mode/actions/tokenAuth.js", "client/actions/auth.js"
|
135
|
+
copy_file "boilerplate/god_mode/actions/flash.js", "client/actions/flash.js"
|
136
|
+
copy_file "boilerplate/god_mode/components/FlashMessage.js", "client/components/FlashMessage.js"
|
137
|
+
copy_file "boilerplate/god_mode/components/Login.js", "client/components/Login.js"
|
138
|
+
copy_file "boilerplate/god_mode/components/SignUp.js", "client/components/SignUp.js"
|
139
|
+
copy_file "boilerplate/god_mode/components/Loading.js", "client/components/Loading.js"
|
140
|
+
copy_file "boilerplate/god_mode/reducers/auth.js", "client/reducers/auth.js"
|
141
|
+
copy_file "boilerplate/god_mode/reducers/flash.js", "client/reducers/flash.js"
|
142
|
+
copy_file "boilerplate/god_mode/reducers/index.js", "client/reducers/index.js"
|
143
|
+
copy_file "boilerplate/god_mode/scss/alert.css.scss", "app/assets/stylesheets/alert.css.scss"
|
144
|
+
|
145
|
+
gem "devise"
|
146
|
+
gem 'omniauth'
|
147
|
+
gem 'devise_token_auth'
|
148
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
149
|
+
<<-'RUBY'
|
150
|
+
"j-toker": "^0.0.10-beta3",
|
151
|
+
RUBY
|
152
|
+
end
|
153
|
+
|
154
|
+
insert_into_file './app/controllers/application_controller.rb', after: /ActionController::Base\n/ do
|
155
|
+
<<-'RUBY'
|
156
|
+
skip_before_action :verify_authenticity_token
|
157
|
+
RUBY
|
158
|
+
end
|
159
|
+
|
160
|
+
Bundler.with_clean_env do
|
161
|
+
run "bundle update"
|
162
|
+
end
|
163
|
+
|
164
|
+
run 'bin/spring stop'
|
165
|
+
generate "devise:install"
|
166
|
+
run "bundle exec rake db:create"
|
167
|
+
model_name = ask("What would you like the devise model to be called? [user]")
|
168
|
+
model_name = "user" if model_name.blank?
|
169
|
+
|
170
|
+
mount_point = ask("Auth Mount Point [api/auth]")
|
171
|
+
mount_point = "api/auth" if mount_point.blank?
|
172
|
+
generate "devise_token_auth:install #{model_name.titleize} #{mount_point}"
|
173
|
+
|
174
|
+
run 'bundle exec rake db:migrate'
|
175
|
+
end
|
176
|
+
|
177
|
+
def whats_next
|
178
|
+
puts <<-EOF.strip_heredoc
|
179
|
+
██████╗ ██████╗ ██████╗ ███╗ ███╗ ██████╗ ██████╗ ███████╗ ███████╗███╗ ██╗ █████╗ ██████╗ ██╗ ███████╗██████╗
|
180
|
+
██╔════╝ ██╔═══██╗██╔══██╗ ████╗ ████║██╔═══██╗██╔══██╗██╔════╝ ██╔════╝████╗ ██║██╔══██╗██╔══██╗██║ ██╔════╝██╔══██╗
|
181
|
+
██║ ███╗██║ ██║██║ ██║ ██╔████╔██║██║ ██║██║ ██║█████╗ █████╗ ██╔██╗ ██║███████║██████╔╝██║ █████╗ ██║ ██║
|
182
|
+
██║ ██║██║ ██║██║ ██║ ██║╚██╔╝██║██║ ██║██║ ██║██╔══╝ ██╔══╝ ██║╚██╗██║██╔══██║██╔══██╗██║ ██╔══╝ ██║ ██║
|
183
|
+
╚██████╔╝╚██████╔╝██████╔╝ ██║ ╚═╝ ██║╚██████╔╝██████╔╝███████╗ ███████╗██║ ╚████║██║ ██║██████╔╝███████╗███████╗██████╔╝
|
184
|
+
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚══════╝╚═════╝
|
185
|
+
|
186
|
+
Note: If you chose a frontend framework (Materialize / Bootstrap) you still need to install the gem and configure it in your project.
|
187
|
+
|
188
|
+
EOF
|
189
|
+
puts <<-EOF.strip_heredoc
|
190
|
+
We've set up the basics of repack for you, but you'll still
|
191
|
+
need to:
|
192
|
+
1. yarn install or npm install
|
193
|
+
2. Add an element with an id of 'app' to your layout
|
194
|
+
3. To disable hot module replacement remove <script src="http://localhost:3808/webpack-dev-server.js"></script> from layout
|
195
|
+
4. Run 'yarn / npm dev_server' to run the webpack-dev-server
|
196
|
+
5. Run 'bundle exec rails s' to run the rails server (both servers must be running)
|
197
|
+
6. If you are using react-router or god mode and want to sync server routes add:
|
198
|
+
get '*unmatched_route', to: <your client controller>#<default action>
|
199
|
+
This must be the very last route in your routes.rb file
|
200
|
+
e.g. get '*unmatched_route', to: 'home#index'
|
201
|
+
FOR HEROKU DEPLOYS:
|
202
|
+
1. yarn / npm heroku-setup
|
203
|
+
2. Push to heroku the post-build hook will take care of the rest
|
204
|
+
See the README.md for this gem at
|
205
|
+
https://github.com/cottonwoodcoding/repack/blob/master/README.md
|
206
|
+
for more info.
|
207
|
+
|
208
|
+
Thanks for using Repack!
|
209
|
+
EOF
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -1,47 +1,11 @@
|
|
1
1
|
module Repack
|
2
2
|
# :nodoc:
|
3
3
|
class InstallGenerator < ::Rails::Generators::Base
|
4
|
-
@yarn_installed = false
|
5
4
|
source_root File.expand_path("../../../../example", __FILE__)
|
6
5
|
desc "Install everything you need for a basic repack integration"
|
7
|
-
class_option :router, type: :boolean, default: false, description: 'Add React Router'
|
8
|
-
class_option :redux, type: :boolean, default: false, description: 'Add Redux'
|
9
|
-
class_option :god, type: :boolean, default: false, description: 'Router, Redux, Devise, Auth, GOD'
|
10
|
-
|
11
|
-
def check_god_mode
|
12
|
-
if options[:god]
|
13
|
-
unless yes?('Is this is new application?')
|
14
|
-
raise 'GOD MODE is for new apps only. Run again at your own risk!'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
6
|
|
19
7
|
def copy_package_json
|
20
8
|
copy_file "package.json", "package.json"
|
21
|
-
if options[:router] || options[:god]
|
22
|
-
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
23
|
-
<<-'RUBY'
|
24
|
-
"react-router": "^2.4.1",
|
25
|
-
RUBY
|
26
|
-
end
|
27
|
-
end
|
28
|
-
if options[:redux] || options[:god]
|
29
|
-
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
30
|
-
<<-'RUBY'
|
31
|
-
"react-redux": "^4.4.5",
|
32
|
-
"redux": "^3.5.2",
|
33
|
-
"redux-thunk": "^2.1.0",
|
34
|
-
RUBY
|
35
|
-
end
|
36
|
-
end
|
37
|
-
if options[:router] && options[:redux] || options[:god]
|
38
|
-
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
39
|
-
<<-'RUBY'
|
40
|
-
"react-router-redux": "^4.0.5",
|
41
|
-
"redux-auth-wrapper": "^1.0.0",
|
42
|
-
RUBY
|
43
|
-
end
|
44
|
-
end
|
45
9
|
end
|
46
10
|
|
47
11
|
def copy_webpack_conf
|
@@ -63,75 +27,25 @@ module Repack
|
|
63
27
|
copy_file "babelrc", "./.babelrc"
|
64
28
|
copy_file "styleMock.js", "client/__tests__/__mocks__/styleMock.js"
|
65
29
|
copy_file "fileMock.js", "client/__tests__/__mocks__/fileMock.js"
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
create_file "client/actions.js"
|
72
|
-
copy_file "boilerplate/router/App.js", "client/containers/App.js"
|
73
|
-
copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
|
74
|
-
elsif options[:router]
|
75
|
-
copy_file "boilerplate/router/application.js", "client/application.js"
|
76
|
-
copy_file "boilerplate/routes.js", "client/routes.js"
|
77
|
-
copy_file "boilerplate/router/App.js", "client/containers/App.js"
|
78
|
-
copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
|
79
|
-
elsif options[:redux]
|
80
|
-
copy_file "boilerplate/redux/application.js", "client/application.js"
|
81
|
-
copy_file "boilerplate/redux/store.js", "client/store.js"
|
82
|
-
copy_file "boilerplate/redux/reducers.js", "client/reducers/index.js"
|
83
|
-
create_file "client/actions.js"
|
84
|
-
copy_file "boilerplate/App.js", "client/containers/App.js"
|
85
|
-
else
|
86
|
-
unless options[:god]
|
87
|
-
copy_file "boilerplate/application.js", "client/application.js"
|
88
|
-
copy_file "boilerplate/App.js", "client/containers/App.js"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
haml_installed = Gem.loaded_specs.has_key? 'haml-rails'
|
93
|
-
layouts_dir = 'app/views/layouts'
|
94
|
-
haml_installed = Gem.loaded_specs.has_key? 'haml-rails'
|
30
|
+
copy_file "boilerplate/application.js", "client/application.js"
|
31
|
+
copy_file "boilerplate/App.js", "client/containers/App.js"
|
32
|
+
end
|
33
|
+
|
34
|
+
def layouts
|
95
35
|
layouts_dir = 'app/views/layouts'
|
96
36
|
|
97
|
-
application_view =
|
98
|
-
|
99
|
-
if haml_installed
|
100
|
-
if yes?('Convert all existing ERB views into HAML? (yes / no)')
|
101
|
-
begin
|
102
|
-
require 'html2haml'
|
103
|
-
rescue LoadError
|
104
|
-
`gem install html2haml`
|
105
|
-
end
|
106
|
-
`find . -name \*.erb -print | sed 'p;s/.erb$/.haml/' | xargs -n2 html2haml`
|
107
|
-
`rm #{layouts_dir}/application.html.erb`
|
108
|
-
end
|
109
|
-
|
110
|
-
insert_into_file application_view, before: /%body/ do
|
111
|
-
<<-'RUBY'
|
112
|
-
- if Rails.env.development?
|
113
|
-
%script{:src => "http://localhost:3808/webpack-dev-server.js"}
|
114
|
-
RUBY
|
115
|
-
end
|
116
|
-
|
117
|
-
insert_into_file application_view, after: /= yield/ do
|
118
|
-
<<-'RUBY'
|
37
|
+
application_view = "#{layouts_dir}/application.html.erb"
|
119
38
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
|
125
|
-
<% if Rails.env.development? %>
|
126
|
-
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
127
|
-
<% end %>
|
39
|
+
insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
|
40
|
+
<% if Rails.env.development? %>
|
41
|
+
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
42
|
+
<% end %>
|
128
43
|
RUBY
|
129
44
|
end
|
130
45
|
insert_into_file application_view, before: /<\/body>/ do <<-'RUBY'
|
131
46
|
<%= javascript_include_tag *webpack_asset_paths('application') %>
|
132
47
|
RUBY
|
133
48
|
end
|
134
|
-
end
|
135
49
|
end
|
136
50
|
|
137
51
|
def add_to_gitignore
|
@@ -144,91 +58,7 @@ module Repack
|
|
144
58
|
end
|
145
59
|
end
|
146
60
|
|
147
|
-
def finishing_god_move
|
148
|
-
if options[:god]
|
149
|
-
nav_template = ask('Frontend Framework: 1) Materialize, 2) Bootstrap, 3) None').strip
|
150
|
-
case nav_template
|
151
|
-
when '1'
|
152
|
-
copy_file "boilerplate/god_mode/components/MaterialNavbar.js", "client/components/Navbar.js"
|
153
|
-
when '2'
|
154
|
-
copy_file "boilerplate/god_mode/components/BootstrapNavbar.js", "client/components/Navbar.js"
|
155
|
-
when '3'
|
156
|
-
puts 'No Navbar template, all the components are ready for you to implement however you want.'
|
157
|
-
else
|
158
|
-
puts 'Wrong template choice, try again!'
|
159
|
-
finishing_god_move
|
160
|
-
end
|
161
|
-
|
162
|
-
if nav_template == '3'
|
163
|
-
copy_file "boilerplate/god_mode/containers/NoNavApp.js", "client/containers/App.js"
|
164
|
-
else
|
165
|
-
copy_file "boilerplate/god_mode/containers/App.js", "client/containers/App.js"
|
166
|
-
end
|
167
|
-
|
168
|
-
copy_file "boilerplate/router_redux/application.js", "client/application.js"
|
169
|
-
copy_file "boilerplate/god_mode/routes.js", "client/routes.js"
|
170
|
-
copy_file "boilerplate/router_redux/store.js", "client/store.js"
|
171
|
-
copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
|
172
|
-
copy_file "boilerplate/god_mode/actions/auth.js", "client/actions/auth.js"
|
173
|
-
copy_file "boilerplate/god_mode/actions/flash.js", "client/actions/flash.js"
|
174
|
-
copy_file "boilerplate/god_mode/components/FlashMessage.js", "client/components/FlashMessage.js"
|
175
|
-
copy_file "boilerplate/god_mode/components/Login.js", "client/components/Login.js"
|
176
|
-
copy_file "boilerplate/god_mode/components/SignUp.js", "client/components/SignUp.js"
|
177
|
-
copy_file "boilerplate/god_mode/components/Loading.js", "client/components/Loading.js"
|
178
|
-
copy_file "boilerplate/god_mode/reducers/auth.js", "client/reducers/auth.js"
|
179
|
-
copy_file "boilerplate/god_mode/reducers/flash.js", "client/reducers/flash.js"
|
180
|
-
copy_file "boilerplate/god_mode/reducers/index.js", "client/reducers/index.js"
|
181
|
-
copy_file "boilerplate/god_mode/controllers/api/users_controller.rb", "app/controllers/api/users_controller.rb"
|
182
|
-
copy_file "boilerplate/god_mode/scss/alert.css.scss", "app/assets/stylesheets/alert.css.scss"
|
183
|
-
|
184
|
-
gem "devise"
|
185
|
-
Bundler.with_clean_env do
|
186
|
-
run "bundle install"
|
187
|
-
end
|
188
|
-
|
189
|
-
run 'bin/spring stop'
|
190
|
-
generate "devise:install"
|
191
|
-
run "bundle exec rake db:create"
|
192
|
-
model_name = ask("What would you like the user model to be called? [user]")
|
193
|
-
model_name = "user" if model_name.blank?
|
194
|
-
generate "devise", model_name
|
195
|
-
generate "devise:controllers #{model_name.pluralize}"
|
196
|
-
|
197
|
-
insert_into_file 'config/routes.rb', after: /devise_for :users/ do <<-'RUBY'
|
198
|
-
, controllers: {
|
199
|
-
sessions: 'users/sessions',
|
200
|
-
registrations: 'users/registrations'
|
201
|
-
}
|
202
|
-
namespace :api do
|
203
|
-
get 'logged_in_user', to: 'users#logged_in_user'
|
204
|
-
end
|
205
|
-
RUBY
|
206
|
-
end
|
207
|
-
['./app/controllers/users/sessions_controller.rb', './app/controllers/users/registrations_controller.rb'].each do |c|
|
208
|
-
insert_into_file c, after: /Devise::\W*.*\n/ do <<-'RUBY'
|
209
|
-
skip_before_action :verify_authenticity_token
|
210
|
-
respond_to :json
|
211
|
-
RUBY
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
run 'bundle exec rake db:migrate'
|
216
|
-
end
|
217
|
-
|
218
61
|
def whats_next
|
219
|
-
if options[:god]
|
220
|
-
puts <<-EOF.strip_heredoc
|
221
|
-
██████╗ ██████╗ ██████╗ ███╗ ███╗ ██████╗ ██████╗ ███████╗ ███████╗███╗ ██╗ █████╗ ██████╗ ██╗ ███████╗██████╗
|
222
|
-
██╔════╝ ██╔═══██╗██╔══██╗ ████╗ ████║██╔═══██╗██╔══██╗██╔════╝ ██╔════╝████╗ ██║██╔══██╗██╔══██╗██║ ██╔════╝██╔══██╗
|
223
|
-
██║ ███╗██║ ██║██║ ██║ ██╔████╔██║██║ ██║██║ ██║█████╗ █████╗ ██╔██╗ ██║███████║██████╔╝██║ █████╗ ██║ ██║
|
224
|
-
██║ ██║██║ ██║██║ ██║ ██║╚██╔╝██║██║ ██║██║ ██║██╔══╝ ██╔══╝ ██║╚██╗██║██╔══██║██╔══██╗██║ ██╔══╝ ██║ ██║
|
225
|
-
╚██████╔╝╚██████╔╝██████╔╝ ██║ ╚═╝ ██║╚██████╔╝██████╔╝███████╗ ███████╗██║ ╚████║██║ ██║██████╔╝███████╗███████╗██████╔╝
|
226
|
-
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚══════╝╚═════╝
|
227
|
-
|
228
|
-
Note: If you chose a frontend framework (Materialize / Bootstrap) you still need to install the gem and configure it in your project.
|
229
|
-
|
230
|
-
EOF
|
231
|
-
end
|
232
62
|
puts <<-EOF.strip_heredoc
|
233
63
|
We've set up the basics of repack for you, but you'll still
|
234
64
|
need to:
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Repack
|
2
|
+
# :nodoc:
|
3
|
+
class ReduxInstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../../../example", __FILE__)
|
5
|
+
desc "Install everything you need for a basic repack integration and redux for state management"
|
6
|
+
|
7
|
+
def copy_package_json
|
8
|
+
copy_file "package.json", "package.json"
|
9
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
10
|
+
<<-'RUBY'
|
11
|
+
"react-redux": "^4.4.5",
|
12
|
+
"redux": "^3.5.2",
|
13
|
+
"redux-thunk": "^2.1.0",
|
14
|
+
RUBY
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_webpack_conf
|
19
|
+
copy_file "webpack.config.js", "config/webpack.config.js"
|
20
|
+
if yes?('Are you going to be deploying to heroku? (yes \ no)')
|
21
|
+
puts 'Copying Heroku Webpack Config!'
|
22
|
+
copy_file "webpack.config.heroku.js", "config/webpack.config.heroku.js"
|
23
|
+
puts 'Adding Basic Puma Proc File'
|
24
|
+
copy_file "Procfile", 'Procfile'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_webpack_application_js
|
29
|
+
empty_directory "client"
|
30
|
+
empty_directory "client/containers"
|
31
|
+
empty_directory "client/components"
|
32
|
+
empty_directory "client/__tests__"
|
33
|
+
empty_directory "client/__tests__/__mocks__"
|
34
|
+
copy_file "babelrc", "./.babelrc"
|
35
|
+
copy_file "styleMock.js", "client/__tests__/__mocks__/styleMock.js"
|
36
|
+
copy_file "fileMock.js", "client/__tests__/__mocks__/fileMock.js"
|
37
|
+
copy_file "boilerplate/redux/application.js", "client/application.js"
|
38
|
+
copy_file "boilerplate/redux/store.js", "client/store.js"
|
39
|
+
copy_file "boilerplate/redux/reducers.js", "client/reducers/index.js"
|
40
|
+
create_file "client/actions.js"
|
41
|
+
copy_file "boilerplate/App.js", "client/containers/App.js"
|
42
|
+
end
|
43
|
+
|
44
|
+
def layouts
|
45
|
+
layouts_dir = 'app/views/layouts'
|
46
|
+
|
47
|
+
application_view = "#{layouts_dir}/application.html.erb"
|
48
|
+
|
49
|
+
insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
|
50
|
+
<% if Rails.env.development? %>
|
51
|
+
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
52
|
+
<% end %>
|
53
|
+
RUBY
|
54
|
+
end
|
55
|
+
insert_into_file application_view, before: /<\/body>/ do <<-'RUBY'
|
56
|
+
<%= javascript_include_tag *webpack_asset_paths('application') %>
|
57
|
+
RUBY
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_to_gitignore
|
62
|
+
append_to_file ".gitignore" do
|
63
|
+
<<-EOF.strip_heredoc
|
64
|
+
/node_modules
|
65
|
+
/public/webpack
|
66
|
+
npm-debug.log
|
67
|
+
EOF
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def whats_next
|
72
|
+
puts <<-EOF.strip_heredoc
|
73
|
+
We've set up the basics of repack for you, but you'll still
|
74
|
+
need to:
|
75
|
+
1. yarn install or npm install
|
76
|
+
2. Add an element with an id of 'app' to your layout
|
77
|
+
3. To disable hot module replacement remove <script src="http://localhost:3808/webpack-dev-server.js"></script> from layout
|
78
|
+
4. Run 'yarn / npm dev_server' to run the webpack-dev-server
|
79
|
+
5. Run 'bundle exec rails s' to run the rails server (both servers must be running)
|
80
|
+
6. If you are using react-router or god mode and want to sync server routes add:
|
81
|
+
get '*unmatched_route', to: <your client controller>#<default action>
|
82
|
+
This must be the very last route in your routes.rb file
|
83
|
+
e.g. get '*unmatched_route', to: 'home#index'
|
84
|
+
FOR HEROKU DEPLOYS:
|
85
|
+
1. yarn / npm heroku-setup
|
86
|
+
2. Push to heroku the post-build hook will take care of the rest
|
87
|
+
See the README.md for this gem at
|
88
|
+
https://github.com/cottonwoodcoding/repack/blob/master/README.md
|
89
|
+
for more info.
|
90
|
+
|
91
|
+
Thanks for using Repack!
|
92
|
+
EOF
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Repack
|
2
|
+
# :nodoc:
|
3
|
+
class RouterInstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../../../example", __FILE__)
|
5
|
+
desc "Install everything you need for a basic repack integration with react router"
|
6
|
+
|
7
|
+
def copy_package_json
|
8
|
+
copy_file "package.json", "package.json"
|
9
|
+
|
10
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
11
|
+
<<-'RUBY'
|
12
|
+
"react-router": "^2.4.1",
|
13
|
+
RUBY
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_webpack_conf
|
18
|
+
copy_file "webpack.config.js", "config/webpack.config.js"
|
19
|
+
if yes?('Are you going to be deploying to heroku? (yes \ no)')
|
20
|
+
puts 'Copying Heroku Webpack Config!'
|
21
|
+
copy_file "webpack.config.heroku.js", "config/webpack.config.heroku.js"
|
22
|
+
puts 'Adding Basic Puma Proc File'
|
23
|
+
copy_file "Procfile", 'Procfile'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_webpack_application_js
|
28
|
+
empty_directory "client"
|
29
|
+
empty_directory "client/containers"
|
30
|
+
empty_directory "client/components"
|
31
|
+
empty_directory "client/__tests__"
|
32
|
+
empty_directory "client/__tests__/__mocks__"
|
33
|
+
copy_file "babelrc", "./.babelrc"
|
34
|
+
copy_file "styleMock.js", "client/__tests__/__mocks__/styleMock.js"
|
35
|
+
copy_file "fileMock.js", "client/__tests__/__mocks__/fileMock.js"
|
36
|
+
copy_file "boilerplate/router/application.js", "client/application.js"
|
37
|
+
copy_file "boilerplate/routes.js", "client/routes.js"
|
38
|
+
copy_file "boilerplate/router/App.js", "client/containers/App.js"
|
39
|
+
copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
|
40
|
+
end
|
41
|
+
|
42
|
+
def layouts
|
43
|
+
layouts_dir = 'app/views/layouts'
|
44
|
+
|
45
|
+
application_view = "#{layouts_dir}/application.html.erb"
|
46
|
+
|
47
|
+
insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
|
48
|
+
<% if Rails.env.development? %>
|
49
|
+
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
50
|
+
<% end %>
|
51
|
+
RUBY
|
52
|
+
end
|
53
|
+
insert_into_file application_view, before: /<\/body>/ do <<-'RUBY'
|
54
|
+
<%= javascript_include_tag *webpack_asset_paths('application') %>
|
55
|
+
RUBY
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_to_gitignore
|
60
|
+
append_to_file ".gitignore" do
|
61
|
+
<<-EOF.strip_heredoc
|
62
|
+
/node_modules
|
63
|
+
/public/webpack
|
64
|
+
npm-debug.log
|
65
|
+
EOF
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def whats_next
|
70
|
+
puts <<-EOF.strip_heredoc
|
71
|
+
We've set up the basics of repack for you, but you'll still
|
72
|
+
need to:
|
73
|
+
1. yarn install or npm install
|
74
|
+
2. Add an element with an id of 'app' to your layout
|
75
|
+
3. To disable hot module replacement remove <script src="http://localhost:3808/webpack-dev-server.js"></script> from layout
|
76
|
+
4. Run 'yarn / npm dev_server' to run the webpack-dev-server
|
77
|
+
5. Run 'bundle exec rails s' to run the rails server (both servers must be running)
|
78
|
+
6. If you are using react-router or god mode and want to sync server routes add:
|
79
|
+
get '*unmatched_route', to: <your client controller>#<default action>
|
80
|
+
This must be the very last route in your routes.rb file
|
81
|
+
e.g. get '*unmatched_route', to: 'home#index'
|
82
|
+
FOR HEROKU DEPLOYS:
|
83
|
+
1. yarn / npm heroku-setup
|
84
|
+
2. Push to heroku the post-build hook will take care of the rest
|
85
|
+
See the README.md for this gem at
|
86
|
+
https://github.com/cottonwoodcoding/repack/blob/master/README.md
|
87
|
+
for more info.
|
88
|
+
|
89
|
+
Thanks for using Repack!
|
90
|
+
EOF
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Repack
|
2
|
+
# :nodoc:
|
3
|
+
class RouterReduxInstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../../../example", __FILE__)
|
5
|
+
desc "Install everything you need for a basic repack integration with react router and redux"
|
6
|
+
|
7
|
+
def copy_package_json
|
8
|
+
copy_file "package.json", "package.json"
|
9
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
10
|
+
<<-'RUBY'
|
11
|
+
"react-router": "^2.4.1",
|
12
|
+
RUBY
|
13
|
+
end
|
14
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
15
|
+
<<-'RUBY'
|
16
|
+
"react-redux": "^4.4.5",
|
17
|
+
"redux": "^3.5.2",
|
18
|
+
"redux-thunk": "^2.1.0",
|
19
|
+
RUBY
|
20
|
+
end
|
21
|
+
insert_into_file './package.json', after: /dependencies\": {\n/ do
|
22
|
+
<<-'RUBY'
|
23
|
+
"react-router-redux": "^4.0.5",
|
24
|
+
"redux-auth-wrapper": "^1.0.0",
|
25
|
+
RUBY
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_webpack_conf
|
30
|
+
copy_file "webpack.config.js", "config/webpack.config.js"
|
31
|
+
if yes?('Are you going to be deploying to heroku? (yes \ no)')
|
32
|
+
puts 'Copying Heroku Webpack Config!'
|
33
|
+
copy_file "webpack.config.heroku.js", "config/webpack.config.heroku.js"
|
34
|
+
puts 'Adding Basic Puma Proc File'
|
35
|
+
copy_file "Procfile", 'Procfile'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_webpack_application_js
|
40
|
+
empty_directory "client"
|
41
|
+
empty_directory "client/containers"
|
42
|
+
empty_directory "client/components"
|
43
|
+
empty_directory "client/__tests__"
|
44
|
+
empty_directory "client/__tests__/__mocks__"
|
45
|
+
copy_file "babelrc", "./.babelrc"
|
46
|
+
copy_file "styleMock.js", "client/__tests__/__mocks__/styleMock.js"
|
47
|
+
copy_file "fileMock.js", "client/__tests__/__mocks__/fileMock.js"
|
48
|
+
copy_file "boilerplate/router_redux/application.js", "client/application.js"
|
49
|
+
copy_file "boilerplate/routes.js", "client/routes.js"
|
50
|
+
copy_file "boilerplate/router_redux/store.js", "client/store.js"
|
51
|
+
copy_file "boilerplate/router_redux/reducers.js", "client/reducers/index.js"
|
52
|
+
create_file "client/actions.js"
|
53
|
+
copy_file "boilerplate/router/App.js", "client/containers/App.js"
|
54
|
+
copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
|
55
|
+
end
|
56
|
+
|
57
|
+
def layouts
|
58
|
+
layouts_dir = 'app/views/layouts'
|
59
|
+
|
60
|
+
application_view = "#{layouts_dir}/application.html.erb"
|
61
|
+
|
62
|
+
insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
|
63
|
+
<% if Rails.env.development? %>
|
64
|
+
<script src="http://localhost:3808/webpack-dev-server.js"></script>
|
65
|
+
<% end %>
|
66
|
+
RUBY
|
67
|
+
end
|
68
|
+
insert_into_file application_view, before: /<\/body>/ do <<-'RUBY'
|
69
|
+
<%= javascript_include_tag *webpack_asset_paths('application') %>
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_to_gitignore
|
75
|
+
append_to_file ".gitignore" do
|
76
|
+
<<-EOF.strip_heredoc
|
77
|
+
/node_modules
|
78
|
+
/public/webpack
|
79
|
+
npm-debug.log
|
80
|
+
EOF
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def whats_next
|
85
|
+
puts <<-EOF.strip_heredoc
|
86
|
+
We've set up the basics of repack for you, but you'll still
|
87
|
+
need to:
|
88
|
+
1. yarn install or npm install
|
89
|
+
2. Add an element with an id of 'app' to your layout
|
90
|
+
3. To disable hot module replacement remove <script src="http://localhost:3808/webpack-dev-server.js"></script> from layout
|
91
|
+
4. Run 'yarn / npm dev_server' to run the webpack-dev-server
|
92
|
+
5. Run 'bundle exec rails s' to run the rails server (both servers must be running)
|
93
|
+
6. If you are using react-router or god mode and want to sync server routes add:
|
94
|
+
get '*unmatched_route', to: <your client controller>#<default action>
|
95
|
+
This must be the very last route in your routes.rb file
|
96
|
+
e.g. get '*unmatched_route', to: 'home#index'
|
97
|
+
FOR HEROKU DEPLOYS:
|
98
|
+
1. yarn / npm heroku-setup
|
99
|
+
2. Push to heroku the post-build hook will take care of the rest
|
100
|
+
See the README.md for this gem at
|
101
|
+
https://github.com/cottonwoodcoding/repack/blob/master/README.md
|
102
|
+
for more info.
|
103
|
+
|
104
|
+
Thanks for using Repack!
|
105
|
+
EOF
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/repack/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Jungst
|
@@ -9,22 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-04-
|
12
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.0.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 4.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: json
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
17
31
|
requirements:
|
18
32
|
- - ">="
|
19
33
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
34
|
+
version: 2.0.0
|
21
35
|
type: :runtime
|
22
36
|
prerelease: false
|
23
37
|
version_requirements: !ruby/object:Gem::Requirement
|
24
38
|
requirements:
|
25
39
|
- - ">="
|
26
40
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
41
|
+
version: 2.0.0
|
28
42
|
description: Production-tested, JavaScript-first tooling to use webpack within your
|
29
43
|
Rails application
|
30
44
|
email:
|
@@ -43,6 +57,7 @@ files:
|
|
43
57
|
- example/boilerplate/application.js
|
44
58
|
- example/boilerplate/god_mode/actions/auth.js
|
45
59
|
- example/boilerplate/god_mode/actions/flash.js
|
60
|
+
- example/boilerplate/god_mode/actions/tokenAuth.js
|
46
61
|
- example/boilerplate/god_mode/components/BootstrapNavbar.js
|
47
62
|
- example/boilerplate/god_mode/components/FlashMessage.js
|
48
63
|
- example/boilerplate/god_mode/components/Loading.js
|
@@ -51,12 +66,14 @@ files:
|
|
51
66
|
- example/boilerplate/god_mode/components/SignUp.js
|
52
67
|
- example/boilerplate/god_mode/containers/App.js
|
53
68
|
- example/boilerplate/god_mode/containers/NoNavApp.js
|
69
|
+
- example/boilerplate/god_mode/containers/TokenApp.js
|
54
70
|
- example/boilerplate/god_mode/controllers/api/users_controller.rb
|
55
71
|
- example/boilerplate/god_mode/reducers/auth.js
|
56
72
|
- example/boilerplate/god_mode/reducers/flash.js
|
57
73
|
- example/boilerplate/god_mode/reducers/index.js
|
58
74
|
- example/boilerplate/god_mode/routes.js
|
59
75
|
- example/boilerplate/god_mode/scss/alert.css.scss
|
76
|
+
- example/boilerplate/god_mode/tokenRoutes.js
|
60
77
|
- example/boilerplate/redux/application.js
|
61
78
|
- example/boilerplate/redux/reducers.js
|
62
79
|
- example/boilerplate/redux/store.js
|
@@ -77,7 +94,11 @@ files:
|
|
77
94
|
- example/styleMock.js
|
78
95
|
- example/webpack.config.heroku.js
|
79
96
|
- example/webpack.config.js
|
97
|
+
- lib/generators/repack/god_install_generator.rb
|
80
98
|
- lib/generators/repack/install_generator.rb
|
99
|
+
- lib/generators/repack/redux_install_generator.rb
|
100
|
+
- lib/generators/repack/router_install_generator.rb
|
101
|
+
- lib/generators/repack/router_redux_install_generator.rb
|
81
102
|
- lib/generators/repack/view_generator.rb
|
82
103
|
- lib/repack.rb
|
83
104
|
- lib/repack/helper.rb
|