mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-30 18:43:23 +08:00
initial custom resource loading and resource caching
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user