Permalink
Browse files

Updated branch

  • Loading branch information...
1 parent 7f414ae commit 0b066641e85ca7fa062c744e32161118b65c1685 @larzconwell larzconwell committed Jun 16, 2012
Showing with 70 additions and 62 deletions.
  1. +7 −52 bin/cli.js
  2. +60 −7 lib/geddy.js
  3. +3 −3 package.json
View
@@ -1,27 +1,22 @@
#!/usr/bin/env node
// Load the basic Geddy toolkit
-require('../lib/geddy');
+var geddy = require('../lib/geddy');
-var fs = require('fs')
- , exec = require('child_process').exec
+var exec = require('child_process').exec
, path = require('path')
, parseopts = require('../lib/parseopts')
, utils = require('../lib/utils/index')
- , App = require('../lib/app.js').App
- , pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString())
, parser
, cwd = process.cwd()
, args = process.argv.slice(2)
- , optsReg
+ , optsMap
, cmds
, opts
, usage
, cmd
, filepath;
-geddy.version = pkg.version;
-
usage = ''
+ 'Geddy web framework for Node.js\n'
+ '*********************************************************************************************\n'
@@ -38,7 +33,7 @@ usage = ''
+ ' -h, --help Outputs help information\n'
+ '';
-optsReg = [
+optsMap = [
{ full: 'origins'
, abbr: 'o'
}
@@ -71,7 +66,7 @@ optsReg = [
}
];
-parser = new parseopts.Parser(optsReg);
+parser = new parseopts.Parser(optsMap);
parser.parse(args);
cmds = parser.cmds;
opts = parser.opts;
@@ -82,48 +77,8 @@ var die = function (str) {
};
var start = function () {
-
- var cluster
- , master
- , worker
- , m
- , w
- , app;
-
- // Node 0.6
- try {
- cluster = require('cluster');
- geddy.FD_HACK = false;
- master = require('../lib/cluster/master')
- worker = require('../lib/cluster/worker');
- }
- // Node 0.4
- catch (e) {
- geddy.FD_HACK = true;
- master = require('../lib/cluster/hack_master')
- worker = require('../lib/cluster/hack_worker');
- }
-
- // Master-process
- if ((cluster && cluster.isMaster) ||
- (geddy.FD_HACK && !opts.spawned)) {
- m = new master.Master();
- m.start(opts);
- }
- // Worker-process -- start up an app
- else {
- w = new worker.Worker();
- geddy.worker = w;
- w.init(function () {
- geddy.mixin(geddy, w);
- app = new App();
- app.init(function () {
- w.startServer();
- geddy.mixin(geddy, app);
- });
- });
- }
-
+ geddy.config(opts);
+ geddy.start();
};
if (typeof opts.help != 'undefined') {
View
@@ -1,13 +1,66 @@
var geddy = global.geddy || {}
- , utils;
+ , cluster = require('cluster')
+ , master
+ , worker
+ , utils = require('./utils/index')
+ , fs = require('fs')
+ , pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString())
+ , App;
+geddy.isMaster = cluster.isMaster;
+
+utils.mixin(geddy, {version: pkg.version});
+utils.mixin(geddy, utils);
+utils.mixin(geddy, new (function () {
+ var _started = false
+ , _opts = {};
+
+ this.config = function (o) {
+ _opts = o;
+ };
+
+ this.start = function () {
+ var m
+ , w
+ , app;
+
+ // No repeatsies
+ if (_started) {
+ return;
+ }
+
+ // Master-process, start workers
+ if (geddy.isMaster) {
+ master = require('../lib/cluster/master')
+ m = new master.Master();
+ m.start(_opts);
+ }
+ // Worker-process, start up an app
+ else {
+ App = require('./app.js').App;
+
+ worker = require('../lib/cluster/worker')
+ w = new worker.Worker();
+ geddy.worker = w;
+
+ w.init(function () {
+ utils.mixin(geddy, w);
+
+ app = new App();
+ app.init(function () {
+ w.startServer();
+ utils.mixin(geddy, app);
+ });
+ });
+ }
+ };
+
+})());
+
+// Set the One True Geddy Global
global.geddy = geddy;
-utils = require('./utils/index');
-// Hang all the util namespaces on the global geddy
-for (var p in utils) {
- geddy[p] = utils[p];
-}
-// Could also be used as export/local
+
+// Also allow export/local
module.exports = geddy;
View
@@ -10,12 +10,12 @@
"version": "0.4.2",
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
"dependencies": {
- "jake": "0.2.x"
+ "jake": "0.3.x"
},
"bin": {
"geddy": "./bin/cli.js"
},
- "main": "./lib",
+ "main": "./lib/geddy",
"repository": {
"type": "git",
"url": "git://github.com/mde/geddy.git"
@@ -25,4 +25,4 @@
"engines": {
"node": "*"
}
-}
+}

0 comments on commit 0b06664

Please sign in to comment.