Skip to content

Commit 0a2bf2a

Browse files
committed
feat(app): restructured project for easier configuration
global configurations are now setup from the config/env folder. moved routes out of server js and into its own module
1 parent 8784106 commit 0a2bf2a

File tree

25 files changed

+158
-91
lines changed

25 files changed

+158
-91
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
test/temp
33
test/UpperCaseBug
4+
.idea

app/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,16 @@ Generator.prototype._injectDependencies = function _injectDependencies() {
471471
Generator.prototype.serverFiles = function () {
472472
this.template('../../templates/express/server.js', 'server.js');
473473
this.copy('../../templates/express/jshintrc', 'lib/.jshintrc');
474-
this.template('../../templates/express/api.js', 'lib/controllers/api.js');
475-
this.template('../../templates/express/index.js', 'lib/controllers/index.js');
474+
this.template('../../templates/express/controllers/api.js', 'lib/controllers/api.js');
475+
this.template('../../templates/express/controllers/index.js', 'lib/controllers/index.js');
476+
this.template('../../templates/express/routes.js', 'lib/routes.js');
477+
476478
this.template('../../templates/express/config/express.js', 'lib/config/express.js');
479+
this.template('../../templates/express/config/config.js', 'lib/config/config.js');
480+
this.template('../../templates/express/config/env/all.js', 'lib/config/env/all.js');
481+
this.template('../../templates/express/config/env/development.js', 'lib/config/env/development.js');
482+
this.template('../../templates/express/config/env/production.js', 'lib/config/env/production.js');
483+
this.template('../../templates/express/config/env/test.js', 'lib/config/env/test.js');
477484
};
478485

479486
Generator.prototype.mongoFiles = function () {
@@ -483,9 +490,8 @@ Generator.prototype.mongoFiles = function () {
483490
}
484491
this.env.options.mongo = this.mongo;
485492

486-
this.template('../../templates/express/mongo/mongo.js', 'lib/db/mongo.js');
487-
this.template('../../templates/express/mongo/dummydata.js', 'lib/db/dummydata.js');
488-
this.template('../../templates/express/mongo/thing.js', 'lib/models/thing.js');
493+
this.template('../../templates/express/config/dummydata.js', 'lib/config/dummydata.js');
494+
this.template('../../templates/express/models/thing.js', 'lib/models/thing.js');
489495

490496
if(!this.mongoPassportUser) {
491497
return; // Skip if disabled.
@@ -508,8 +514,8 @@ Generator.prototype.mongoFiles = function () {
508514
// config
509515
this.template('../../templates/express/config/passport.js', 'lib/config/passport.js');
510516
// models
511-
this.template('../../templates/express/mongo/user.js', 'lib/models/user.js');
517+
this.template('../../templates/express/models/user.js', 'lib/models/user.js');
512518
// controllers
513-
this.template('../../templates/express/session.js', 'lib/controllers/session.js');
514-
this.template('../../templates/express/users.js', 'lib/controllers/users.js');
519+
this.template('../../templates/express/controllers/session.js', 'lib/controllers/session.js');
520+
this.template('../../templates/express/controllers/users.js', 'lib/controllers/users.js');
515521
};

deploy/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Generator.prototype.herokuCreate = function herokuCreate() {
6868
} else {
6969
console.log('stdout: ' + stdout);
7070
console.log(chalk.green('You\'re all set! Now push to heroku with\n\t' + chalk.bold('git push heroku master') +
71-
'\nfrom your new distribution folder'));
71+
'\nfrom your new ' + chalk.bold('dist') + ' folder'));
7272
console.log(chalk.yellow('After app modification run\n\t' + chalk.bold('grunt build') +
7373
'\nthen commit and push the dist folder'));
7474
}

templates/common/Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = function (grunt) {
9292
express: {
9393
files: [
9494
'server.js',
95-
'lib/{,*//*}*.{js,json}'
95+
'lib/**/*.{js,json}'
9696
],
9797
tasks: ['newer:jshint:server', 'express:dev'],
9898
options: {

templates/common/_package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dependencies": {
55
"express": "~3.4.3"<% if (mongo) { %>,
66
"async": "~0.2.9",
7+
"lodash": "~2.4.1",
78
"mongoose": "~3.5.5"<% } %><% if (mongo && mongoPassportUser) { %>,
89
"mongoose-unique-validator": "~0.3.0",
910
"passport": "latest",

templates/express/config/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
var _ = require('lodash');
4+
5+
/**
6+
* Load environment configuration
7+
*/
8+
module.exports = _.extend(
9+
require('./env/all.js'),
10+
require('./env/' + process.env.NODE_ENV + '.js') || {});
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ var mongoose = require('mongoose'),<% if(mongo && mongoPassportUser) { %>
44
User = mongoose.model('User'),<% } %>
55
Thing = mongoose.model('Thing');
66

7+
/**
8+
* Populate database with sample application data
9+
*/
10+
711
//Clear old things, then add things in
812
Thing.find({}).remove(function() {
9-
Thing.create({
13+
Thing.create({
1014
name : 'HTML5 Boilerplate',
1115
info : 'HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites.',
1216
awesomeness: 10
@@ -26,19 +30,19 @@ Thing.find({}).remove(function() {
2630
name : 'MongoDB + Mongoose',
2731
info : 'An excellent document database. Combined with Mongoose to simplify adding validation and business logic.',
2832
awesomeness: 10
29-
}, function(err) {
33+
}, function() {
3034
console.log('finished populating things');
3135
}
3236
);
3337
});
3438
<% if(mongo && mongoPassportUser) { %>
3539
// Clear old users, then add a default user
3640
User.find({}).remove(function() {
37-
User.create({
41+
User.create({
3842
name: 'Test User',
3943
email: 'test@test.com',
4044
password: 'test'
41-
}, function(err) {
45+
}, function() {
4246
console.log('finished populating users');
4347
}
4448
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
5+
var rootPath = path.normalize(__dirname + '/../../..');
6+
7+
module.exports = {
8+
root: rootPath,
9+
port: process.env.PORT || 3000<% if (mongo) { %>,
10+
mongo: {
11+
options: {
12+
db: {
13+
safe: true
14+
}
15+
}
16+
}<% } %>
17+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
module.exports = {
4+
env: 'development'<% if (mongo) { %>,
5+
mongo: {
6+
uri: 'mongodb://localhost/fullstack-dev'
7+
}<% } %>
8+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
module.exports = {
4+
env: 'production'<% if (mongo) { %>,
5+
mongo: {
6+
uri: process.env.MONGOLAB_URI ||
7+
process.env.MONGOHQ_URL ||
8+
'mongodb://localhost/fullstack'
9+
}<% } %>
10+
};

0 commit comments

Comments
 (0)