Skip to content

Commit

Permalink
loader/service: use class name as the service name
Browse files Browse the repository at this point in the history
Use class name as the service name when load serice.

PR-URL: #18
Reviewed-By: XadillaX <i@2333.moe>
  • Loading branch information
DuanPengfei authored and XadillaX committed Jul 6, 2017
1 parent f26f7a2 commit 93c3cff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/loader/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fs = require("fs");
const path = require("path");

const _ = require("lodash");
const Case = require("case");

class Service {
constructor(akyuu) {
Expand All @@ -33,8 +34,14 @@ class Service {
this.load(`${file}/${filenames[i]}`);
} else if(_.endsWith(filenames[i], ".js")) {
const apiName = filenames[i].substr(0, filenames[i].length - 3).toLowerCase();
this.services[apiName] = new (require(`${directory}/${filenames[i]}`))();
this.serviceClasses[apiName] = require(`${directory}/${filenames[i]}`);

const apiClass = require(`${directory}/${filenames[i]}`);
const apiClassInstance = new apiClass();
let apiClassName = apiClassInstance.constructor.name;
apiClassName = Case.snake(apiClassName);

this.services[apiClassName] = apiClassInstance;
this.serviceClasses[apiClassName] = apiClass;
this.logger.info(`Service \`${apiName}\` loaded.`);
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"homepage": "https://github.com/akyuujs/akyuu#readme",
"dependencies": {
"async": "^2.1.5",
"case": "^1.5.2",
"config": "^1.20.1",
"debug": "^2.2.0",
"ero": "^0.2.3",
Expand Down

0 comments on commit 93c3cff

Please sign in to comment.