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

feat: support dot file #24

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion lib/mods.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = function getMods(dirpath, opt) {
var properties = name.replace('.js', '')
.split('/')
.map(function(property) {
var reg = /^[a-z][a-z0-9_-]*$/ig;
// want support dao/User.sqlmap.js;
var reg = /^[a-z][a-z\.0-9_-]*$/ig;
if (!reg.test(property)) {
throw new Error(property + ' is not match ' + reg + ' in ' + name);
}
Copy link
Member

Choose a reason for hiding this comment

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

property.replace(/[_-][a-z]/ig 这个需要将 . 改成驼峰么

Copy link
Member

Choose a reason for hiding this comment

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

感觉一般来说都是用:name.postfix.js 这样的,保留比较合理?

Copy link
Author

Choose a reason for hiding this comment

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

我也是想保留 user.sqlmap.js 的模式; 感觉直观一些;

image

Copy link
Member

Choose a reason for hiding this comment

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

比较奇怪吧,不能用属性访问

Copy link
Member

Choose a reason for hiding this comment

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

这个还搞么?

Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/services/dot.dir/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (app) {
return {
load: true,
app: app
};
};
2 changes: 1 addition & 1 deletion test/loading.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('loading.test.js', function () {
loading(path.join(__dirname, 'fixtures', 'services')).into(app, 'services');

app.should.have.property('services');
app.services.should.have.keys('dir', 'foo', 'fooBarHello', 'fooService', 'hyphenDir', 'underscoreDir', 'userProfile');
app.services.should.have.keys('dir', 'foo', 'fooBarHello', 'fooService', 'hyphenDir', 'underscoreDir', 'userProfile', 'dot.dir', 'dot.file');
app.services.fooService.should.have.keys('a');

done = pedding(2, done);
Expand Down
25 changes: 16 additions & 9 deletions test/mods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('mods.test.js', function() {
it('should get mods', function() {
var dir = join(fixtures, 'services');
var sortFn = function(x, y){
return x.fullpath < y.fullpath;
return x.fullpath < y.fullpath ? 1 : -1;
};
var mods = getMods(dir).sort(sortFn);
mods.should.eql([{
Expand Down Expand Up @@ -40,28 +40,35 @@ describe('mods.test.js', function() {
}, {
fullpath: dir + '/userProfile.js',
properties: ['userProfile']
}, {
fullpath: dir + '/dot.file.js',
properties: ['dot.file']
}, {
fullpath: dir + '/dot.dir/a.js',
properties: ['dot.dir', 'a']
}].sort(sortFn));
});

it('should throw when directory contains dot', function() {
(function() {
getMods(join(fixtures, 'error/dotdir'));
}).should.throw('dot.dir is not match /^[a-z][a-z0-9_-]*$/gi in dot.dir/a.js');
});
// when support dot file, this case will remove;
// it('should throw when directory contains dot', function() {
Copy link
Member

Choose a reason for hiding this comment

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

把这个测试用例改对吧,dot.dir 应该变成怎样

Copy link
Author

Choose a reason for hiding this comment

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

dot.dir也会变成同步支持. 现在好像没法区分是file还是dir

// (function() {
// getMods(join(fixtures, 'error/dotdir'));
// }).should.throw('dot.dir is not match /^[a-z][a-z0-9_-]*$/gi in dot.dir/a.js');
// });

it('should throw when directory starts with underscore', function() {
(function() {
getMods(join(fixtures, 'error/underscore-dir'));
}).should.throw('_underscore is not match /^[a-z][a-z0-9_-]*$/gi in _underscore/a.js');
}).should.throw('_underscore is not match /^[a-z][a-z\\.0-9_-]*$/gi in _underscore/a.js');
(function() {
getMods(join(fixtures, 'error/underscore-file-in-dir'));
}).should.throw('_a is not match /^[a-z][a-z0-9_-]*$/gi in dir/_a.js');
}).should.throw('_a is not match /^[a-z][a-z\\.0-9_-]*$/gi in dir/_a.js');
});

it('should throw when file starts with underscore', function() {
(function() {
getMods(join(fixtures, 'error/underscore-file'));
}).should.throw('_private is not match /^[a-z][a-z0-9_-]*$/gi in _private.js');
}).should.throw('_private is not match /^[a-z][a-z\\.0-9_-]*$/gi in _private.js');
});

});