2019-05-23 19:10:06 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-07-10 13:11:46 +00:00
|
|
|
import { promises as fs } from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
2019-05-23 19:10:06 +00:00
|
|
|
import a from 'awilix';
|
|
|
|
|
2019-05-23 21:26:31 +00:00
|
|
|
import Ansi from '../Helpers/Ansi.mjs';
|
2019-05-29 10:59:40 +00:00
|
|
|
import Log from '../Helpers/Log.mjs';
|
2019-05-23 19:10:06 +00:00
|
|
|
import TTNAppServer from '../ttn-app-server/TTNAppServer.mjs';
|
2019-07-04 16:18:38 +00:00
|
|
|
import MessageHandler from '../ttn-app-server/MessageHandler.mjs';
|
2019-05-23 19:10:06 +00:00
|
|
|
|
2019-07-11 13:03:27 +00:00
|
|
|
import DataProcessor from '../process-data/DataProcessor.mjs';
|
|
|
|
|
2019-07-17 14:15:31 +00:00
|
|
|
import AITrainer from '../train-ai/AITrainer.mjs';
|
|
|
|
import DatasetFetcher from '../train-ai/DatasetFetcher.mjs';
|
|
|
|
|
2019-05-23 21:26:31 +00:00
|
|
|
import settings from './settings.mjs';
|
|
|
|
import database_init from '../bootstrap/database_init.mjs';
|
|
|
|
|
2019-07-10 13:11:46 +00:00
|
|
|
const root_dir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
2019-05-29 10:59:40 +00:00
|
|
|
|
2019-07-10 13:11:46 +00:00
|
|
|
export default async function setup() {
|
|
|
|
const c = a.createContainer({
|
|
|
|
injectionMode: a.InjectionMode.PROXY
|
|
|
|
});
|
2019-05-23 19:10:06 +00:00
|
|
|
|
2019-07-10 13:11:46 +00:00
|
|
|
c.register({
|
|
|
|
root_dir: a.asValue(root_dir),
|
|
|
|
settings: a.asValue(settings),
|
|
|
|
ansi: a.asClass(Ansi).singleton(),
|
|
|
|
log: a.asClass(Log).singleton(),
|
|
|
|
database: a.asFunction(database_init).singleton(),
|
|
|
|
TTNAppServer: a.asClass(TTNAppServer),
|
2019-07-11 13:03:27 +00:00
|
|
|
MessageHandler: a.asClass(MessageHandler),
|
2019-07-17 14:15:31 +00:00
|
|
|
|
|
|
|
DataProcessor: a.asClass(DataProcessor),
|
|
|
|
|
|
|
|
AITrainer: a.asClass(AITrainer),
|
2019-07-18 16:22:37 +00:00
|
|
|
DatasetFetcher: a.asClass(DatasetFetcher)
|
2019-07-10 13:11:46 +00:00
|
|
|
});
|
|
|
|
|
2019-07-16 17:01:17 +00:00
|
|
|
// Enable / disable colourising the output
|
|
|
|
c.cradle.ansi.enabled = settings.logging.colour;
|
|
|
|
c.cradle.ansi.escape_codes();
|
|
|
|
|
2019-07-10 13:11:46 +00:00
|
|
|
let repo_filenames = await fs.readdir(path.join(root_dir, "./Repos.SQLite"));
|
|
|
|
|
|
|
|
for(let repo_filename of repo_filenames) {
|
|
|
|
let class_root = await import(path.join(root_dir, `./Repos.SQLite/${repo_filename}`)),
|
|
|
|
class_name = class_root.default.prototype.constructor.name;
|
|
|
|
|
|
|
|
c.register(
|
|
|
|
class_name,
|
|
|
|
a.asClass(class_root.default).singleton(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.log(c.registrations);
|
|
|
|
|
|
|
|
// c.loadModules([
|
|
|
|
// "./Repos.SQLite/*.mjs"
|
|
|
|
// // "./Repos.SQLite/ReadingRepo.mjs"
|
|
|
|
// ], {
|
|
|
|
// cwd: root_dir,
|
|
|
|
// resolverOptions: {
|
|
|
|
// register: a.asClass,
|
|
|
|
// lifetime: a.Lifetime.SINGLETON
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|