feat(shell): filter out invalid engine

This commit is contained in:
Il Harper 2024-03-06 12:36:41 +08:00
parent 0277077fbf
commit 1ec90d1dfd
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC

View File

@ -24,6 +24,13 @@ export * from './types'
declare const __DEFINE_CHRONO_VERSION__: string
interface EngineInfo {
name: string
filename: string
type: string
path: string
}
export const chronocat = async () => {
l.info(`Chronocat v${__DEFINE_CHRONO_VERSION__}`)
@ -59,14 +66,24 @@ export const chronocat = async () => {
recursive: true,
})
const engines = readdirSync(enginesPath).map((filename) => {
const engines = readdirSync(enginesPath)
.map((filename) => {
let valid = false
let name = filename
let type = 'js'
if (name.endsWith('.jsc')) {
valid = true
name = name.slice(0, name.length - 4)
type = 'jsc'
}
if (name.endsWith('.js')) name = name.slice(0, name.length - 3)
if (name.endsWith('.js')) {
valid = true
name = name.slice(0, name.length - 3)
}
if (!valid) return undefined
return {
name,
@ -75,6 +92,9 @@ export const chronocat = async () => {
path: join(enginesPath, filename),
}
})
.filter(
Boolean as unknown as (x: EngineInfo | undefined) => x is EngineInfo,
)
if (!engines.length)
l.warn('没有找到任何引擎。Chronocat 服务仍将启动。', { code: 2156 })