UNPKG

1.28 kBMarkdownView Raw
1#pomelo-loader - loader module for pomelo
2
3Load codes for pomelo based on the convention over configuration rules.
4
5pomelo-rpc could load modules in batch but not load the sub-directory recursively.
6
7+ Tags: node.js
8
9##Regulation
10Module name
11
12Module would use the filename by default. For example: load ```lib/a.js``` and the return result would be: ```{a: require('./lib/a')}```
13
14It would use the name if the module with a name property. For example
15
16```javascript
17a.js
18exports.name = 'test';
19```
20the return result would be: ```{test: require('./lib/a')}```
21
22Module definiation
23
24If the module exported as a function, pomelo-loader would take it as a factory method and generate a new instance of module by calling the function. And it would return the module directly for other situation.
25
26```javascript
27module.exports = function(context) {
28 return {}; // return some module instance
29};
30```
31
32##Installation
33```
34npm install pomelo-loader
35```
36
37##Usage
38``` javascript
39var Loader = require('pomelo-loader');
40
41var res = Loader.load('.');
42console.log('res: %j', res);
43```
44
45##API
46###Loader.load(path, context)
47Load all modules in the path.
48####Parameters
49+ path loaded path
50+ context if the module provides a factory method, the context would be pass as a parameter as the factory method.