Permalink
Browse files

Minor pre-release cleanup + reduced size of browserify lib

  • Loading branch information...
Owen Barnes
Owen Barnes committed Jul 17, 2012
1 parent 4393984 commit b99790034f5a150ab3241a34635904f17ca5e52a
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -12,7 +12,7 @@ window.require = function (file, cwd) {
require.paths = [];
require.modules = {};
-require.extensions = [".js",".coffee"];
+require.extensions = [".js",".coffee",".ls"];
require._core = {
'assert': true,
@@ -54,25 +54,7 @@ require.resolve = (function () {
}
function loadAsDirectorySync (x) {
- x = x.replace(/\/+$/, '');
- var pkgfile = x + '/package.json';
- if (require.modules[pkgfile]) {
- var pkg = require.modules[pkgfile]();
- var b = pkg.browserify;
- if (typeof b === 'object' && b.main) {
- var m = loadAsFileSync(path.resolve(x, b.main));
- if (m) return m;
- }
- else if (typeof b === 'string') {
- var m = loadAsFileSync(path.resolve(x, b));
- if (m) return m;
- }
- else if (pkg.main) {
- var m = loadAsFileSync(path.resolve(x, pkg.main));
- if (m) return m;
- }
- }
-
+ x = x.replace(/\/+$/, '');
return loadAsFileSync(x + '/index');
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -12,7 +12,7 @@ var version = exports.version = require('./utils/file').loadPackageJSON().versio
var root = exports.root = process.cwd().replace(/\\/g, '/'); // replace '\' with '/' to support Windows
// Warn if attempting to start without a cwd (e.g. through upstart script)
-if (root == '/') throw new Error("You must change into the project directory before starting your SocketStream app")
+if (root == '/') throw new Error("You must change into the project directory before starting your SocketStream app");
// Set environment
var env = exports.env = (process.env['SS_ENV'] || 'development').toLowerCase();
@@ -32,16 +32,17 @@ var api = exports.api = {
// Call ss.api.add('name_of_api', value_or_function) from your app to safely extend the 'ss' internal API object passed through to your /server code
add: function(name, fn) {
var exists = false;
- if (exists = api[name]) {
+ if (exists == api[name]) {
throw new Error("Unable to register internal API extension '" + name + "' as this name has already been taken");
} else {
api[name] = fn;
return true;
}
}
-}
+};
// Create internal Events bus
+// Note: only used by the ss-console module for now. This idea will be expended upon in SocketStream 0.4
var events = exports.events = new EventEmitter2();
// Publish Events
@@ -87,7 +88,7 @@ var start = function(httpServer) {
ws.load(httpServer, server.responders, server.eventTransport);
// Append SocketStream middleware to stack
- http.load(client.options.dirs.static, server.sessionStore, session.options);
+ http.load(client.options.dirs['static'], server.sessionStore, session.options);
// Load Client Asset Manager
client.load(api);
@@ -96,11 +97,11 @@ var start = function(httpServer) {
events.emit('server:start', server);
// If no HTTP server is passed return an API to allow for server-side testing
- // Note this feature is currently considered 'experiemntal' and the implementation
- // may change in the future to ensure any type of Request Responder can be tested
+ // Note this feature is currently considered 'experimental' and the implementation will
+ // be changed in SocketStream 0.4 to ensure any type of Request Responder can be tested
} else {
- var sessionID = session.create();
+ var id, sessionID = session.create();
for (id in server.responders) {
@@ -110,18 +111,18 @@ var start = function(httpServer) {
var fn = function(){
var args = Array.prototype.slice.call(arguments);
var cb = args.pop();
- return responder.interfaces.internal(args, {sessionId: sessionID, transport: 'test'}, function(err, params){ cb(params) });
- }
+ return responder.interfaces.internal(args, {sessionId: sessionID, transport: 'test'}, function(err, params){ cb(params); });
+ };
api.add(responder.name, fn);
}
}
}
return api;
-}
+};
// Ensure server can only be started once
exports.start = function(httpServer) {
return serverInstance || (serverInstance = start(httpServer));
-}
+};
View
@@ -10,7 +10,7 @@ exports.readDirSync = function(start) {
function isHidden(path){ return path.match(/(^_|^\.|~$)/); }
function isDir(abspath) {
var stat = fs.statSync(abspath);
- var abspathAry = abspath.split('/')
+ var abspathAry = abspath.split('/');
if(stat.isDirectory() && !isHidden(abspathAry[abspathAry.length -1])) {
found.dirs.push(abspath);
// If we found a directory, recurse!
@@ -19,7 +19,7 @@ exports.readDirSync = function(start) {
found.files = found.files.concat(data.files);
if(++processed == total) return found;
} else {
- var abspathAry = abspath.split('/')
+ abspathAry = abspath.split('/');
var file_name = abspathAry[abspathAry.length-1];
if (!isHidden(file_name)) found.files.push(abspath);
if(++processed == total) return found;
@@ -40,7 +40,7 @@ exports.readDirSync = function(start) {
} catch(e) {
if(e.code != 'ENOENT') throw(e); // Ignore if optional dirs are missing
return false;
- };
+ }
};
// Load package JSON file
@@ -49,8 +49,8 @@ exports.loadPackageJSON = function () {
return JSON.parse(fs.readFileSync(__dirname + '/../../package.json'));
} catch (e) {
throw('Error: Unable to find or parse SocketStream\'s package.json file');
- };
-}
+ }
+};
exports.isDir = function (filePath) { return fs.statSync(filePath).isDirectory(); };
View
@@ -2,7 +2,7 @@
exports.randomString = function (len) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = [];
- radix = chars.length;
+ var radix = chars.length;
for (var i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
return uuid.join('');
};
View
@@ -14,7 +14,7 @@ dir_mode = '0755'
exports.generate = (program) ->
name = program.args[1]
clientFiles = {css: [], code: []}
- return console.log "Please provide a name for your application: $> socketstream new <MyAppName>" if name is undefined
+ return log "Please provide a name for your application: $> socketstream new <MyAppName>" if name is undefined
if makeRootDirectory(name)
# Force stylus for now
View
@@ -3,7 +3,7 @@
# Extend Node's HTTP http.ServerResponse object to serve views either from a cache (in production)
# or by generating them on-the-fly (in development)
# Note: Even though this is exactly what Express.js does, it's not best practice to extend Node's native
-# objects so I may change this in the future
+# objects and we don't be doing this in SocketStream 0.4
require('colors')
fs = require('fs')
@@ -52,7 +52,7 @@ module.exports = (ss, clients, options) ->
else
view(ss, client, options, sendHTML)
- # Never send stack trace to the browser, log it to the terminal instad
+ # Never send stack trace to the browser, log it to the terminal instead
catch e
sendHTML('Internal Server Error', 500)
ss.log('Error: Unable to serve HTML!'.red)
@@ -12,7 +12,7 @@ window.require = function (file, cwd) {
require.paths = [];
require.modules = {};
-require.extensions = [".js",".coffee"];
+require.extensions = [".js",".coffee",".ls"];
require._core = {
'assert': true,
@@ -54,25 +54,7 @@ require.resolve = (function () {
}
function loadAsDirectorySync (x) {
- x = x.replace(/\/+$/, '');
- var pkgfile = x + '/package.json';
- if (require.modules[pkgfile]) {
- var pkg = require.modules[pkgfile]();
- var b = pkg.browserify;
- if (typeof b === 'object' && b.main) {
- var m = loadAsFileSync(path.resolve(x, b.main));
- if (m) return m;
- }
- else if (typeof b === 'string') {
- var m = loadAsFileSync(path.resolve(x, b));
- if (m) return m;
- }
- else if (pkg.main) {
- var m = loadAsFileSync(path.resolve(x, pkg.main));
- if (m) return m;
- }
- }
-
+ x = x.replace(/\/+$/, '');
return loadAsFileSync(x + '/index');
}
View
@@ -31,7 +31,7 @@ module.exports = (ss) ->
responders[id] = mod(id, config, ss)
catch e
responderName = responders[id] && responders[id].name || ''
- err = Error("Unable to initalize Request Responder '#{responderName}'")
+ err = Error("Unable to initialize Request Responder '#{responderName}'")
err.stack = e.stack
throw e
View
@@ -12,7 +12,7 @@ var version = exports.version = require('./utils/file').loadPackageJSON().versio
var root = exports.root = process.cwd().replace(/\\/g, '/'); // replace '\' with '/' to support Windows
// Warn if attempting to start without a cwd (e.g. through upstart script)
-if (root == '/') throw new Error("You must change into the project directory before starting your SocketStream app")
+if (root == '/') throw new Error("You must change into the project directory before starting your SocketStream app");
// Set environment
var env = exports.env = (process.env['SS_ENV'] || 'development').toLowerCase();
@@ -32,16 +32,17 @@ var api = exports.api = {
// Call ss.api.add('name_of_api', value_or_function) from your app to safely extend the 'ss' internal API object passed through to your /server code
add: function(name, fn) {
var exists = false;
- if (exists = api[name]) {
+ if (exists == api[name]) {

This comment has been minimized.

Show comment Hide comment
@plievone

plievone Jul 26, 2012

Hi Owen, unfortunate variable naming here, as the logic in ss.api.add does not work now (it was an assignment).

@plievone

plievone Jul 26, 2012

Hi Owen, unfortunate variable naming here, as the logic in ss.api.add does not work now (it was an assignment).

This comment has been minimized.

Show comment Hide comment
@owenb

owenb Jul 26, 2012

Hey pilevone

The change didn't stop it working for me, but it is clearly wrong! Thanks for spotting. Will fix.

@owenb

owenb Jul 26, 2012

Hey pilevone

The change didn't stop it working for me, but it is clearly wrong! Thanks for spotting. Will fix.

throw new Error("Unable to register internal API extension '" + name + "' as this name has already been taken");
} else {
api[name] = fn;
return true;
}
}
-}
+};
// Create internal Events bus
+// Note: only used by the ss-console module for now. This idea will be expended upon in SocketStream 0.4
var events = exports.events = new EventEmitter2();
// Publish Events
@@ -87,7 +88,7 @@ var start = function(httpServer) {
ws.load(httpServer, server.responders, server.eventTransport);
// Append SocketStream middleware to stack
- http.load(client.options.dirs.static, server.sessionStore, session.options);
+ http.load(client.options.dirs['static'], server.sessionStore, session.options);
// Load Client Asset Manager
client.load(api);
@@ -96,11 +97,11 @@ var start = function(httpServer) {
events.emit('server:start', server);
// If no HTTP server is passed return an API to allow for server-side testing
- // Note this feature is currently considered 'experiemntal' and the implementation
- // may change in the future to ensure any type of Request Responder can be tested
+ // Note this feature is currently considered 'experimental' and the implementation will
+ // be changed in SocketStream 0.4 to ensure any type of Request Responder can be tested
} else {
- var sessionID = session.create();
+ var id, sessionID = session.create();
for (id in server.responders) {
@@ -110,18 +111,18 @@ var start = function(httpServer) {
var fn = function(){
var args = Array.prototype.slice.call(arguments);
var cb = args.pop();
- return responder.interfaces.internal(args, {sessionId: sessionID, transport: 'test'}, function(err, params){ cb(params) });
- }
+ return responder.interfaces.internal(args, {sessionId: sessionID, transport: 'test'}, function(err, params){ cb(params); });
+ };
api.add(responder.name, fn);
}
}
}
return api;
-}
+};
// Ensure server can only be started once
exports.start = function(httpServer) {
return serverInstance || (serverInstance = start(httpServer));
-}
+};
View
@@ -10,7 +10,7 @@ exports.readDirSync = function(start) {
function isHidden(path){ return path.match(/(^_|^\.|~$)/); }
function isDir(abspath) {
var stat = fs.statSync(abspath);
- var abspathAry = abspath.split('/')
+ var abspathAry = abspath.split('/');
if(stat.isDirectory() && !isHidden(abspathAry[abspathAry.length -1])) {
found.dirs.push(abspath);
// If we found a directory, recurse!
@@ -19,7 +19,7 @@ exports.readDirSync = function(start) {
found.files = found.files.concat(data.files);
if(++processed == total) return found;
} else {
- var abspathAry = abspath.split('/')
+ abspathAry = abspath.split('/');
var file_name = abspathAry[abspathAry.length-1];
if (!isHidden(file_name)) found.files.push(abspath);
if(++processed == total) return found;
@@ -40,7 +40,7 @@ exports.readDirSync = function(start) {
} catch(e) {
if(e.code != 'ENOENT') throw(e); // Ignore if optional dirs are missing
return false;
- };
+ }
};
// Load package JSON file
@@ -49,8 +49,8 @@ exports.loadPackageJSON = function () {
return JSON.parse(fs.readFileSync(__dirname + '/../../package.json'));
} catch (e) {
throw('Error: Unable to find or parse SocketStream\'s package.json file');
- };
-}
+ }
+};
exports.isDir = function (filePath) { return fs.statSync(filePath).isDirectory(); };
View
@@ -2,7 +2,7 @@
exports.randomString = function (len) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = [];
- radix = chars.length;
+ var radix = chars.length;
for (var i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
return uuid.join('');
};
@@ -1,5 +1,5 @@
# SocketIO Websocket Transport
-# Alot of this code will be cleaned up and may change in the future
+# A lot of this code will be cleaned up and may change in the future
fs = require('fs')
qs = require('querystring')
@@ -74,7 +74,7 @@ module.exports = (ss, emitter, httpServer, config = {}) ->
processSession = (socket) ->
return true if socket.sessionId
- # Parse session ID from initial hankshake data
+ # Parse session ID from initial handshake data
try
rawCookie = socket.handshake.headers.cookie
cookie = qs.parse(rawCookie, '; ')

0 comments on commit b997900

Please sign in to comment.