import moduleAlias from 'module-alias';
import { FOLDERS } from './constants/index';
import { root } from './root';

moduleAlias.addAliases({
	'#': __dirname,
	...FOLDERS.reduce(
		(folderAlias, folder) => Object.assign(folderAlias, { [`#${folder}`]: `${__dirname}/${folder}` }),
		{},
	),
});
moduleAlias();

// Set global base directory
(global as any).__baseDir = root;

// Validate required environment variables before starting the server
import { validateEnv } from './utils/envValidator';
validateEnv();

const { startServer } = require('./server');
import type { Environment } from './interfaces/IEnv';

// eslint-disable-next-line no-restricted-syntax
startServer(<Environment>(process.env.NODE_ENV?.toLowerCase() ?? 'development'));
