初始化模版工程
This commit is contained in:
6
utils/cn.ts
Normal file
6
utils/cn.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
18
utils/getAuth.ts
Normal file
18
utils/getAuth.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @description 从当前服务里获取到当前登录的userId
|
||||
* @returns userId | undefined
|
||||
*/
|
||||
export async function getUserId() {
|
||||
// 从当前服务里获取到当前登录的userId
|
||||
|
||||
// 默认值是undefined
|
||||
return void 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get ProjectId
|
||||
* @returns projectId | undefined
|
||||
*/
|
||||
export function getProjectId() {
|
||||
return process.env.PROJECT_ID ?? void 0;
|
||||
}
|
||||
35
utils/logger.ts
Normal file
35
utils/logger.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { createLogger, format, transports } from 'winston'
|
||||
import DailyRotateFile from 'winston-daily-rotate-file'
|
||||
|
||||
const isDev = process.env.NODE_ENV !== 'production'
|
||||
|
||||
const logsDir = process.env.LOG_DIR || path.join(process.cwd(), 'logs')
|
||||
|
||||
if (!isDev) {
|
||||
fs.mkdirSync(logsDir, { recursive: true })
|
||||
}
|
||||
|
||||
const outputTransport = isDev
|
||||
? new transports.Console()
|
||||
: new DailyRotateFile({
|
||||
dirname: logsDir,
|
||||
filename: 'app-%DATE%.log',
|
||||
datePattern: 'YYYY-MM-DD',
|
||||
zippedArchive: false,
|
||||
})
|
||||
|
||||
export const logger = createLogger({
|
||||
level: isDev ? 'debug' : 'info',
|
||||
format: format.combine(
|
||||
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
||||
format.errors({ stack: true }),
|
||||
format.printf(({ timestamp, level, message, stack, ...meta }) => {
|
||||
const metaText = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : ''
|
||||
const base = `[${timestamp}] ${level}: ${message}${metaText}`
|
||||
return stack ? `${base}\n${stack}` : base
|
||||
})
|
||||
),
|
||||
transports: [outputTransport],
|
||||
})
|
||||
Reference in New Issue
Block a user