This commit is contained in:
yinsx
2025-12-16 15:14:07 +08:00
commit 33910f031f
11 changed files with 476 additions and 0 deletions

35
cli.js Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env node
import color from "picocolors";
import { checkToktx, scanImages, compressAll } from "./lib/compressor.js";
import { runInteractive, showSummary } from "./lib/ui.js";
// 检查 toktx
checkToktx();
// 运行交互界面
const [exts, quality, encoding, mipmap, outputOpts] = await runInteractive();
const config = { exts, quality, encoding, mipmap, outputOpts };
// 显示配置摘要
showSummary(config);
// 扫描文件
const { images, cwd } = scanImages(exts);
if (images.length === 0) {
console.log(color.yellow("当前目录没有匹配的图片"));
process.exit(0);
}
console.log(`📁 找到 ${color.cyan(images.length)} 个待转换文件\n`);
// 执行压缩
const { total, failed } = await compressAll(images, config, cwd);
// 显示结果
if (failed > 0) {
console.log(color.yellow(`\n⚠️ 完成,但有 ${failed} 个文件失败`));
} else {
console.log(color.green("\n🎉 全部文件压缩完成!"));
}