Skip to content

Commit

Permalink
0.3RC
Browse files Browse the repository at this point in the history
Express 4 Support
New naming convention
Glob patterns
CSS Linting
Uglify
CSS Min
Environmental Asset Management
DI Menu System
  • Loading branch information
amoshaviv committed Apr 20, 2014
1 parent 09f1eab commit 44bf81a
Show file tree
Hide file tree
Showing 60 changed files with 425 additions and 231 deletions.
15 changes: 15 additions & 0 deletions .csslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"adjoining-classes": false,
"box-model": false,
"box-sizing": false,
"floats": false,
"font-sizes": false,
"important": false,
"known-properties": false,
"overqualified-elements": false,
"qualified-headings": false,
"regex-selectors": false,
"unique-headings": false,
"universal-selector": false,
"unqualified-attributes": false
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 11 additions & 2 deletions app/models/user.js → app/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ var UserSchema = new Schema({
},
providerData: {},
additionalProvidersData: {},
roles: {
type: [{
type: String,
enum: ['user', 'admin']
}],
default: ['user']
},
updated: {
type: Date
},
Expand Down Expand Up @@ -114,8 +121,10 @@ UserSchema.statics.findUniqueUsername = function(username, suffix, callback) {
var _this = this;
var possibleUsername = username + (suffix || '');

_this.findOne({username: possibleUsername}, function(err, user) {
if(!err) {
_this.findOne({
username: possibleUsername
}, function(err, user) {
if (!err) {
if (!user) {
callback(possibleUsername);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Module dependencies.
*/
var users = require('../../app/controllers/users'),
articles = require('../../app/controllers/articles');
var users = require('../../app/controllers/users.server.controller'),
articles = require('../../app/controllers/articles.server.controller');

module.exports = function(app) {
// Article Routes
Expand Down
2 changes: 1 addition & 1 deletion app/routes/core.js → app/routes/core.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module.exports = function(app) {
// Root routing
var core = require('../../app/controllers/core');
var core = require('../../app/controllers/core.server.controller');
app.get('/', core.index);
};
2 changes: 1 addition & 1 deletion app/routes/users.js → app/routes/users.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var passport = require('passport');

module.exports = function(app) {
// User Routes
var users = require('../../app/controllers/users');
var users = require('../../app/controllers/users.server.controller');
app.get('/users/me', users.me);
app.put('/users', users.update);
app.post('/users/password', users.changePassword);
Expand Down
File renamed without changes.
File renamed without changes.
39 changes: 8 additions & 31 deletions app/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@
<meta name="twitter:image" content="/img/brand/logo.png">

<!-- Fav Icon -->
<link href="/img/brand/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link href="/modules/core/img/brand/favicon.ico" rel="shortcut icon" type="image/x-icon">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap-theme.css">

<!-- Application CSS -->
<link rel="stylesheet" href="/css/common.css">

<!--Application Modules CSS-->
{% for modulesCSSFile in modulesCSSFiles %}
<link rel="stylesheet" href="{{modulesCSSFile}}">{% endfor %}
<!--Application CSS Files-->
{% for cssFile in cssFiles %}<link rel="stylesheet" href="{{cssFile}}">
{% endfor %}

<!-- HTML5 Shim -->
<!--[if lt IE 9]>
Expand All @@ -62,29 +55,13 @@
var user = {{ user | json | safe }};
</script>

<!--AngularJS-->
<script type="text/javascript" src="/lib/angular/angular.js"></script>
<script type="text/javascript" src="/lib/angular-resource/angular-resource.js"></script>
<script type="text/javascript" src="/lib/angular-cookies/angular-cookies.js"></script>
<script type="text/javascript" src="/lib/angular-animate/angular-animate.js"></script>

<!--Angular UI-->
<script type="text/javascript" src="/lib/angular-bootstrap/ui-bootstrap.js"></script>
<script type="text/javascript" src="/lib/angular-ui-utils/ui-utils.js"></script>
<script type="text/javascript" src="/lib/angular-ui-router/release/angular-ui-router.js"></script>

<!--AngularJS Application Init-->
<script type="text/javascript" src="/js/config.js"></script>
<script type="text/javascript" src="/js/application.js"></script>

<!--Application Modules-->
{% for modulesJSFile in modulesJSFiles %}
<script type="text/javascript" src="{{modulesJSFile}}"></script>
<!--Application JavaScript Files-->
{% for jsFile in jsFiles %}<script type="text/javascript" src="{{jsFile}}"></script>
{% endfor %}

{% if process.env.NODE_ENV === 'development' %}
<!--Livereload script rendered -->
<script type="text/javascript" src="http://localhost:35729/livereload.js"></script>
<!--Livereload script rendered -->
<script type="text/javascript" src="http://localhost:35729/livereload.js"></script>
{% endif %}
</body>

Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dependencies": {
"bootstrap": "~3",
"angular": "~1.2",
"angular-cookies": "~1.2",
"angular-resource": "~1.2",
"angular-animate": "~1.2",
"angular-mocks": "~1.2",
Expand Down
71 changes: 65 additions & 6 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,74 @@
'use strict';

var _ = require('lodash'),
utilities = require('./utilities');
glob = require('glob');

// Look for a valid NODE_ENV variable and if one cannot be found load the development NODE_ENV
process.env.NODE_ENV = ~utilities.walk('./config/env', /(.*)\.js$/).map(function(file) {
return file.split('/').pop().slice(0, -3);
}).indexOf(process.env.NODE_ENV) ? process.env.NODE_ENV : 'development';
/**
* Before we begin, lets set the envrionment variable
* We'll Look for a valid NODE_ENV variable and if one cannot be found load the development NODE_ENV
*/
glob('./config/env/' + process.env.NODE_ENV + '.js', {
sync: true
}, function(err, environmentFiles) {
process.env.NODE_ENV = environmentFiles.length ? process.env.NODE_ENV : 'development';
});

// Load app configurations
module.exports = _.extend(
require('./env/all'),
require('./env/' + process.env.NODE_ENV) || {}
);
);

/**
* Get the modules JavaScript files
*/
module.exports.getGlobbedFiles = function(globPatterns, removeRoot) {
// For context switching
var _this = this;

// The output array
var output = [];

// If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob
if (_.isArray(globPatterns)) {
globPatterns.forEach(function(globPattern) {
output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot));
});
} else if (_.isString(globPatterns)) {
glob(globPatterns, {
sync: true
}, function(err, files) {
if (removeRoot) {
files = files.map(function(file) {
return file.replace(removeRoot, '');
});
}

output = _.union(output, files);
});
}

return output;
};

/**
* Get the modules JavaScript files
*/
module.exports.getJavaScriptAssets = function(includeTests) {
var output = this.getGlobbedFiles(this.assets.js, 'public/');

// To include tests
if (includeTests) {
output = _.union(output, this.getGlobbedFiles(this.assets.tests));
}

return output;
};

/**
* Get the modules CSS files
*/
module.exports.getCSSAssets = function() {
var output = this.getGlobbedFiles(this.assets.css, 'public/');
return output;
};
25 changes: 24 additions & 1 deletion config/env/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,28 @@ module.exports = {
port: process.env.PORT || 3000,
templateEngine: 'swig',
sessionSecret: 'MEAN',
sessionCollection: 'sessions'
sessionCollection: 'sessions',
assets: {
css: [
'public/lib/bootstrap/dist/css/bootstrap.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.css',
'public/modules/**/css/*.css'
],
js: [
'public/lib/angular/angular.js',
'public/lib/angular-resource/angular-resource.js',
'public/lib/angular-animate/angular-animate.js',
'public/lib/angular-ui-router/release/angular-ui-router.js',
'public/lib/angular-ui-utils/ui-utils.js',
'public/lib/angular-bootstrap/ui-bootstrap-tpls.js',
'public/config.js',
'public/application.js',
'public/modules/*/*.js',
'public/modules/*/*[!tests]*/*.js'
],
tests: [
'public/lib/angular-mocks/angular-mocks.js',
'public/modules/*/tests/*.js'
]
}
};
6 changes: 5 additions & 1 deletion config/env/production.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

module.exports = {
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean',
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean',
assets: {
css: 'public/dist/application.min.css',
js: 'public/dist/application.min.js'
},
facebook: {
clientID: 'APP_ID',
clientSecret: 'APP_SECRET',
Expand Down
17 changes: 8 additions & 9 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ var express = require('express'),
flash = require('connect-flash'),
config = require('./config'),
consolidate = require('consolidate'),
path = require('path'),
utilities = require('./utilities');
path = require('path');

module.exports = function(db) {
// Initialize express app
var app = express();

// Initialize models
utilities.walk('./app/models').forEach(function(modelPath) {
// Globbing model files
config.getGlobbedFiles('./app/models/**/*.js').forEach(function(modelPath) {
require(path.resolve(modelPath));
});

Expand All @@ -27,8 +26,8 @@ module.exports = function(db) {
description: config.app.description,
keywords: config.app.keywords,
facebookAppId: config.facebook.clientID,
modulesJSFiles: utilities.walk('./public/modules', /(.*)\.(js)/, /(.*)\.(spec.js)/, './public'),
modulesCSSFiles: utilities.walk('./public/modules', /(.*)\.(css)/, null, './public')
jsFiles: config.getJavaScriptAssets(),
cssFiles: config.getCSSAssets()
});

// Passing the request url to environment locals
Expand Down Expand Up @@ -104,8 +103,8 @@ module.exports = function(db) {
// Setting the app router and static folder
app.use(express.static(config.root + '/public'));

// Load Routes
utilities.walk('./app/routes').forEach(function(routePath) {
// Globbing routing files
config.getGlobbedFiles('./app/routes/**/*.js').forEach(function(routePath) {
require(path.resolve(routePath))(app);
});

Expand All @@ -132,4 +131,4 @@ module.exports = function(db) {
});

return app;
};
};
8 changes: 4 additions & 4 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var passport = require('passport'),
User = require('mongoose').model('User'),
path = require('path'),
utilities = require('./utilities');
config = require('./config');

module.exports = function() {
// Serialize sessions
Expand All @@ -21,7 +21,7 @@ module.exports = function() {
});

// Initialize strategies
utilities.walk('./config/strategies').forEach(function(strategyPath) {
require(path.resolve(strategyPath))();
config.getGlobbedFiles('./config/strategies/**/*.js').forEach(function(strategy) {
require(path.resolve(strategy))();
});
};
};
2 changes: 1 addition & 1 deletion config/strategies/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var passport = require('passport'),
FacebookStrategy = require('passport-facebook').Strategy,
config = require('../config'),
users = require('../../app/controllers/users');
users = require('../../app/controllers/users.server.controller');

module.exports = function() {
// Use facebook strategy
Expand Down
2 changes: 1 addition & 1 deletion config/strategies/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var passport = require('passport'),
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
config = require('../config'),
users = require('../../app/controllers/users');
users = require('../../app/controllers/users.server.controller');

module.exports = function() {
// Use google strategy
Expand Down
2 changes: 1 addition & 1 deletion config/strategies/linkedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var passport = require('passport'),
LinkedInStrategy = require('passport-linkedin').Strategy,
config = require('../config'),
users = require('../../app/controllers/users');
users = require('../../app/controllers/users.server.controller');

module.exports = function() {
// Use linkedin strategy
Expand Down
1 change: 0 additions & 1 deletion config/strategies/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
User = require('mongoose').model('User');


module.exports = function() {
// Use local strategy
passport.use(new LocalStrategy({
Expand Down
2 changes: 1 addition & 1 deletion config/strategies/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var passport = require('passport'),
TwitterStrategy = require('passport-twitter').Strategy,
config = require('../config'),
users = require('../../app/controllers/users');
users = require('../../app/controllers/users.server.controller');

module.exports = function() {
// Use twitter strategy
Expand Down
Loading

0 comments on commit 44bf81a

Please sign in to comment.