mirror of
https://github.com/Silentely/eSIM-Tools.git
synced 2026-09-03 06:24:20 +08:00
- 新增统一的中间件模块,提供鉴权、CORS和错误处理功能 - 重构所有Functions使用withAuth中间件简化代码结构 - 添加安全存储模块替代localStorage,防御XSS攻击 - 引入HTML清理工具,自动转义特殊字符和验证URL安全性 - 创建代码质量检查脚本,验证语法、环境变量和依赖完整性 - 添加构建日志工具和重构脚本,统一替换console.log为Logger - 引入ESLint配置,提升代码质量和一致性 - 重构Giffgaff相关API,统一错误处理和验证逻辑 - 优化构建脚本,添加压缩和图片优化功能 - 新增健康检查端点,用于服务监控和状态报告
91 lines
1.9 KiB
JavaScript
91 lines
1.9 KiB
JavaScript
/**
|
|
* 构建脚本日志工具
|
|
* 为构建/部署脚本提供统一的日志输出
|
|
* 注: 构建脚本始终需要输出信息,因此不像前端Logger那样禁用
|
|
*/
|
|
|
|
// ANSI颜色码
|
|
const colors = {
|
|
reset: '\x1b[0m',
|
|
bold: '\x1b[1m',
|
|
dim: '\x1b[2m',
|
|
red: '\x1b[31m',
|
|
green: '\x1b[32m',
|
|
yellow: '\x1b[33m',
|
|
blue: '\x1b[34m',
|
|
cyan: '\x1b[36m',
|
|
gray: '\x1b[90m'
|
|
};
|
|
|
|
class BuildLogger {
|
|
/**
|
|
* 信息日志 (蓝色)
|
|
*/
|
|
static log(...args) {
|
|
console.log(colors.blue + '[INFO]' + colors.reset, ...args);
|
|
}
|
|
|
|
/**
|
|
* 成功日志 (绿色)
|
|
*/
|
|
static success(...args) {
|
|
console.log(colors.green + '[SUCCESS]' + colors.reset, ...args);
|
|
}
|
|
|
|
/**
|
|
* 警告日志 (黄色)
|
|
*/
|
|
static warn(...args) {
|
|
console.warn(colors.yellow + '[WARN]' + colors.reset, ...args);
|
|
}
|
|
|
|
/**
|
|
* 错误日志 (红色)
|
|
*/
|
|
static error(...args) {
|
|
console.error(colors.red + '[ERROR]' + colors.reset, ...args);
|
|
}
|
|
|
|
/**
|
|
* 调试日志 (灰色)
|
|
*/
|
|
static debug(...args) {
|
|
if (process.env.DEBUG || process.env.VERBOSE) {
|
|
console.log(colors.gray + '[DEBUG]' + colors.reset, ...args);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 标题日志 (粗体青色)
|
|
*/
|
|
static title(text) {
|
|
console.log('\n' + colors.bold + colors.cyan + text + colors.reset);
|
|
console.log(colors.cyan + '='.repeat(text.length) + colors.reset);
|
|
}
|
|
|
|
/**
|
|
* 进度信息 (无标签)
|
|
*/
|
|
static progress(...args) {
|
|
console.log(' ', ...args);
|
|
}
|
|
|
|
/**
|
|
* 检查项 (带emoji)
|
|
*/
|
|
static check(passed, message) {
|
|
const icon = passed ? '✅' : '❌';
|
|
const color = passed ? colors.green : colors.red;
|
|
console.log(icon, color + message + colors.reset);
|
|
}
|
|
|
|
/**
|
|
* 步骤开始
|
|
*/
|
|
static step(number, total, message) {
|
|
console.log(colors.cyan + `\n[${number}/${total}]` + colors.reset, colors.bold + message + colors.reset);
|
|
}
|
|
}
|
|
|
|
module.exports = BuildLogger;
|