UNPKG

wxt

Version:

⚡ Next-gen Web Extension Framework

44 lines (43 loc) 1.52 kB
import { wxt } from "../../wxt.mjs"; import { printTable } from "./printTable.mjs"; import { lstat } from "node:fs/promises"; import path from "node:path"; import { styleText } from "node:util"; import { filesize } from "filesize"; //#region src/core/utils/log/printFileList.ts async function printFileList(log, header, baseDir, files) { let totalSize = 0; const fileRows = await Promise.all(files.map(async (file, i) => { const parts = [path.relative(process.cwd(), baseDir) + path.sep, path.relative(baseDir, file)]; const prefix = i === files.length - 1 ? " └─" : " ├─"; const chunkColor = getChunkColor(file); let size = ""; try { const stats = await lstat(file); totalSize += stats.size; size = String(filesize(stats.size)); } catch (ex) { wxt.logger.warn(`Could not get stats of '${file}' error: ${ex}`); } return [`${styleText("gray", prefix)} ${styleText("dim", parts[0])}${styleText(chunkColor, parts[1])}`, styleText("dim", size)]; })); fileRows.push([`${styleText("cyan", "Σ Total size:")} ${String(filesize(totalSize))}`]); printTable(log, header, fileRows); } const DEFAULT_COLOR = "blue"; const CHUNK_COLORS = { ".js.map": "gray", ".cjs.map": "gray", ".mjs.map": "gray", ".html": "green", ".css": "magenta", ".js": "cyan", ".cjs": "cyan", ".mjs": "cyan", ".zip": "yellow" }; function getChunkColor(filename) { return Object.entries(CHUNK_COLORS).find(([key]) => filename.endsWith(key))?.[1] ?? DEFAULT_COLOR; } //#endregion export { printFileList };