From b7d32c5e693002eebeb669e635131a15e50801c5 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Mon, 4 Mar 2024 23:58:18 +0800 Subject: [PATCH] refactor(shell): log engine version --- packages/shell/src/index.ts | 20 ++++++++++++-------- packages/shell/src/types.ts | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/shell/src/index.ts b/packages/shell/src/index.ts index c1aaf80..a73ae68 100644 --- a/packages/shell/src/index.ts +++ b/packages/shell/src/index.ts @@ -48,26 +48,30 @@ export const chronocat = async () => { return { name, + filename, type, path: join(enginesPath, filename), } }) - for (const engine of engines) { + for (const engineInfo of engines) { try { - l.info( - `加载引擎:${styles.green.open}${engine.name}${styles.green.close}`, + l.debug( + `加载引擎:${styles.green.open}${engineInfo.filename}${styles.green.close}`, ) - if (engine.type === 'jsc') - require('bytenode') + if (engineInfo.type === 'jsc') require('bytenode') - // eslint-disable-next-line @typescript-eslint/no-var-requires - ;(require(engine.path) as Engine).apply(ctx) + // eslint-disable-next-line @typescript-eslint/no-var-requires + const engine = require(engineInfo.path) as unknown as Engine + l.info( + `使用引擎 ${engine.name} v${engine.version}${styles.grey.open},来自 ${engineInfo.filename}${styles.grey.close}`, + ) + engine.apply(ctx) } catch (e) { setTimeout(() => process.exit(1), 2000) l.error( - new Error(`加载引擎 ${engine.name} 失败`, { + new Error(`加载引擎 ${engineInfo.filename} 失败`, { cause: e, }), { diff --git a/packages/shell/src/types.ts b/packages/shell/src/types.ts index 5e3f4b1..bd72f3d 100644 --- a/packages/shell/src/types.ts +++ b/packages/shell/src/types.ts @@ -25,6 +25,8 @@ export interface ChronocatContext { } export interface Engine { + name: string + version: string apply: (ctx: ChronocatContext) => unknown }