initial custom resource loading and resource caching

This commit is contained in:
Ritchie Martori
2012-07-24 13:00:18 -07:00
parent d200b22fe0
commit 2d0b48b0c1
10 changed files with 110 additions and 41 deletions

View File

@@ -1,35 +1,35 @@
var fs = require('fs');
module.exports = function loadTypes(basepath, fn) {
var types = {}
, defaults = {};
var types = {}
defaults = {};
if(typeof basepath == 'function') {
fn = basepath;
basepath = undefined;
}
if(typeof basepath == 'function') {
fn = basepath;
basepath = undefined;
}
var path = basepath || './resources';
var path = basepath || './resources';
// read default lib resources
fs.readdir(__dirname + '/resources', function(err, dir) {
dir.forEach(function(file) {
if(file.indexOf('.js') == file.length - 3 || file.indexOf('.') === -1) {
var c = require(path + '/' + file);
defaults[c.name] = c;
}
});
// read local project resources
// fs.readdir(path, function(err, dir) {
// dir && dir.forEach(function(file) {
// if(file.indexOf('.js') == file.length - 3) {
// var c = require(require('path').resolve(path) + '/' + file);
// types[c.name] = c;
// }
// });
// read default lib resources
fs.readdir(__dirname + '/resources', function(err, dir) {
dir.forEach(function(file) {
if(file.indexOf('.js') == file.length - 3) {
var c = require(path + '/' + file);
defaults[c.name] = c;
}
});
fn(defaults, types);
});
// });
// read local project resources
fs.readdir(path, function(err, dir) {
dir && dir.forEach(function(file) {
if(file.indexOf('.js') == file.length - 3 || file.indexOf('.') === -1) {
var c = require(require('path').resolve(path) + '/' + file);
types[c.name] = c;
}
});
fn(defaults, types);
});
});
}