Skip to content

Commit da82ae3

Browse files
author
Scott Prue
committed
Files copied from https://github.com/KyperTech/webpack-redux-react-starter to templates folder. Project and app files are now being copied correctly.
1 parent 1faca0e commit da82ae3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1200
-163
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
33
**/.DS_Store
4+
**/npm-debug.log

Diff for: generators/app/index.js

+71-26
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,101 @@
22
var yeoman = require('yeoman-generator');
33
var chalk = require('chalk');
44
var yosay = require('yosay');
5-
5+
var _ = require('lodash');
6+
var path = require('path');
7+
var appFolder = 'app';
68
module.exports = yeoman.generators.Base.extend({
9+
initializing: function () {
10+
this.argument('name', { type: String, required: false });
11+
this.appName = this.name || path.basename(process.cwd()) || 'webpack-redux-react-starter';
12+
this.appPath = this.env.options.appPath;
13+
this.version = "0.0.1";
14+
},
715
prompting: function () {
816
var done = this.async();
917

1018
// Have Yeoman greet the user.
1119
this.log(yosay(
12-
'Welcome to the exceptional ' + chalk.red('GeneratorReactRedux') + ' generator!'
20+
'Welcome to the exceptional ' + chalk.red('Webpack Redux React') + ' generator!'
1321
));
1422

1523
var prompts = [{
1624
type: 'confirm',
1725
name: 'someOption',
18-
message: 'Would you like to enable this option?',
19-
default: true
26+
message: 'Would you like to include Matter.js for authentication?',
27+
default: false
2028
}];
2129

2230
this.prompt(prompts, function (props) {
2331
this.props = props;
2432
// To access props later use this.props.someOption;
25-
2633
done();
2734
}.bind(this));
2835
},
29-
3036
writing: {
3137
app: function () {
32-
this.fs.copy(
33-
this.templatePath('_package.json'),
34-
this.destinationPath('package.json')
35-
);
36-
this.fs.copy(
37-
this.templatePath('_bower.json'),
38-
this.destinationPath('bower.json')
39-
);
38+
var filesArray = [
39+
{src:'_index.html', dest:'index.html'},
40+
{src:'app/**', dest: 'app'},
41+
{src:'assets/**', dest: 'assets'},
42+
{src:'bin/**', dest: 'bin'},
43+
{src:'lib/**', dest: 'lib'},
44+
];
45+
this.copyFiles(filesArray);
4046
},
41-
4247
projectfiles: function () {
43-
this.fs.copy(
44-
this.templatePath('editorconfig'),
45-
this.destinationPath('.editorconfig')
46-
);
47-
this.fs.copy(
48-
this.templatePath('jshintrc'),
49-
this.destinationPath('.jshintrc')
50-
);
48+
var filesArray = [
49+
{src:'_package.json', dest: 'package.json'},
50+
{src:'webpack-dev.config.js'},
51+
{src:'webpack.config.js'},
52+
{src:'.gitignore'}
53+
]
54+
this.copyFiles(filesArray);
5155
}
5256
},
53-
5457
install: function () {
55-
this.installDependencies();
56-
}
58+
this.npmInstall();
59+
},
60+
/**
61+
* @param {Array|Object} filesArray
62+
*/
63+
copyFiles: function(filesArray){
64+
var array = [];
65+
if(_.isArray(filesArray)){
66+
array = filesArray;
67+
} else { //Handle array of arguments if first argument is not array
68+
array = arguments;
69+
}
70+
for(var i=0; i < array.length; i++){
71+
var src = '';
72+
var destination = '';
73+
if (!_.has(array[i],'src')) {
74+
if (_.isString(array[i])) {
75+
src = array[i];
76+
} else {
77+
console.error('Invalid source for file copying.');
78+
throw new Error('Invalid source for file copy.');
79+
}
80+
}
81+
if(_.isObject(array[i])){
82+
src = array[i].src;
83+
destination = array[i].dest || array[i].src; //Make destination source if not provided
84+
}
85+
if(src.charAt(0) === "_"){ //template if filename starts with _
86+
//Copy with templating
87+
this.template(src, destination, this.templateContext);
88+
} else if(src.indexOf('*') !== -1 || src.indexOf('/**') !== -1) {
89+
//TODO: make this work better (work with nested folders and use src correctly)
90+
src.replace("**", ""); //Remove /**
91+
src.replace("/", ""); //Remove /
92+
this.directory(destination, destination);
93+
} else {
94+
//Normal copy
95+
this.fs.copy(
96+
this.templatePath(src),
97+
this.destinationPath(destination)
98+
);
99+
}
100+
}
101+
},
57102
});

Diff for: generators/app/templates/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
stats.json
4+
.DS_Store
5+
**/.DS_Store

Diff for: generators/app/templates/_bower.json

-6
This file was deleted.

Diff for: generators/app/templates/_index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<!-- style -->
7+
<link rel="shortcut icon" type="image/x-icon" href="/assets/favicon.ico" />
8+
<title><%= appName %></title>
9+
<!-- analytics -->
10+
</head>
11+
<body style="margin:0px;">
12+
<div id="root"/>
13+
<!-- app -->
14+
<!-- script -->
15+
</body>
16+
</html>

Diff for: generators/app/templates/_package.json

+44-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
{
2-
"name": "package",
3-
"version": "0.0.0",
4-
"dependencies": {}
2+
"name": "<%= appName %>",
3+
"version": "<%= version %>",
4+
"main": "index.js",
5+
"scripts": {
6+
"start": "node bin/dev-server"
7+
},
8+
"keywords": [
9+
"webpack",
10+
"redux",
11+
"react",
12+
"react-router",
13+
"kyper"
14+
],
15+
"license": "MIT",
16+
"dependencies": {
17+
"babel-core": "^5.8.22",
18+
"babel-loader": "^5.3.2",
19+
"express": "^4.13.3",
20+
"extract-text-webpack-plugin": "^0.8.2",
21+
"history": "^1.9.1",
22+
"kyper-matter": "^0.1.2",
23+
"lodash": "^3.10.1",
24+
"proxy-middleware": "^0.13.1",
25+
"react": "^0.14.0-rc1",
26+
"react-dom": "^0.14.0-rc1",
27+
"react-hot-loader": "^1.2.8",
28+
"react-redux": "^2.1.2",
29+
"react-router": "^1.0.0-rc1",
30+
"redux": "^3.0.0",
31+
"redux-router": "^1.0.0-beta3",
32+
"redux-thunk": "^1.0.0"
33+
},
34+
"devDependencies": {
35+
"css-loader": "^0.16.0",
36+
"eslint": "^1.4.1",
37+
"eslint-config-airbnb": "0.0.8",
38+
"eslint-plugin-react": "^3.2.3",
39+
"node-sass": "^3.3.2",
40+
"redux-devtools": "^2.1.2",
41+
"sass-loader": "^2.0.1",
42+
"style-loader": "^0.12.3",
43+
"webpack": "^1.12.2",
44+
"webpack-dev-server": "^1.12.0"
45+
}
546
}

Diff for: generators/app/templates/app/actions/auth.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
export const LOGIN_ATTEMPT = 'LOGIN_ATTEMPT';
2+
export const LOGIN_RESPONSE = 'LOGIN_RESPONSE';
3+
export const SIGNUP_ATTEMPT = 'SIGNUP_ATTEMPT';
4+
export const SIGNUP_RESPONSE = 'SIGNUP_RESPONSE';
5+
export const LOGOUT_ATTEMPT = 'LOGOUT_ATTEMPT';
6+
export const LOGOUT_RESPONSE = 'LOGOUT_RESPONSE';
7+
export const AUTH_ERR = 'AUTH_ERR';
8+
9+
import Matter from 'kyper-matter';
10+
let matter = new Matter('exampleApp');
11+
12+
// Fetches a single user from Github API unless it is cached.
13+
// Relies on Redux Thunk middleware.
14+
export function loadAccount(login, requiredFields = []) {
15+
return (dispatch, getState) => {
16+
const user = getState().account;
17+
if (user) {
18+
return null;
19+
}
20+
};
21+
}
22+
export function attemptLogin(loginData) {
23+
console.log('attempt login action', loginData);
24+
return {
25+
type: LOGIN_ATTEMPT,
26+
payload: loginData
27+
};
28+
}
29+
//Requires react-thunk
30+
export function login(loginData) {
31+
console.log('login action called', loginData);
32+
return (dispatch, getState) => {
33+
console.log('distpatch function running.');
34+
dispatch(attemptLogin(loginData));
35+
console.log('distpatch function running.');
36+
return matter.login(loginData)
37+
.then(loginRes => {
38+
console.log('signup response');
39+
return dispatch(receiveLogin(loginData, loginRes));
40+
});
41+
}
42+
}
43+
export function receiveLogin(loginData, res) {
44+
console.log('receive login called', loginData, res);
45+
return {
46+
type: LOGIN_RESPONSE,
47+
loginData: loginData,
48+
account: res,
49+
receivedAt: Date.now()
50+
};
51+
}
52+
53+
export function attemptSignup(signupData) {
54+
return {
55+
type: SIGNUP_ATTEMPT,
56+
payload: signupData
57+
};
58+
}
59+
export function signup(signupData) {
60+
return dispatch => {
61+
distpatch(attemptSignup(signupData));
62+
return matter.signup(action.payload)
63+
.then((loginRes) => {
64+
dispatch(receiveSignup(signupData, loginRes));
65+
}, (err) => {
66+
return {type: AUTH_ERR, payload: err};
67+
});
68+
}
69+
}
70+
export function receiveSignup(signupData, res) {
71+
return {
72+
type: SIGNUP_RESPONSE,
73+
signupData,
74+
account: res,
75+
receivedAt: Date.now()
76+
};
77+
}
78+
79+
export function logout() {
80+
return dispatch => {
81+
dispatch(attemptLogout());
82+
return matter.logout()
83+
.then((logoutRes) => {
84+
console.log('logout successful:', logoutRes);
85+
dispatch(receiveLogout(logoutRes));
86+
}, (err) => {
87+
return {type: AUTH_ERR, payload: err};
88+
});
89+
}
90+
}
91+
export function attemptLogout() {
92+
return {
93+
type: LOGOUT_ATTEMPT
94+
};
95+
}
96+
export function receiveLogout(res) {
97+
return {
98+
type: LOGOUT_RESPONSE,
99+
account: null,
100+
receivedAt: Date.now()
101+
};
102+
}

Diff for: generators/app/templates/app/actions/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const ADD_CAR = 'ADD_CAR';
2+
3+
export function addCar(car) {
4+
return {
5+
type: ADD_CAR,
6+
payload: car
7+
};
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import { Link } from 'react-router';
3+
4+
class AccountDropdown extends Component {
5+
render() {
6+
return (
7+
<div className="buttons">
8+
<Link to="/profile">{this.props.currentAccount.username}</Link>
9+
</div>
10+
)
11+
}
12+
}
13+
AccountDropdown.propTypes = {
14+
currentAccount: PropTypes.shape({
15+
username: PropTypes.string.isRequired
16+
}).isRequired
17+
};
18+
export default AccountDropdown;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import {bindActionCreators} from 'redux';
3+
import {connect} from 'react-redux';
4+
import { Link } from 'react-router';
5+
import AccountDropdown from '../AccountDropdown/AccountDropdown';
6+
import * as Actions from '../../actions';
7+
8+
class AccountManager extends Component {
9+
constructor(props) {
10+
super(props);
11+
// this.state.account = this.props.loadAccount.bind(this);
12+
}
13+
14+
render() {
15+
if(this.props.currentAccount){
16+
return (<AccountDropdown currentAccount={ this.props.currentAccount } />)
17+
} else {
18+
return (<div className="buttons">
19+
<Link to="/login">Login</Link>
20+
<Link to="/signup">Signup</Link>
21+
</div>)
22+
}
23+
}
24+
}
25+
AccountManager.propTypes = {
26+
currentAccount: PropTypes.object
27+
}
28+
29+
export default AccountManager;

0 commit comments

Comments
 (0)