Permalink
Browse files

get rid of InternalContext, make load* calls into callback-style, mov…

…e load* method to Context
  • Loading branch information...
jaredcosulich committed Sep 7, 2012
1 parent 054aca8 commit 56f0d376cb2081623fb710db41f4ca65fc8bd76c
Showing with 756 additions and 683 deletions.
  1. +49 −8 bin/soma
  2. +178 −169 lib/client/ender.js
  3. +28 −14 lib/index.js
  4. +175 −177 lib/node/index.js
  5. +168 −147 src/client/ender.coffee
  6. +22 −27 src/index.coffee
  7. +136 −141 src/node/index.coffee
View
@@ -1,6 +1,6 @@
#!/usr/bin/env node
// Generated by CoffeeScript 1.3.3
-var domain, fs, http, load, mime, path, soma,
+var domain, fs, http, load, loadFiles, mime, path, soma,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
domain = require('domain');
@@ -15,6 +15,41 @@ mime = require('../lib/node/lib/mime');
soma = require('soma');
+loadFiles = function(source, tree) {
+ var abs, url, watcher;
+ if (tree == null) {
+ tree = {};
+ }
+ if (fs.statSync(source).isDirectory()) {
+ watcher = fs.watch(source, function() {
+ var name, _i, _len, _ref, _results;
+ if (!path.existsSync(source)) {
+ console.log('Directory went missing: ', source);
+ delete tree[basename];
+ watcher.close();
+ return;
+ }
+ _ref = fs.readdirSync(source);
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ name = _ref[_i];
+ if (name[0] === '.') {
+ continue;
+ }
+ _results.push(tree[name] = loadFiles("" + source + "/" + name));
+ }
+ return _results;
+ });
+ watcher.emit('change');
+ return tree;
+ } else {
+ abs = "" + (process.cwd()) + "/" + source;
+ url = "/" + source;
+ soma.files[url] = fs.readFileSync(source, encoding);
+ return url;
+ }
+};
+
load = function(source, exec, serve) {
var abs, m, name, names, stats, url, urls, watcher, _i, _len;
stats = fs.statSync(source);
@@ -65,26 +100,32 @@ load = function(source, exec, serve) {
};
soma.init = function() {
- var packageJSON, scripts, serverDomain, source, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3;
+ var scripts, serverDomain, source, _base, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3;
soma.files = {};
- packageJSON = JSON.parse(fs.readFileSync('package.json'));
- _ref = packageJSON.soma.shared;
+ soma.config = JSON.parse(fs.readFileSync('package.json')).soma;
+ (_base = soma.config).chunks || (_base.chunks = 'chunks');
+ soma.tree = {};
+ loadFiles(soma.config.chunks, soma.tree);
+ if (soma.config.templates) {
+ loadFiles(soma.config.templates, soma.tree);
+ }
+ _ref = soma.config.shared;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
source = _ref[_i];
load(path.normalize(source), true, true);
}
- _ref1 = packageJSON.soma.server;
+ _ref1 = soma.config.server;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
source = _ref1[_j];
load(path.normalize(source), true, false);
}
- _ref2 = packageJSON.soma.client;
+ _ref2 = soma.config.client;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
source = _ref2[_k];
load(path.normalize(source), false, true);
}
scripts = [];
- _ref3 = packageJSON.soma.init;
+ _ref3 = soma.config.init;
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
source = _ref3[_l];
scripts = scripts.concat(load(path.normalize(source), false, true));
@@ -129,7 +170,7 @@ soma.init = function() {
}
});
});
- port = process.env.PORT || packageJSON.soma.port || 8000;
+ port = process.env.PORT || soma.config.port || 8000;
server.listen(port);
return console.log("Soma listening on port " + port + "...");
});
Oops, something went wrong.

0 comments on commit 56f0d37

Please sign in to comment.