BotanSS/package.js

35 lines
676 B
JavaScript
Raw Normal View History

2015-04-18 14:14:36 +00:00
// The Package Loader
var fs = require( "fs" );
var rootNS = {
botanss: "./"
};
var Package = function() { };
Package.prototype.rootNS = function( name, path )
{
if( rootNS[ name ] ) return;
rootNS[ name ] = fs.realpathSync( path ) + "/";
};
2015-06-03 06:45:45 +00:00
Package.prototype.load = function( _class, deCache )
2015-04-18 14:14:36 +00:00
{
var fSep = _class.indexOf( "." );
var nsdomain = _class.substr( 0, fSep );
_class = _class.substr( fSep + 1 ).replace( /\./g, "/" );
var file = rootNS[ nsdomain ] + _class;
var lClass = require( file );
// TODO: Implements filewatcher
2015-06-03 06:45:45 +00:00
if( deCache )
{
delete require.cache[ require.resolve( file ) ];
}
2015-04-18 14:14:36 +00:00
return lClass;
};
global.botanLoader = new Package();