Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for disabled modules, multiple database connections, lazy models creation, further implementation of core modules according to original idea given by Andrija Petrovic, support for submenu items ... #37

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
17240e9
support for disabled modules
veljkopopovic Sep 11, 2014
3ac12f2
introducing support for multiple mongodb connections
veljkopopovic Sep 11, 2014
a6f0304
typo
veljkopopovic Sep 11, 2014
ee41151
Merge remote-tracking branch 'upstream/master'
veljkopopovic Sep 12, 2014
48b972a
Merge branch 'master' of github.com:veljkopopovic/mean-cli
veljkopopovic Sep 12, 2014
204720c
original idea of core modules implemented as far as could be ... for …
veljkopopovic Sep 12, 2014
52b37a6
introduced lazy mongoose model creation
veljkopopovic Sep 12, 2014
ccfe2fe
force aggregation to respect config.debug parameter and not to minify…
veljkopopovic Sep 16, 2014
e87b452
introducing support for submenu items ...
veljkopopovic Sep 16, 2014
50b8f24
Merge remote-tracking branch 'velj/master'
ellman Sep 17, 2014
039c855
inconsistency fixed
veljkopopovic Sep 17, 2014
7bec2c0
Merge remote-tracking branch 'upstream/master'
veljkopopovic Sep 17, 2014
6e5873e
defaultMenu problem fixed in order to be backward compatible
veljkopopovic Sep 17, 2014
0bec7f2
Merge remote-tracking branch 'velj/master'
ellman Sep 17, 2014
d282822
naming convention
veljkopopovic Sep 17, 2014
aaa1b78
fixed jshint issues - removed anonymous function() definition within …
lirantal Sep 20, 2014
0b365b7
cleaning up jshint semi-colon issues
lirantal Sep 20, 2014
9b30508
adding javascript implicit strict
lirantal Sep 20, 2014
bf8e994
cleaning up jshints issues
lirantal Sep 20, 2014
0ff02e1
adding my own CLA to the list
lirantal Sep 20, 2014
ca2383d
fixing spellings
lirantal Sep 20, 2014
bc745e2
Merge branch 'lirantal-cleanup-spellings' into 0.4.1
fyockm Sep 20, 2014
2e204f9
Merge branch 'cleanup-jshint-warnings' of https://github.com/lirantal…
fyockm Sep 20, 2014
e30494f
few details and few comments
veljkopopovic Sep 21, 2014
08a6472
Merge remote-tracking branch 'upstream/0.4.1'
veljkopopovic Sep 21, 2014
9597bca
fixing some errors ...
veljkopopovic Sep 22, 2014
6fbcc50
introduced implicit role named "all", test updated
veljkopopovic Sep 22, 2014
dac84e0
menu item for "all" can be specified as null in add_menu as well
veljkopopovic Sep 22, 2014
ece912a
link as name? remove / from link string
veljkopopovic Sep 22, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The mean-cli project requires agreeing to the following CLA (contributor license agreement) for developers that would like to contribute code to the project.

We appreciate your time, energy and will to contributre, as the company behind the project - Linnovate Technologies LTD that has invested considerable time and money, we believe we need to retain rights and control over this part of the project so it can move forward with a sane governing model, and so we can not merge contributions from authors who do not accept the current CLA.
We appreciate your time, energy and will to contribute, as the company behind the project - Linnovate Technologies LTD that has invested considerable time and money, we believe we need to retain rights and control over this part of the project so it can move forward with a sane governing model, and so we can not merge contributions from authors who do not accept the current CLA.

Please read the following text carefully, and if you agree to it's content:

Expand All @@ -14,7 +14,7 @@ Once we merge the file you can gladly contribute to the project!

## Agreement Content

By "commiting" to this file, you ("you" or "You") hereby grant to Linnovate and to recipients of software distributed through Linnovate a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to use, make, have made, offer to sell, sell, import, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works as part of Linnovate.
By "committing" to this file, you ("you" or "You") hereby grant to Linnovate and to recipients of software distributed through Linnovate a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to use, make, have made, offer to sell, sell, import, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works as part of Linnovate.

You, the contributor agree to the following…

Expand All @@ -35,3 +35,4 @@ If you become aware of any facts or circumstances related to the representation
* Taylor Thomas {thomastaylor312}
* David Büttner {zloKOMAtic}
* Andrija Petrovic {andrija-hers}
* Liran Tal {lirantal}
10 changes: 5 additions & 5 deletions lib/aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ Aggregator.prototype.pushAggregatedData = function(ext, filename, data) {
if (ext === 'js') {

var code = this.options.global ? data.toString() + '\n' : '(function(){' + data.toString() + '})();';

var ugly = uglify.minify(code, {
var ugly = this.debug ? {code:code} : uglify.minify(code, {
fromString: true,
mangle: false
});

aggregated[group][ext].weights[filename] = {
weight: weight,
data: !this.debug ? ugly.code : code
data: ugly.code
};
} else {
group = this.options.group || 'header';
Expand All @@ -149,7 +148,7 @@ function supportAggregate(Meanio) {
callback(aggregated[group][ext].data);
};

// Allows redbuilding aggregated data
// Allows rebuilding aggregated data
Meanio.prototype.rebuildAggregated = function() {
sortAggregateAssetsByWeight();
};
Expand All @@ -162,7 +161,8 @@ function supportAggregate(Meanio) {
Meanio.aggregate(type, asset, options, Meanio.Singleton.config.clean.debug);
};

Meanio.onModulesFoundAggregate = function(ext, options, debug) {
Meanio.onModulesFoundAggregate = function(ext, options) {
var debug = Meanio.Singleton.config.clean.debug;
var aggregator = new Aggregator(options, false, debug);
for (var name in Meanio.modules) {
aggregator.readFiles(ext, path.join(process.cwd(), Meanio.modules[name].source, name.toLowerCase(), 'public'));
Expand Down
49 changes: 37 additions & 12 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
var express = require('express'),
Grid = require('gridfs-stream'),
errorHandler = require('errorhandler'),
config = require('meanio').loadConfig(),
fs = require('fs'),
http = require('http'),
https = require('https'),
appPath = process.cwd();

var mean = require('meanio');

module.exports = function(options, db) {

module.exports = function(Meanio) {

var db = Meanio.Singleton.get('database').connection;
var config = Meanio.Singleton.config.clean;

// Register app dependency;
mean.register('app', function(access, database) {
Meanio.Singleton.register('app', function(access, database) {
require(appPath + '/config/express')(app, access.passport, database.connection);
return app;
});
Expand All @@ -27,7 +31,7 @@ module.exports = function(options, db) {

res.setHeader('content-type', 'text/javascript');

mean.aggregated('js', req.query.group ? req.query.group : 'footer', function(data) {
Meanio.Singleton.aggregated('js', req.query.group ? req.query.group : 'footer', function(data) {
res.send(data);
});

Expand Down Expand Up @@ -67,23 +71,23 @@ module.exports = function(options, db) {
app.get('/modules/aggregated.css', function(req, res) {
res.setHeader('content-type', 'text/css');

mean.aggregated('css', req.query.group ? req.query.group : 'header', function(data) {
Meanio.Singleton.aggregated('css', req.query.group ? req.query.group : 'header', function(data) {
res.send(data);
});
});

app.use('/bower_components', express.static(config.root + '/bower_components'));

mean.events.on('modulesEnabled', function() {
Meanio.Singleton.events.on('modulesEnabled', function() {

for (var name in mean.modules) {
app.use('/' + name, express.static(config.root + '/' + mean.modules[name].source + '/' + name.toLowerCase() + '/public'));
for (var name in Meanio.Singleton.modules) {
app.use('/' + name, express.static(config.root + '/' + Meanio.Singleton.modules[name].source + '/' + name.toLowerCase() + '/public'));
}

// We are going to catch everything else here
app.route('*').get(function(req, res, next) {
if (!mean.template) return next();
mean.template(req, res, next);
if (!Meanio.Singleton.template) return next();
Meanio.Singleton.template(req, res, next);
});

// Assume "not found" in the error msgs is a 404. this is somewhat
Expand Down Expand Up @@ -116,5 +120,26 @@ module.exports = function(options, db) {
}
});

return app;
// Listen on http.port (or port as fallback for old configs)
var httpServer = http.createServer(app);
Meanio.Singleton.register('http', httpServer);
httpServer.listen(config.http ? config.http.port : config.port, config.hostname);

if (config.https && config.https.port) {
var httpsOptions = {
key: fs.readFileSync(config.https.ssl.key),
cert: fs.readFileSync(config.https.ssl.cert)
};

var httpsServer = https.createServer(httpsOptions, app);
Meanio.Singleton.register('https', httpsServer);
httpsServer.listen(config.https.port);
}

Meanio.Singleton.Module.bootstrapModules();

Meanio.Singleton.aggregate('js', null);
Meanio.Singleton.name = config.app.name;
Meanio.Singleton.app = app;
Meanio.Singleton.menus = new (Meanio.Singleton.Menus)();
};
6 changes: 2 additions & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ function getPackage(name, callback) {
});
}

var install = exports.install = function(module, options) {
exports.install = function(module, options) {
requiresRoot(function() {

loadPackageJson('./node_modules/meanio/package.json', function(err, data) {
Expand Down Expand Up @@ -743,9 +743,7 @@ function packagesMeanJson(source) {

for (var dep in data.dependencies) {
shell.cd(process.cwd());
shell.exec('node node_modules/meanio/bin/mean-install ' + dep + '@' + data.dependencies[dep], function(code) {
if (code) console.log(code);
});
shell.exec('node node_modules/meanio/bin/mean-install ' + dep + '@' + data.dependencies[dep], console.log);
}
});

Expand Down
142 changes: 142 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
'use strict';

function mergeConfig(original, saved) {
var clean = {};
for (var index in saved) {
clean[index] = saved[index].value;
if (original[index]) {
original[index].value = saved[index].value;
} else {
original[index] = {
value: saved[index].value
};
}
original[index]['default'] = original[index]['default'] || saved[index]['default'];
}
return {
diff: original,
clean: clean
};
}

function createConfig(Meanio){
function Config(defaultconfig) {
this.verbose = {};
this.original = JSON.flatten(defaultconfig, {
default: true
});
this.clean = null;
this.diff = null;
this.flat = null;
this.createConfigurations(defaultconfig);
}

Config.prototype.loadSettings = function(callback) {
var Package = this.loadPackageModel();
if (!Package){
return callback ? callback(this.original) : undefined;
}
Package.findOne({
name: 'config'
}, this.onPackageRead.bind(this,callback));
};

Config.prototype.updateSettings = function(name, settings, callback) {
var Package = this.loadPackageModel();
if (!Package){
return callback ? callback(new Error('Failed to update settings')) : undefined;
}
Package.findOneAndUpdate({
name: name
}, {
$set: {
settings: settings,
updated: new Date()
}
}, {
upsert: true,
multi: false
}, function(err, doc) {
if (err) {
console.log(err);
return callback(new Error('Failed to update settings'));
}
return callback(null, doc);
});
};

Config.prototype.getSettings = function(name, callback) {
var Package = this.loadPackageModel();
if (!Package){
return callback ? callback(new Error('Failed to retrieve settings')) : undefined;
}
Package.findOne({
name: name
}, function(err, doc) {
if (err) {
console.log(err);
return callback(new Error('Failed to retrieve settings'));
}
return callback(null, doc);
});
};

Config.prototype.loadPackageModel = function() {
var database = Meanio.Singleton.get('database');
if (!database || !database.connection) {
return null;
}
if (!database.connection.models.Package) {
require('../modules/package')(database);
}
return database.connection.model('Package');
};

Config.prototype.onPackageRead = function(callback,err,doc){
if (err) {
return callback ? callback(err) : undefined;
}

if(!(doc&&doc.settings)){
return callback ? callback() : undefined;
}
this.createConfigurations(doc.settings);
if (callback) callback();
};

Config.prototype.createConfigurations = function(config){
var saved = JSON.flatten(config, {});
var merged = mergeConfig(this.original, saved);
var clean = JSON.unflatten(merged.clean, {});
var diff = JSON.unflatten(merged.diff, {});
this.verbose = {
clean: clean,
diff: diff,
flat: merged
};
this.clean = clean;
this.diff = diff;
this.flat = merged;
};

Config.prototype.update = function(settings, callback) {
var Package = this.loadPackageModel();
if (!Package) return callback(new Error('failed to load data model'));
Package.findOneAndUpdate({
name: 'config'
}, {
$set: {
settings: settings,
updated: new Date()
}
}, {
upsert: true,
new: true,
multi: false
}, this.onPackageRead.bind(this,callback));
};

Meanio.Config = Config;
}

module.exports = createConfig;
Loading