mtcute/packages/bun/src/platform.ts

33 lines
946 B
TypeScript
Raw Normal View History

2024-11-26 20:21:47 +03:00
import type { ICorePlatform } from '@mtcute/core'
import * as os from 'node:os'
2024-11-26 20:21:47 +03:00
import { beforeExit } from './utils/exit-hook.js'
import { defaultLoggingHandler } from './utils/logging.js'
import { normalizeFile } from './utils/normalize-file.js'
2024-04-24 13:22:16 +03:00
2024-11-26 20:21:47 +03:00
export class BunPlatform implements ICorePlatform {
// ICorePlatform
declare log: typeof defaultLoggingHandler
declare beforeExit: typeof beforeExit
2024-04-24 13:22:16 +03:00
declare normalizeFile: typeof normalizeFile
2024-04-28 22:41:28 +03:00
getDeviceModel(): string {
2024-06-23 20:43:32 +03:00
return `Bun/${Bun.version} (${os.type()} ${os.arch()})`
2024-04-28 22:41:28 +03:00
}
2024-11-26 20:21:47 +03:00
getDefaultLogLevel(): number | null {
const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? '')
if (!Number.isNaN(envLogLevel)) {
return envLogLevel
}
return null
}
2024-04-24 13:22:16 +03:00
}
BunPlatform.prototype.normalizeFile = normalizeFile
2024-11-26 20:21:47 +03:00
BunPlatform.prototype.log = defaultLoggingHandler
BunPlatform.prototype.beforeExit = beforeExit