1 | #pomelo-loader - loader module for pomelo
|
2 |
|
3 | Load codes for pomelo based on the convention over configuration rules.
|
4 |
|
5 | pomelo-rpc could load modules in batch but not load the sub-directory recursively.
|
6 |
|
7 | + Tags: node.js
|
8 |
|
9 | ##Regulation
|
10 | Module name
|
11 |
|
12 | Module would use the filename by default. For example: load ```lib/a.js``` and the return result would be: ```{a: require('./lib/a')}```
|
13 |
|
14 | It would use the name if the module with a name property. For example
|
15 |
|
16 | ```javascript
|
17 | a.js
|
18 | exports.name = 'test';
|
19 | ```
|
20 | the return result would be: ```{test: require('./lib/a')}```
|
21 |
|
22 | Module definiation
|
23 |
|
24 | If 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
|
27 | module.exports = function(context) {
|
28 | return {}; // return some module instance
|
29 | };
|
30 | ```
|
31 |
|
32 | ##Installation
|
33 | ```
|
34 | npm install pomelo-loader
|
35 | ```
|
36 |
|
37 | ##Usage
|
38 | ``` javascript
|
39 | var Loader = require('pomelo-loader');
|
40 |
|
41 | var res = Loader.load('.');
|
42 | console.log('res: %j', res);
|
43 | ```
|
44 |
|
45 | ##API
|
46 | ###Loader.load(path, context)
|
47 | Load 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.
|