Using package loader

This commit is contained in:
2015-04-18 22:14:36 +08:00
parent 6bfa913c06
commit efd618845c
6 changed files with 47 additions and 9 deletions
+30
View File
@@ -0,0 +1,30 @@
// 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 ) + "/";
};
Package.prototype.load = function( _class )
{
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
return lClass;
};
global.botanLoader = new Package();