Created
February 15, 2012 15:41
-
-
Save FLYBYME/1836764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** | |
| * | |
| * | |
| * | |
| */ | |
| var events = require('events'); | |
| var util = require('util'); | |
| var fs = require('fs'); | |
| var modulesObj = require('./modules'); | |
| var Evn = module.exports = function(options, app) { | |
| this._requireCache = {}; | |
| this.__dirname = options.dirname; | |
| this.__filename = options.filename; | |
| this.__app = app; | |
| this.libsDir = options.libs; | |
| this.moduleCache = {}; | |
| events.EventEmitter.call(this); | |
| }; | |
| /** | |
| * Inherits from EventEmitter | |
| */ | |
| util.inherits(Evn, events.EventEmitter); | |
| var nodeModules = ['fs', 'util', 'events'] | |
| Evn.prototype.get = function(module) { | |
| if(!!~nodeModules.indexOf(module)) { | |
| return require(module) | |
| } | |
| if(modulesObj[module]) { | |
| return modulesObj[module]; | |
| } else { | |
| this.emit('error', new Error('No such module ' + module)); | |
| } | |
| }; | |
| Evn.prototype.require = function(module) { | |
| if(this.__app.__Modules[module]) { | |
| this.__app.compileModule(this.__app.__Modules[module], this, module); | |
| return this._requireCache[module]; | |
| } else | |
| this.emit('error', new Error('No such module ' + module)); | |
| }; | |
| Evn.prototype.define = function(name, module) { | |
| this._requireCache[name] = module; | |
| return this; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment