mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-19 01:03:58 +00:00
chore: apply code fixes with biome
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
import type { Logger } from './logger.js'
|
||||
|
||||
export default function checkEnv(logger: Logger) {
|
||||
if (!process.env['NODE_ENV'])
|
||||
logger.warn('NODE_ENV not set, defaulting to `development`')
|
||||
const environment = (process.env['NODE_ENV'] ??
|
||||
'development') as NodeEnvironment
|
||||
|
||||
if (!['development', 'production'].includes(environment)) {
|
||||
logger.error(
|
||||
'NODE_ENV is neither `development` nor `production`, unable to determine environment'
|
||||
)
|
||||
logger.info('Set NODE_ENV to blank to use `development` mode')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
logger.info(`Running in ${environment} mode...`)
|
||||
|
||||
if (environment === 'production' && process.env['IS_USING_DOT_ENV']) {
|
||||
logger.warn(
|
||||
'You seem to be using .env files, this is generally not a good idea in production...'
|
||||
)
|
||||
}
|
||||
|
||||
if (!process.env['WIT_AI_TOKEN']) {
|
||||
logger.error('WIT_AI_TOKEN is not defined in the environment variables')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
return environment
|
||||
}
|
||||
import type { Logger } from './logger.js'
|
||||
|
||||
export default function checkEnv(logger: Logger) {
|
||||
if (!process.env['NODE_ENV'])
|
||||
logger.warn('NODE_ENV not set, defaulting to `development`')
|
||||
const environment = (process.env['NODE_ENV'] ??
|
||||
'development') as NodeEnvironment
|
||||
|
||||
if (!['development', 'production'].includes(environment)) {
|
||||
logger.error(
|
||||
'NODE_ENV is neither `development` nor `production`, unable to determine environment',
|
||||
)
|
||||
logger.info('Set NODE_ENV to blank to use `development` mode')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
logger.info(`Running in ${environment} mode...`)
|
||||
|
||||
if (environment === 'production' && process.env['IS_USING_DOT_ENV']) {
|
||||
logger.warn(
|
||||
'You seem to be using .env files, this is generally not a good idea in production...',
|
||||
)
|
||||
}
|
||||
|
||||
if (!process.env['WIT_AI_TOKEN']) {
|
||||
logger.error('WIT_AI_TOKEN is not defined in the environment variables')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
return environment
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import { resolve as resolvePath } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
const configPath = resolvePath(process.cwd(), 'config.json')
|
||||
|
||||
const userConfig: Partial<Config> = existsSync(configPath)
|
||||
? (
|
||||
await import(pathToFileURL(configPath).href, {
|
||||
assert: {
|
||||
type: 'json',
|
||||
},
|
||||
})
|
||||
).default
|
||||
: {}
|
||||
|
||||
type BaseTypeOf<T> = T extends (infer U)[]
|
||||
? U[]
|
||||
: T extends (...args: unknown[]) => infer U
|
||||
? (...args: unknown[]) => U
|
||||
: T extends object
|
||||
? { [K in keyof T]: T[K] }
|
||||
: T
|
||||
|
||||
export type Config = Omit<
|
||||
BaseTypeOf<typeof import('../../config.json')>,
|
||||
'$schema'
|
||||
>
|
||||
|
||||
export const defaultConfig: Config = {
|
||||
address: '127.0.0.1',
|
||||
port: 80,
|
||||
ocrConcurrentQueues: 1,
|
||||
clientHeartbeatInterval: 60000,
|
||||
debugLogsInProduction: false,
|
||||
}
|
||||
|
||||
export default function getConfig() {
|
||||
return Object.assign(defaultConfig, userConfig) satisfies Config
|
||||
}
|
||||
import { existsSync } from 'node:fs'
|
||||
import { resolve as resolvePath } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
|
||||
const configPath = resolvePath(process.cwd(), 'config.json')
|
||||
|
||||
const userConfig: Partial<Config> = existsSync(configPath)
|
||||
? (
|
||||
await import(pathToFileURL(configPath).href, {
|
||||
assert: {
|
||||
type: 'json',
|
||||
},
|
||||
})
|
||||
).default
|
||||
: {}
|
||||
|
||||
type BaseTypeOf<T> = T extends (infer U)[]
|
||||
? U[]
|
||||
: T extends (...args: unknown[]) => infer U
|
||||
? (...args: unknown[]) => U
|
||||
: T extends object
|
||||
? { [K in keyof T]: T[K] }
|
||||
: T
|
||||
|
||||
export type Config = Omit<
|
||||
BaseTypeOf<typeof import('../../config.json')>,
|
||||
'$schema'
|
||||
>
|
||||
|
||||
export const defaultConfig: Config = {
|
||||
address: '127.0.0.1',
|
||||
port: 80,
|
||||
ocrConcurrentQueues: 1,
|
||||
clientHeartbeatInterval: 60000,
|
||||
debugLogsInProduction: false,
|
||||
}
|
||||
|
||||
export default function getConfig() {
|
||||
return Object.assign(defaultConfig, userConfig) satisfies Config
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { default as getConfig } from './getConfig.js'
|
||||
export { default as checkEnv } from './checkEnv.js'
|
||||
export { default as logger } from './logger.js'
|
||||
export { default as getConfig } from './getConfig.js'
|
||||
export { default as checkEnv } from './checkEnv.js'
|
||||
export { default as logger } from './logger.js'
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import { Chalk } from 'chalk'
|
||||
|
||||
const chalk = new Chalk()
|
||||
const logger = {
|
||||
debug: (...args) => console.debug(chalk.gray('DEBUG:', ...args)),
|
||||
info: (...args) =>
|
||||
console.info(chalk.bgBlue.whiteBright(' INFO '), ...args),
|
||||
warn: (...args) =>
|
||||
console.warn(
|
||||
chalk.bgYellow.blackBright.bold(' WARN '),
|
||||
chalk.yellowBright(...args)
|
||||
),
|
||||
error: (...args) =>
|
||||
console.error(
|
||||
chalk.bgRed.whiteBright.bold(' ERROR '),
|
||||
chalk.redBright(...args)
|
||||
),
|
||||
log: console.log,
|
||||
} satisfies Logger
|
||||
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'log'
|
||||
export type LogFunction = (...x: unknown[]) => void
|
||||
export type Logger = Record<LogLevel, LogFunction>
|
||||
|
||||
export default logger
|
||||
import { Chalk } from 'chalk'
|
||||
|
||||
const chalk = new Chalk()
|
||||
const logger = {
|
||||
debug: (...args) => console.debug(chalk.gray('DEBUG:', ...args)),
|
||||
info: (...args) =>
|
||||
console.info(chalk.bgBlue.whiteBright(' INFO '), ...args),
|
||||
warn: (...args) =>
|
||||
console.warn(
|
||||
chalk.bgYellow.blackBright.bold(' WARN '),
|
||||
chalk.yellowBright(...args),
|
||||
),
|
||||
error: (...args) =>
|
||||
console.error(
|
||||
chalk.bgRed.whiteBright.bold(' ERROR '),
|
||||
chalk.redBright(...args),
|
||||
),
|
||||
log: console.log,
|
||||
} satisfies Logger
|
||||
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'log'
|
||||
export type LogFunction = (...x: unknown[]) => void
|
||||
export type Logger = Record<LogLevel, LogFunction>
|
||||
|
||||
export default logger
|
||||
|
||||
Reference in New Issue
Block a user