2023-10-26 20:12:19 +02:00
|
|
|
import "reflect-metadata";
|
2023-10-28 21:39:17 +02:00
|
|
|
import { container, DependencyContainer } from "tsyringe";
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
// For the Vitest Custom Environment.
|
|
|
|
import type { Environment } from "vitest";
|
2023-10-28 21:39:17 +02:00
|
|
|
import { Container } from "@spt-aki/di/Container";
|
2023-10-30 03:21:21 +01:00
|
|
|
|
|
|
|
// Required for importing the database.
|
2023-10-30 22:38:37 +01:00
|
|
|
import path from "node:path";
|
2023-10-27 23:48:24 +02:00
|
|
|
import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
|
2023-10-28 21:39:17 +02:00
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { ImporterUtil } from "@spt-aki/utils/ImporterUtil";
|
2023-10-26 20:12:19 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
export default <Environment> {
|
|
|
|
name: "spt-aki-server",
|
|
|
|
transformMode: "ssr",
|
|
|
|
async setup()
|
2023-10-26 20:12:19 +02:00
|
|
|
{
|
2023-10-30 03:21:21 +01:00
|
|
|
// Register all of the dependencies in the container.
|
2023-10-28 21:39:17 +02:00
|
|
|
Container.registerTypes(container);
|
|
|
|
Container.registerListTypes(container);
|
2023-10-26 20:12:19 +02:00
|
|
|
|
2023-10-27 23:48:24 +02:00
|
|
|
// Import the database.
|
2023-10-28 05:55:34 +02:00
|
|
|
await importDatabase(container);
|
2023-10-26 23:19:16 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
return {
|
2023-10-30 03:21:21 +01:00
|
|
|
async teardown()
|
2023-10-30 22:38:37 +01:00
|
|
|
{}
|
2023-10-28 05:55:34 +02:00
|
|
|
};
|
2023-10-26 20:12:19 +02:00
|
|
|
}
|
2023-10-28 05:55:34 +02:00
|
|
|
};
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-30 03:21:21 +01:00
|
|
|
/**
|
|
|
|
* Reads the database JSON files and imports them into memory.
|
|
|
|
*
|
|
|
|
* @param container The dependency container.
|
|
|
|
* @returns A void promise.
|
|
|
|
*/
|
2023-10-28 05:55:34 +02:00
|
|
|
async function importDatabase(container: DependencyContainer): Promise<void>
|
|
|
|
{
|
|
|
|
const importerUtil = container.resolve<ImporterUtil>("ImporterUtil");
|
|
|
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
// Read the data from the JSON files.
|
|
|
|
const databaseDir = path.resolve("./assets/database");
|
|
|
|
const dataToImport = await importerUtil.loadAsync<IDatabaseTables>(`${databaseDir}/`);
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
// Save the data to memory.
|
|
|
|
databaseServer.setTables(dataToImport);
|
2023-10-26 20:12:19 +02:00
|
|
|
}
|