(inputPath, filename)
| 105 | |
| 106 | // 生成多种格式 (with parallel processing) |
| 107 | async function generateMultipleFormats(inputPath, filename) { |
| 108 | const baseName = path.parse(filename).name; |
| 109 | |
| 110 | // Check file size threshold |
| 111 | const fileStats = await stat(inputPath); |
| 112 | if (fileStats.size < config.minFileSize) { |
| 113 | BuildLogger.log(`⏭️ 跳过小文件: ${filename} (${fileStats.size} bytes)`); |
| 114 | return []; |
| 115 | } |
| 116 | |
| 117 | // Generate formats in parallel |
| 118 | const formatPromises = []; |
| 119 | |
| 120 | // Generate JPEG version |
| 121 | const jpegPath = path.join(config.outputDir, `${baseName}.jpg`); |
| 122 | formatPromises.push(optimizeImage(inputPath, jpegPath, 'jpeg')); |
| 123 | |
| 124 | // Generate WebP version |
| 125 | const webpPath = path.join(config.outputDir, `${baseName}.webp`); |
| 126 | formatPromises.push(optimizeImage(inputPath, webpPath, 'webp')); |
| 127 | |
| 128 | // Generate PNG version (if original is PNG) |
| 129 | if (path.extname(filename).toLowerCase() === '.png') { |
| 130 | const pngPath = path.join(config.outputDir, `${baseName}.png`); |
| 131 | formatPromises.push(optimizeImage(inputPath, pngPath, 'png')); |
| 132 | } |
| 133 | |
| 134 | const results = await Promise.all(formatPromises); |
| 135 | return results; |
| 136 | } |
| 137 | |
| 138 | // 生成缩略图 (with better error recovery) |
| 139 | async function generateThumbnails(inputPath, filename) { |
no test coverage detected