repack 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3544828053114aa5dcc0d6dba65db42e243d6996
4
- data.tar.gz: db580c08614f6633a8e1eee96d650e8a6818a7bb
3
+ metadata.gz: 512edcf1b6ceeae486756f16c6de2035059bab31
4
+ data.tar.gz: 80d6ca9ca00b9fdba2b77ee02aae587116554581
5
5
  SHA512:
6
- metadata.gz: 1588340b6e9ec331bbe801975d475fda393a95ce525f36d08b426e7602436b0388d442064320d0d5709c7cf25dc6d52d17d1b3eb25c724c14bc6c3fb91e4627f
7
- data.tar.gz: 7749c7cd6ac80d28c3d514b99fe750f5b47dcfaf26eaaaa0cd76a069179374c2d64eb642e0f56780be3f0229ce022e0434e7cf9a4b91ea4d94a20c8326bb9fc0
6
+ metadata.gz: eca54c72ed38802324459e62fc1aa87269033c11cf6b180522a689eb63dbd9d15b5bfcd32c5585c9f29a33685cbdcd86220ca7bf1e416c6de421f4c5010bb97d
7
+ data.tar.gz: 5977c99360398ee72bf8b70a2eaf2bc93d00598e5de4e1fc41e509416af4fdedebe5215d8204fc5d3f284cf30017894490351cc98b195decd6290ad5abc280cd
data/example/babelrc CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- presets: ['latest', 'react', 'stage-2']
2
+ presets: ['env', 'react', 'stage-2']
3
3
  }
@@ -0,0 +1,74 @@
1
+ import { browserHistory } from 'react-router';
2
+ import { setFlash } from './flash';
3
+
4
+ const logout = () => {
5
+ return { type: 'LOGOUT' }
6
+ }
7
+
8
+ const login = (user) => {
9
+ return { type: 'LOGIN', user }
10
+ }
11
+
12
+ export const handleLogin = (email, password) => {
13
+ return(dispatch) => {
14
+ $.ajax({
15
+ url: '/users/sign_in',
16
+ type: 'POST',
17
+ dataType: 'JSON',
18
+ data: { user: { email, password } }
19
+ }).done( user => {
20
+ dispatch(login(user));
21
+ browserHistory.push('/')
22
+ }).fail( data => {
23
+ dispatch(setFlash('Error Logging In.', 'error'));
24
+ });
25
+ }
26
+ }
27
+
28
+ export const handleLogout = () => {
29
+ return(dispatch) => {
30
+ $.ajax({
31
+ url: '/users/sign_out',
32
+ type: 'DELETE',
33
+ dataType: 'JSON'
34
+ }).done( data => {
35
+ dispatch(logout());
36
+ browserHistory.push('/');
37
+ }).fail( data => {
38
+ dispatch(setFlash('Error Logging Out.', 'error'));
39
+ });
40
+ }
41
+ }
42
+
43
+ export const refreshLogin = () => {
44
+ return(dispatch) => {
45
+ $.ajax({
46
+ url: '/api/logged_in_user',
47
+ type: 'GET',
48
+ dataType: 'JSON'
49
+ }).done( user => {
50
+ if(user.id)
51
+ dispatch(login(user))
52
+ else
53
+ dispatch(logout());
54
+ }).fail( data => {
55
+ dispatch(setFlash('Error Refreshing User Data.', 'error'));
56
+ });
57
+ }
58
+ }
59
+
60
+ export const handleSignUp = (email, password) => {
61
+ return(dispatch) => {
62
+ $.ajax({
63
+ url: '/users',
64
+ type: 'POST',
65
+ dataType: 'JSON',
66
+ data: { user: { email, password } }
67
+ }).done( user => {
68
+ dispatch(login(user));
69
+ browserHistory.push('/');
70
+ }).fail(data => {
71
+ dispatch(setFlash('Error Creating Account.', 'error'));
72
+ });
73
+ }
74
+ }
@@ -0,0 +1,11 @@
1
+ export const clearFlash = () => {
2
+ return { type: "CLEAR_FLASH" }
3
+ }
4
+
5
+ export const setFlash = (message, msgType) => {
6
+ return {
7
+ type: 'SET_FLASH',
8
+ message,
9
+ msgType
10
+ }
11
+ }
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { connect } from 'react-redux';
3
+ import { clearFlash } from '../actions/flash.js';
4
+
5
+ const fadeFlash = (dispatch) => {
6
+ setTimeout( () => {
7
+ dispatch(clearFlash())
8
+ }, 15000)
9
+ }
10
+
11
+ const FlashMessage= ({ flash, dispatch }) => {
12
+ if (flash.message) {
13
+ return (
14
+ <div
15
+ id="alert"
16
+ className={`alert alert-${flash.msgType} center`}
17
+ style={{ width: '90%', margin: '0 auto'}}
18
+ onClick={ (e) => {
19
+ e.preventDefault
20
+ dispatch(clearFlash())
21
+ }}
22
+ >
23
+ {flash.message}
24
+ { fadeFlash(dispatch) }
25
+ </div>
26
+ )
27
+ } else {
28
+ return null
29
+ }
30
+ }
31
+
32
+ FlashMessage.PropTypes = {
33
+ flash: React.PropTypes.object,
34
+ dispatch: React.PropTypes.func,
35
+ }
36
+
37
+ const mapStateToProps = (state) => {
38
+ return { flash: state.flash }
39
+ }
40
+
41
+ export default connect(mapStateToProps)(FlashMessage);
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+
3
+ class Loading extends React.Component {
4
+ constructor(props) {
5
+ super(props);
6
+ this.state = { isLoading: false };
7
+ let destructTimeout;
8
+ }
9
+
10
+ componentDidMount() {
11
+ this.setState({ isLoading: true });
12
+ }
13
+
14
+ componentWillUnmount() {
15
+ clearTimeout(this.destructTimeout);
16
+ }
17
+
18
+ selfDestruct = () => {
19
+ this.destructTimeout = setTimeout( () => {
20
+ this.setState({ isLoading: false });
21
+ }, 3000);
22
+ }
23
+
24
+ render() {
25
+ if(this.state.isLoading) {
26
+ this.selfDestruct();
27
+ } else {
28
+ clearTimeout(this.destructTimeout);
29
+ }
30
+
31
+ return (
32
+ <div>
33
+ { this.state.isLoading ?
34
+ <span className="loading">{`Loading ${this.props.info}`}</span>
35
+ :
36
+ <span>{`No ${this.props.info} found`}</span>
37
+ }
38
+ </div>
39
+ )
40
+ }
41
+ }
42
+
43
+ Loading.proptypes = {
44
+ info: React.PropTypes.string.isRequired
45
+ }
46
+
47
+ export default Loading;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { handleLogin } from '../actions/auth';
3
+ import { connect } from 'react-redux';
4
+ import { Link } from 'react-router';
5
+
6
+ class Login extends React.Component {
7
+ handleSubmit = (e) => {
8
+ e.preventDefault();
9
+ let email = this.refs.email.value;
10
+ let password = this.refs.password.value;
11
+ this.props.dispatch(handleLogin(email, password));
12
+ }
13
+
14
+ render() {
15
+ return(
16
+ <div>
17
+ <h3>Login</h3>
18
+ <form onSubmit={ this.handleSubmit }>
19
+ <input ref='email' type='text' required placeholder='Email' />
20
+ <br />
21
+ <input ref='password' type='password' required placeholder='Password' />
22
+ <br />
23
+ <input type='submit' className='btn' />
24
+ </form>
25
+ <Link to='/sign_up'>Sign Up</Link>
26
+ </div>
27
+ );
28
+ }
29
+ }
30
+
31
+ export default connect()(Login);
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { Link } from 'react-router';
3
+ import { handleLogout } from '../actions/auth';
4
+ import { connect } from 'react-redux';
5
+
6
+ class Navbar extends React.Component {
7
+ logout = (e) => {
8
+ e.preventDefault();
9
+ this.props.dispatch(handleLogout());
10
+ }
11
+
12
+ authLinks = () =>{
13
+ let { auth } = this.props;
14
+ if(auth && auth.isAuthenticated) {
15
+ return(
16
+ <li> <a href='#' onClick={this.logout}>Logout</a> </li>
17
+ )
18
+ } else {
19
+ return(<li> <Link to='/login'>Login</Link> </li>);
20
+ }
21
+ }
22
+
23
+ render() {
24
+ return(
25
+ <header>
26
+ <div className='navbar-fixed'>
27
+ <nav>
28
+ <div className='nav-wrapper'>
29
+ <Link to='/' className='brand-logo'>Logo</Link>
30
+ <ul className='right'>
31
+ { this.authLinks() }
32
+ </ul>
33
+ </div>
34
+ </nav>
35
+ </div>
36
+ </header>
37
+ );
38
+ }
39
+ }
40
+
41
+ const mapStateToProps = (state) => {
42
+ return { auth: state.auth }
43
+ }
44
+
45
+ export default connect(mapStateToProps)(Navbar);
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { Link } from 'react-router';
3
+ import { handleSignUp } from '../actions/auth';
4
+ import { connect } from 'react-redux';
5
+
6
+ class SignUp extends React.Component {
7
+ handleSubmit = (e) => {
8
+ e.preventDefault();
9
+ let email = this.refs.email.value;
10
+ let password = this.refs.password.value;
11
+ this.props.dispatch(handleSignUp(email, password));
12
+ }
13
+
14
+ render() {
15
+ return(
16
+ <div className='center'>
17
+ <h3>Sign Up For A New Account</h3>
18
+ <form onSubmit={ this.handleSubmit }>
19
+ <input ref='email' type='text' required placeholder='Email' />
20
+ <br />
21
+ <input ref='password' type='password' required placeholder='Password' />
22
+ <br />
23
+ <input type='submit' className='btn' value='Sign Up' />
24
+ <Link to='/login' className='btn grey'>Cancel</Link>
25
+ </form>
26
+ </div>
27
+ );
28
+ }
29
+ }
30
+
31
+ export default connect()(SignUp);
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { connect } from 'react-redux';
3
+ import Navbar from '../components/Navbar';
4
+ import { refreshLogin } from '../actions/auth';
5
+ import FlashMessage from '../components/FlashMessage';
6
+ import { clearFlash } from '../actions/flash';
7
+
8
+ class App extends React.Component {
9
+ componentDidMount() {
10
+ this.props.dispatch(refreshLogin());
11
+ }
12
+
13
+ componentDidUpdate() {
14
+ this.props.dispatch(clearFlash());
15
+ }
16
+
17
+ render() {
18
+ let { auth, children } = this.props;
19
+
20
+ return(
21
+ <div>
22
+ <Navbar />
23
+ <div style={{ marginBottom: '30px' }}>
24
+ <FlashMessage />
25
+ </div>
26
+ <div className='container'>
27
+ { children }
28
+ </div>
29
+ </div>
30
+ );
31
+ }
32
+ }
33
+
34
+ export default connect()(App);
35
+
@@ -0,0 +1,9 @@
1
+ class Api::UsersController < ApplicationController
2
+ def logged_in_user
3
+ if current_user
4
+ render json: current_user
5
+ else
6
+ render json: {}
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ const auth = (state = {}, action) => {
2
+ switch(action.type) {
3
+ case 'LOGIN':
4
+ return {
5
+ isAuthenticated: true,
6
+ user: action
7
+ }
8
+ case 'LOGOUT':
9
+ return {}
10
+ default:
11
+ return state;
12
+ }
13
+ }
14
+
15
+ export default auth;
@@ -0,0 +1,13 @@
1
+ const flash = ( state = {}, action ) => {
2
+ switch ( action.type ) {
3
+ case 'SET_FLASH':
4
+ let { message, msgType } = action;
5
+ return { message, msgType }
6
+ case 'CLEAR_FLASH':
7
+ return {}
8
+ default:
9
+ return state;
10
+ }
11
+ }
12
+
13
+ export default flash;
@@ -0,0 +1,8 @@
1
+ import { combineReducers } from 'redux';
2
+ import { routerReducer } from 'react-router-redux';
3
+ import auth from './auth'
4
+ import flash from './flash';
5
+
6
+ const rootReducer = combineReducers({ routing: routerReducer, auth, flash });
7
+
8
+ export default rootReducer;
@@ -0,0 +1,24 @@
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
+
9
+ const UserIsAuthenticated = UserAuthWrapper({
10
+ authSelector: state => state.auth,
11
+ predicate: auth => auth.isAuthenticated,
12
+ });
13
+
14
+ export default (
15
+ <Route>
16
+
17
+ <Route path="/" component={App}>
18
+ <Route path='/login' component={Login} />
19
+ <Route path='/sign_up' component={SignUp} />
20
+ </Route>
21
+
22
+ <Route path="*" status={404} component={NoMatch} />
23
+ </Route>
24
+ )
@@ -0,0 +1,22 @@
1
+ .alert {
2
+ top: 0px;
3
+ left: 0px;
4
+ right: 0px;
5
+ padding: 15px 0px;
6
+ margin-bottom: 60px;
7
+ border: 1px solid transparent;
8
+ border-radius: 4px;
9
+ z-index: 1999;
10
+ }
11
+
12
+ .alert-success {
13
+ color: #3c763d;
14
+ background-color: #dff0d8;
15
+ border-color: #d6e9c6;
16
+ }
17
+
18
+ .alert-error {
19
+ color: #a94442;
20
+ background-color: #f2dede;
21
+ border-color: #ebccd1;
22
+ }
data/example/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "repack",
3
+ "repository": "https://github.com/cottonwoodcoding/repack",
3
4
  "version": "0.0.1",
4
5
  "license": "MIT",
5
6
  "jest": {
@@ -22,11 +23,11 @@
22
23
  "autoprefixer": "^6.7.6",
23
24
  "react": "^15.1.0",
24
25
  "react-dom": "^15.1.0",
25
- "stats-webpack-plugin": "^0.2.1",
26
+ "stats-webpack-plugin": "^0.5.0",
26
27
  "webpack": "^2.2.1",
27
28
  "babel-core": "^6.9.1",
28
29
  "babel-loader": "^6.2.4",
29
- "babel-preset-latest": "^6.16.0",
30
+ "babel-preset-env": "^1.2.1",
30
31
  "image-webpack-loader": "3.0.0",
31
32
  "file-loader": "^0.9.0",
32
33
  "url-loader": "^0.5.7",
@@ -6,16 +6,26 @@ module Repack
6
6
  desc "Install everything you need for a basic repack integration"
7
7
  class_option :router, type: :boolean, default: false, description: 'Add React Router'
8
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
+
9
19
  def copy_package_json
10
20
  copy_file "package.json", "package.json"
11
- if options[:router]
21
+ if options[:router] || options[:god]
12
22
  insert_into_file './package.json', after: /dependencies\": {\n/ do
13
23
  <<-'RUBY'
14
24
  "react-router": "^2.4.1",
15
25
  RUBY
16
26
  end
17
27
  end
18
- if options[:redux]
28
+ if options[:redux] || options[:god]
19
29
  insert_into_file './package.json', after: /dependencies\": {\n/ do
20
30
  <<-'RUBY'
21
31
  "react-redux": "^4.4.5",
@@ -24,10 +34,11 @@ module Repack
24
34
  RUBY
25
35
  end
26
36
  end
27
- if options[:router] && options[:redux]
37
+ if options[:router] && options[:redux] || options[:god]
28
38
  insert_into_file './package.json', after: /dependencies\": {\n/ do
29
39
  <<-'RUBY'
30
40
  "react-router-redux": "^4.0.5",
41
+ "redux-auth-wrapper": "^1.0.0",
31
42
  RUBY
32
43
  end
33
44
  end
@@ -70,8 +81,10 @@ module Repack
70
81
  create_file "client/actions.js"
71
82
  copy_file "boilerplate/App.js", "client/containers/App.js"
72
83
  else
73
- copy_file "boilerplate/application.js", "client/application.js"
74
- copy_file "boilerplate/App.js", "client/containers/App.js"
84
+ unless options[:god]
85
+ copy_file "boilerplate/application.js", "client/application.js"
86
+ copy_file "boilerplate/App.js", "client/containers/App.js"
87
+ end
75
88
  end
76
89
 
77
90
  haml_installed = Gem.loaded_specs.has_key? 'haml-rails'
@@ -106,17 +119,15 @@ module Repack
106
119
  RUBY
107
120
  end
108
121
  else
109
- insert_into_file application_view, before: /<\/head>/ do
110
- <<-'RUBY'
111
- <% if Rails.env.development? %>
112
- <script src="http://localhost:3808/webpack-dev-server.js"></script>
113
- <% end %>
114
- RUBY
122
+ insert_into_file application_view, before: /<\/head>/ do <<-'RUBY'
123
+ <% if Rails.env.development? %>
124
+ <script src="http://localhost:3808/webpack-dev-server.js"></script>
125
+ <% end %>
126
+ RUBY
115
127
  end
116
- insert_into_file application_view, before: /<\/body>/ do
117
- <<-'RUBY'
118
- <%= javascript_include_tag *webpack_asset_paths('application') %>
119
- RUBY
128
+ insert_into_file application_view, before: /<\/body>/ do <<-'RUBY'
129
+ <%= javascript_include_tag *webpack_asset_paths('application') %>
130
+ RUBY
120
131
  end
121
132
  end
122
133
  end
@@ -131,9 +142,9 @@ module Repack
131
142
  end
132
143
 
133
144
  def install_yarn
134
- if yes?('Do you want to install and use yarn as your package manager? (yes / no)')
145
+ if yes?('Do you want to global install and use yarn as your package manager? (yes / no)')
135
146
  @yarn_installed = true
136
- run "npm install yarn --save-dev"
147
+ run "npm install yarn -g"
137
148
  end
138
149
  end
139
150
 
@@ -145,6 +156,58 @@ module Repack
145
156
  end
146
157
  end
147
158
 
159
+ def finishing_god_move
160
+ if options[:god]
161
+ copy_file "boilerplate/router_redux/application.js", "client/application.js"
162
+ copy_file "boilerplate/god_mode/routes.js", "client/routes.js"
163
+ copy_file "boilerplate/router_redux/store.js", "client/store.js"
164
+ copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js"
165
+ copy_file "boilerplate/god_mode/actions/auth.js", "client/actions/auth.js"
166
+ copy_file "boilerplate/god_mode/actions/flash.js", "client/actions/flash.js"
167
+ copy_file "boilerplate/god_mode/components/Navbar.js", "client/components/Navbar.js"
168
+ copy_file "boilerplate/god_mode/components/FlashMessage.js", "client/components/FlashMessage.js"
169
+ copy_file "boilerplate/god_mode/components/Login.js", "client/components/Login.js"
170
+ copy_file "boilerplate/god_mode/components/SignUp.js", "client/components/SignUp.js"
171
+ copy_file "boilerplate/god_mode/components/Loading.js", "client/components/Loading.js"
172
+ copy_file "boilerplate/god_mode/containers/App.js", "client/containers/App.js"
173
+ copy_file "boilerplate/god_mode/reducers/auth.js", "client/reducers/auth.js"
174
+ copy_file "boilerplate/god_mode/reducers/flash.js", "client/reducers/flash.js"
175
+ copy_file "boilerplate/god_mode/reducers/index.js", "client/reducers/index.js"
176
+ copy_file "boilerplate/god_mode/controllers/api/users_controller.rb", "app/controllers/api/users_controller.rb"
177
+ copy_file "boilerplate/god_mode/scss/alert.css.scss", "app/assets/stylesheets/alert.css.scss"
178
+ gem "devise"
179
+ Bundler.with_clean_env do
180
+ run "bundle install"
181
+ end
182
+ run 'bin/spring stop'
183
+ generate "devise:install"
184
+ run "bundle exec rake db:create"
185
+ model_name = ask("What would you like the user model to be called? [user]")
186
+ model_name = "user" if model_name.blank?
187
+ generate "devise", model_name
188
+ generate "devise:controllers #{model_name.pluralize}"
189
+
190
+ insert_into_file 'config/routes.rb', after: /devise_for :users/ do <<-'RUBY'
191
+ , controllers: {
192
+ sessions: 'users/sessions',
193
+ registrations: 'users/registrations'
194
+ }
195
+ namespace :api do
196
+ get 'logged_in_user', to: 'users#logged_in_user'
197
+ end
198
+ RUBY
199
+ end
200
+ ['./app/controllers/users/sessions_controller.rb', './app/controllers/users/registrations_controller.rb'].each do |c|
201
+ insert_into_file c, after: /Devise::\W*.*\n/ do <<-'RUBY'
202
+ skip_before_action :verify_authenticity_token
203
+ respond_to :json
204
+ RUBY
205
+ end
206
+ end
207
+ end
208
+ run 'bundle exec rake db:migrate'
209
+ end
210
+
148
211
  def whats_next
149
212
  puts <<-EOF.strip_heredoc
150
213
  We've set up the basics of repack for you, but you'll still
@@ -1,3 +1,3 @@
1
1
  module Repack
2
- VERSION = "2.3.1"
2
+ VERSION = "2.4.0"
3
3
  end
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: 2.3.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Jungst
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-03 00:00:00.000000000 Z
12
+ date: 2017-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -41,6 +41,20 @@ files:
41
41
  - example/babelrc
42
42
  - example/boilerplate/App.js
43
43
  - example/boilerplate/application.js
44
+ - example/boilerplate/god_mode/actions/auth.js
45
+ - example/boilerplate/god_mode/actions/flash.js
46
+ - example/boilerplate/god_mode/components/FlashMessage.js
47
+ - example/boilerplate/god_mode/components/Loading.js
48
+ - example/boilerplate/god_mode/components/Login.js
49
+ - example/boilerplate/god_mode/components/Navbar.js
50
+ - example/boilerplate/god_mode/components/SignUp.js
51
+ - example/boilerplate/god_mode/containers/App.js
52
+ - example/boilerplate/god_mode/controllers/api/users_controller.rb
53
+ - example/boilerplate/god_mode/reducers/auth.js
54
+ - example/boilerplate/god_mode/reducers/flash.js
55
+ - example/boilerplate/god_mode/reducers/index.js
56
+ - example/boilerplate/god_mode/routes.js
57
+ - example/boilerplate/god_mode/scss/alert.css.scss
44
58
  - example/boilerplate/redux/application.js
45
59
  - example/boilerplate/redux/reducers.js
46
60
  - example/boilerplate/redux/store.js