2022-02-14 08:15:50 +00:00
|
|
|
import Util from './util.mjs'
|
|
|
|
import fs from 'fs/promises'
|
|
|
|
import getLog from './log.mjs'
|
|
|
|
import GetDB from './db.mjs'
|
|
|
|
import Core from './core.mjs'
|
|
|
|
|
|
|
|
|
|
|
|
export async function runner(root_import_meta_url, configname = 'config.json', dbname = 'db.json') {
|
|
|
|
if (!root_import_meta_url) {
|
|
|
|
throw new Error('ServiceRunner must be called with the full string from "import.meta.url" from a file residing in the root directory')
|
|
|
|
}
|
|
|
|
const util = new Util(root_import_meta_url)
|
|
|
|
|
|
|
|
let config = configname
|
|
|
|
if (typeof(config) === 'string') {
|
|
|
|
let fullpath = util.getPathFromRoot('./' + config)
|
|
|
|
|
|
|
|
try {
|
|
|
|
config = JSON.parse(await fs.readFile(fullpath))
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error(`critical error opening ${fullpath}: ${err.message}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const log = getLog(config.name)
|
|
|
|
runner.log = log
|
|
|
|
const db = await GetDB(config, log, util.getPathFromRoot('./' + dbname))
|
|
|
|
|
2022-02-15 11:28:30 +00:00
|
|
|
const core = new Core(db, util, log)
|
2022-02-14 08:15:50 +00:00
|
|
|
await core.init()
|
|
|
|
await core.run()
|
|
|
|
|
|
|
|
return core
|
|
|
|
}
|
|
|
|
|
|
|
|
runner.log = getLog('runner')
|