41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import color from "picocolors";
|
|
import { checkToktx, scanImages, compressAll } from "./compressor.js";
|
|
import { runInteractive, showSummary } from "./ui.js";
|
|
|
|
export async function run() {
|
|
// 检查 toktx
|
|
checkToktx();
|
|
|
|
// 运行交互界面
|
|
const result = await runInteractive();
|
|
|
|
// ESC 返回主菜单
|
|
if (!result) return "back";
|
|
|
|
const [exts, quality, encoding, mipmap, outputOpts] = result;
|
|
const config = { exts, quality, encoding, mipmap, outputOpts };
|
|
|
|
// 显示配置摘要
|
|
showSummary(config);
|
|
|
|
// 扫描文件
|
|
const { images, cwd } = scanImages(exts);
|
|
|
|
if (images.length === 0) {
|
|
console.log(color.yellow("当前目录没有匹配的图片"));
|
|
return;
|
|
}
|
|
|
|
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🎉 全部文件压缩完成!"));
|
|
}
|
|
}
|