Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve #9

Merged
merged 5 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .autod.conf
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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. -->
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ this.loadExtend('application', app);
- {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
- {Function} initializer - custom file exports, receive two parameters, the first one is the inject object,
second one is the path of the loaded file.
- {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
Expand Down
8 changes: 8 additions & 0 deletions lib/loader/egg_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,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
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function getExports(fullpath, initializer, isCall, inject) {

// process exports as you like
if (initializer) {
exports = initializer(exports);
exports = initializer(exports, fullpath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

第二个参数是不是改为 info { fullpath, ... } 之类的 Object, 预留扩展位好点?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩,改成 opt

TZ | 天猪 [email protected]于2016年8月17日 周三上午8:25写道:

In lib/loader/file_loader.js
#9 (comment):

@@ -119,7 +119,7 @@ function getExports(fullpath, initializer, isCall, inject) {

// process exports as you like
if (initializer) {

  • exports = initializer(exports);
  • exports = initializer(exports, fullpath);

第二个参数是不是改为 info { fullpath, ... } 之类的 Object, 预留扩展位好点?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/eggjs/egg-core/pull/9/files/268073f496b5cfcbf8f449b43238ba288bf7db1f#r75045138,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWA1bt6OxIpc_5Kp9V9zsPyZkV4wHKgks5qglTwgaJpZM4JlsDo
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fullPath or filePath

}

// return exports when it's a class or generator
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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, fullpath) {
return new exports(app, fullpath);
},
}).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