const path = require('path');
const dotenv = require('dotenv');

const instances = Number.parseInt(process.env.WEB_CONCURRENCY ?? '1', 10) || 1;
const { parsed: envFromFile = {} } = dotenv.config({ path: path.join(__dirname, '.env') });

module.exports = {
	apps: [
		{
			name: "DouyinArchive",
			script: 'index.ts',
			cwd: __dirname,
			autorestart: true,
			restart_delay: 4000,
			kill_timeout: 5000,
			instances,
			exec_mode: instances > 1 ? 'cluster' : 'fork',
			watch: process.env.NODE_ENV !== 'production',
			ignore_watch: ['generated', 'node_modules', '.git'],
			env: {
				...envFromFile,
				NODE_ENV: 'development'
			},
			env_production: {
				...envFromFile,
				NODE_ENV: 'production'
			},
			time: true
		}
	]
};
