2018-01-13 18:46:29 +00:00
|
|
|
// @flow
|
2020-08-09 05:53:59 +00:00
|
|
|
import path from "path";
|
2020-06-20 20:59:15 +00:00
|
|
|
import debug from "debug";
|
|
|
|
import fs from "fs-extra";
|
2018-01-13 18:46:29 +00:00
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
const log = debug("services");
|
2018-01-13 18:46:29 +00:00
|
|
|
const services = {};
|
|
|
|
|
2020-08-09 01:53:11 +00:00
|
|
|
fs.readdirSync(__dirname)
|
2020-04-20 05:14:31 +00:00
|
|
|
.filter(
|
2020-08-09 01:53:11 +00:00
|
|
|
(file) =>
|
2020-06-20 20:59:15 +00:00
|
|
|
file.indexOf(".") !== 0 &&
|
2020-04-20 05:14:31 +00:00
|
|
|
file !== path.basename(__filename) &&
|
2020-06-20 20:59:15 +00:00
|
|
|
!file.includes(".test")
|
2020-04-20 05:14:31 +00:00
|
|
|
)
|
2020-08-09 01:53:11 +00:00
|
|
|
.forEach((fileName) => {
|
2018-12-05 06:24:30 +00:00
|
|
|
const servicePath = path.join(__dirname, fileName);
|
2020-06-20 20:59:15 +00:00
|
|
|
const name = path.basename(servicePath.replace(/\.js$/, ""));
|
2018-01-13 18:46:29 +00:00
|
|
|
// $FlowIssue
|
2018-12-05 06:24:30 +00:00
|
|
|
const Service = require(servicePath).default;
|
|
|
|
services[name] = new Service();
|
2020-04-20 05:14:31 +00:00
|
|
|
log(`loaded ${name} service`);
|
2018-01-13 18:46:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default services;
|