feat(framework): config 调试 profiles + ?profile= 切换
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { ChannelIdentity } from './identity.ts';
|
||||
|
||||
export interface DebugProfile {
|
||||
name: string;
|
||||
server?: string; // 显式 ws 调试服地址(给定则跳过远程抓取)
|
||||
gameserver?: string; // 远程配置 txt URL(不含防缓存串)
|
||||
identity?: Partial<ChannelIdentity>; // 调试用渠道身份覆盖
|
||||
isDebugger?: boolean; // 收发包日志开关(替代旧 Game_Config.Debugger.isDebugger)
|
||||
}
|
||||
|
||||
/** 正式 gameserver:原 00_SubGame_Config.js:11。 */
|
||||
export const DEFAULT_GAMESERVER = 'http://ylyxservice1.0791ts.cn/config/update_json.txt';
|
||||
/** 测试 gameserver:原 00_SubGame_Config.js:9 注释。 */
|
||||
const STAGING_GAMESERVER = 'http://testgame.youlehdyx.com/update_json/ceshi_json.txt';
|
||||
|
||||
export const PROFILES: Record<string, DebugProfile> = {
|
||||
prod: { name: 'prod', gameserver: DEFAULT_GAMESERVER, isDebugger: false },
|
||||
staging: { name: 'staging', gameserver: STAGING_GAMESERVER, isDebugger: true },
|
||||
local: { name: 'local', server: 'ws://127.0.0.1:3088', isDebugger: true },
|
||||
};
|
||||
|
||||
/** 发布只需保持 'prod'。 */
|
||||
export const ACTIVE_PROFILE = 'prod';
|
||||
|
||||
/** 解析当前 profile:ACTIVE_PROFILE 为基线,?profile=<name> 临时切换;未知名回退 ACTIVE_PROFILE。 */
|
||||
export function resolveActiveProfile(search: string): DebugProfile {
|
||||
const name = new URLSearchParams(search).get('profile') || ACTIVE_PROFILE;
|
||||
return PROFILES[name] ?? PROFILES[ACTIVE_PROFILE];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { resolveActiveProfile, PROFILES, ACTIVE_PROFILE } from '../../YouleNexus/assets/framework/config/profiles.ts';
|
||||
|
||||
test('默认返回 ACTIVE_PROFILE', () => {
|
||||
const p = resolveActiveProfile('');
|
||||
assert.equal(p.name, ACTIVE_PROFILE);
|
||||
});
|
||||
|
||||
test('prod profile 无调试覆盖、isDebugger=false', () => {
|
||||
const prod = PROFILES['prod'];
|
||||
assert.equal(prod.isDebugger, false);
|
||||
assert.equal(prod.server, undefined);
|
||||
assert.equal(prod.identity, undefined);
|
||||
assert.ok(prod.gameserver && prod.gameserver.length > 0);
|
||||
});
|
||||
|
||||
test('?profile=local 切到 local,含调试服地址', () => {
|
||||
const p = resolveActiveProfile('?profile=local');
|
||||
assert.equal(p.name, 'local');
|
||||
assert.ok(p.server && p.server.startsWith('ws://'));
|
||||
});
|
||||
|
||||
test('未知 profile 回退到 ACTIVE_PROFILE', () => {
|
||||
const p = resolveActiveProfile('?profile=nope');
|
||||
assert.equal(p.name, ACTIVE_PROFILE);
|
||||
});
|
||||
Reference in New Issue
Block a user