fix: support containerized release runtimes
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
"scripts": {
|
||||
"build": "tsdown -c ../../tsdown.config.ts -F @sammo-ts/game-engine",
|
||||
"dev": "tsdown -c ../../tsdown.config.ts -F @sammo-ts/game-engine --watch",
|
||||
"start": "pnpm run build && node dist/index.js",
|
||||
"start": "pnpm run build && GAME_ENGINE_ROLE=turn-daemon node dist/index.js",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"profile:npc-unification-memory": "node scripts/profile-npc-unification-memory.mjs",
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { runTurnDaemonCli } from './turn/cli.js';
|
||||
|
||||
export * from './lifecycle/types.js';
|
||||
@@ -29,17 +26,9 @@ export * from './turn/selectPoolService.js';
|
||||
export * from './turn/turnDaemon.js';
|
||||
export * from './turn/cli.js';
|
||||
|
||||
const isMain = (): boolean => {
|
||||
if (typeof process.env.NODE_APP_INSTANCE === 'string') {
|
||||
return true;
|
||||
}
|
||||
if (!process.argv[1]) {
|
||||
return false;
|
||||
}
|
||||
return fileURLToPath(import.meta.url) === path.resolve(process.argv[1]);
|
||||
};
|
||||
export const shouldRunTurnDaemon = (role: string | undefined): boolean => role === 'turn-daemon';
|
||||
|
||||
if (isMain()) {
|
||||
if (shouldRunTurnDaemon(process.env.GAME_ENGINE_ROLE)) {
|
||||
runTurnDaemonCli().catch((error) => {
|
||||
console.error('[turn-daemon] failed to start', error);
|
||||
process.exitCode = 1;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { shouldRunTurnDaemon } from '../src/index.js';
|
||||
|
||||
describe('game-engine entrypoint', () => {
|
||||
it('starts only for an explicitly selected turn-daemon role', () => {
|
||||
expect(shouldRunTurnDaemon('turn-daemon')).toBe(true);
|
||||
expect(shouldRunTurnDaemon('api')).toBe(false);
|
||||
expect(shouldRunTurnDaemon(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user