My LoRaWAN Signal Mapping MSc summer project. This is a copy of the actual repository with personal information removed.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
1.5 KiB

"use strict";
import { promises as fs } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import a from 'awilix';
import Ansi from '../Helpers/Ansi.mjs';
import Log from '../Helpers/Log.mjs';
import TTNAppServer from '../ttn-app-server/TTNAppServer.mjs';
import MessageHandler from '../ttn-app-server/MessageHandler.mjs';
import settings from './settings.mjs';
import database_init from '../bootstrap/database_init.mjs';
const root_dir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
export default async function setup() {
const c = a.createContainer({
injectionMode: a.InjectionMode.PROXY
});
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),
MessageHandler: a.asClass(MessageHandler)
});
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;
}