Skip to content

Commit

Permalink
Merge branch 'master' into code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Aug 17, 2016
2 parents c92ea85 + 4c2848a commit 827c48b
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 18 deletions.
17 changes: 17 additions & 0 deletions .autod.conf
@@ -0,0 +1,17 @@
'ues strict';

module.exports = {
write: true,
prefix: '^',
devprefix: '^',
exclude: [
'test/fixtures',
],
devdep: [
'autod',
],
keep: [
],
semver: [
],
};
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,24 @@
<!--
Thank you for your pull request. Please review below requirements.
Bug fixes and new features should include tests and possibly benchmarks.
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
感谢您贡献代码。请确认下列 checklist 的完成情况。
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
-->

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [ ] `npm test` passes
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows commit guidelines

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s). -->


##### Description of change
<!-- Provide a description of the change below this comment. -->
26 changes: 18 additions & 8 deletions README.md
Expand Up @@ -211,13 +211,23 @@ this.loadExtend('application', app);

### LoaderOptions

- {String|Array} directory - directories to load
- {Object} target: attach object from loaded files,
- {String} ignore - ignore the files when load
- {Function} initializer - custom file exports
- {Boolean} lowercaseFirst - determine whether the fist letter is lowercase
- {Boolean} override: determine whether override the property when get the same name
- {Boolean} call - determine whether invoke when exports is function
- {Object} inject - an object that be the argument when invoke the function
Param | Type | Description
-------------- | -------------- | ------------------------
directory | `String/Array` | directories to load
target | `Object` | attach object from loaded files
ignore | `String` | ignore the files when load
initializer | `Function` | custom file exports, receive two parameters, first is the inject object, second is an `options` object that contain `path`
lowercaseFirst | `Boolean` | determine whether the fist letter is lowercase
override | `Boolean` | determine whether override the property when get the same name
call | `Boolean` | determine whether invoke when exports is function
inject | `Object` | an object that be the argument when invoke the function

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

[egg]: https://github.com/eggjs/egg
8 changes: 8 additions & 0 deletions lib/loader/egg_loader.js
Expand Up @@ -268,6 +268,14 @@ class EggLoader {
new ContextLoader(opt).load();
}

get FileLoader() {
return FileLoader;
}

get ContextLoader() {
return ContextLoader;
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/loader/file_loader.js
Expand Up @@ -120,7 +120,7 @@ function getExports(fullpath, initializer, isCall, inject) {

// process exports as you like
if (initializer) {
exports = initializer(exports);
exports = initializer(exports, { path: fullpath });
}

// return exports when it's a class or generator
Expand Down
14 changes: 8 additions & 6 deletions package.json
Expand Up @@ -4,6 +4,7 @@
"description": "A core Plugable framework based on koa",
"main": "index.js",
"scripts": {
"autod": "autod",
"lint": "eslint lib test *.js",
"test": "npm run lint && egg-bin test",
"cov": "egg-bin cov",
Expand All @@ -30,29 +31,30 @@
"version": "4, 6"
},
"devDependencies": {
"autod": "^2.7.0",
"egg-bin": "1",
"egg-ci": "1",
"eslint": "~3.1.0",
"eslint-config-egg": "3",
"koa": "1",
"koa-router": "4",
"mm": "1",
"mm": "^2.0.0",
"pedding": "^1.0.0",
"should": "9",
"supertest": "1"
"should": "^11.1.0",
"supertest": "^2.0.0"
},
"dependencies": {
"debug": "^2.2.0",
"depd": "^1.1.0",
"egg-logger": "^1.1.0",
"egg-logger": "^1.2.0",
"extend": "^3.0.0",
"globby": "^6.0.0",
"inflection": "^1.10.0",
"interop-require": "^1.0.0",
"is-type-of": "^1.0.0",
"koa": "^1.2.0",
"koa": "^1.2.1",
"koa-router": "^5.4.0",
"ready-callback": "^1.0.0",
"utility": "^1.8.0"
}
}
}
4 changes: 3 additions & 1 deletion test/fixtures/load_dirs/dao/TestClass.js
@@ -1,9 +1,11 @@
'use strict';

module.exports = class TestClass {
constructor() {
constructor(app, fullpath) {
this.user = {
name: 'kai.fangk',
};
this.app = app;
this.path = fullpath;
}
}
18 changes: 18 additions & 0 deletions test/loader/egg_loader.test.js
@@ -0,0 +1,18 @@
'use strict';

const should = require('should');
const utils = require('../utils');

describe('test/loader/egg_loader.test.js', () => {

let app;
before(() => {
app = utils.createApp('nothing');
});

it('should container FileLoader and ContextLoader', () => {
should.exists(app.loader.FileLoader);
should.exists(app.loader.ContextLoader);
});

});
6 changes: 4 additions & 2 deletions test/loader/file_loader.test.js
Expand Up @@ -155,12 +155,14 @@ describe('test/file_loader.test.js', () => {
directory: path.join(dirBase, 'dao'),
target: app.dao,
ignore: 'util/**',
initializer(exports) {
return new exports(app);
initializer(exports, opt) {
return new exports(app, opt.path);
},
}).load();
app.dao.should.have.property('TestClass');
app.dao.TestClass.user.should.eql({ name: 'kai.fangk' });
app.dao.TestClass.app.should.equal(app);
app.dao.TestClass.path.should.equal(path.join(dirBase, 'dao/TestClass.js'));
app.dao.should.have.property('testFunction', { user: { name: 'kai.fangk' } });
app.dao.should.have.property('testReturnFunction', { user: { name: 'kai.fangk' } });
});
Expand Down

0 comments on commit 827c48b

Please sign in to comment.