diff --git a/packages/shell/src/index.ts b/packages/shell/src/index.ts index 3bab3af..24005a8 100644 --- a/packages/shell/src/index.ts +++ b/packages/shell/src/index.ts @@ -29,6 +29,7 @@ interface EngineInfo { filename: string type: string path: string + hidden: boolean } export const chronocat = async () => { @@ -60,27 +61,29 @@ export const chronocat = async () => { }, } - const enginesPath = join(baseDir, 'engines') + const engines: EngineInfo[] = [] - mkdirSync(enginesPath, { + const externalEnginesPath = join(baseDir, 'engines') + + mkdirSync(externalEnginesPath, { recursive: true, }) - const engines = readdirSync(enginesPath) + readdirSync(externalEnginesPath) .map((filename) => { let valid = false let name = filename let type = 'js' - if (name.endsWith('.jsc')) { + if (name.endsWith('.engine.jsc')) { valid = true - name = name.slice(0, name.length - 4) + name = name.slice(0, name.length - 11) type = 'jsc' } - if (name.endsWith('.js')) { + if (name.endsWith('.engine.js')) { valid = true - name = name.slice(0, name.length - 3) + name = name.slice(0, name.length - 10) } if (!valid) return undefined @@ -89,13 +92,46 @@ export const chronocat = async () => { name, filename, type, - path: join(enginesPath, filename), + path: join(externalEnginesPath, filename), + hidden: false, } }) .filter( Boolean as unknown as (x: EngineInfo | undefined) => x is EngineInfo, ) + if (!engines.length) + readdirSync(__dirname) + .map((filename) => { + let valid = false + let name = filename + let type = 'js' + + if (name.endsWith('.engine.jsc')) { + valid = true + name = name.slice(0, name.length - 11) + type = 'jsc' + } + + if (name.endsWith('.engine.js')) { + valid = true + name = name.slice(0, name.length - 10) + } + + if (!valid) return undefined + + return { + name, + filename, + type, + path: join(__dirname, filename), + hidden: true, + } + }) + .filter( + Boolean as unknown as (x: EngineInfo | undefined) => x is EngineInfo, + ) + if (!engines.length) l.warn('没有找到任何引擎。Chronocat 服务仍将启动。', { code: 2156 }) @@ -110,7 +146,7 @@ export const chronocat = async () => { // 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}`, + `使用引擎 ${styles.green.open}${engine.name}${styles.green.close} v${engine.version}${engineInfo.hidden ? '' : `${styles.grey.open},来自 ${engineInfo.filename}${styles.grey.close}`}`, ) engine.apply(ctx) } catch (e) { diff --git a/scripts/packengine.cts b/scripts/packengine.cts index 0909422..3d57c2d 100644 --- a/scripts/packengine.cts +++ b/scripts/packengine.cts @@ -5,12 +5,25 @@ void Promise.all( ['engine-chronocat-api', 'engine-chronocat-event'].map(async (x) => { const srcPath = resolve(__dirname, `../packages/${x}/lib/index.js`) - const distPath = resolve(__dirname, `../build/dist/${x}`) + const distDir = resolve(__dirname, `../build/dist/${x}`) - await mkdir(distPath, { + await mkdir(distDir, { recursive: true, }) - await cp(srcPath, join(distPath, `${x}.js`)) + const filename = `${x.slice(7)}.engine.js` + + const distPath = join(distDir, filename) + + await cp(srcPath, distPath) + + await cp( + distPath, + resolve(__dirname, `../build/dist/llqqntv0/src/${filename}`), + ) + await cp( + distPath, + resolve(__dirname, `../build/dist/llqqntv1/src/${filename}`), + ) }), )