UNPKG

kirbyup

Version:

Zero-config bundler for Kirby Panel plugins

26 lines (24 loc) 1.09 kB
import { consola } from "consola"; import { colors } from "consola/utils"; import { normalize, relative, resolve } from "pathe"; import { Buffer } from "node:buffer"; import { promisify } from "node:util"; import { gzip } from "node:zlib"; //#region src/node/utils.ts const compress = promisify(gzip); function toArray(array) { array ??= []; return Array.isArray(array) ? array : [array]; } async function getCompressedSize(code) { return ` / gzip: ${((await compress(typeof code === "string" ? code : Buffer.from(code))).length / 1024).toFixed(2)} KiB`; } async function printFileInfo({ root, outDir, filePath, content, type, maxLength }) { const prettyOutDir = `${normalize(relative(root, resolve(root, outDir)))}/`; const kibs = content.length / 1024; const compressedSize = await getCompressedSize(content); const writeColor = type === "chunk" ? colors.cyan : colors.magenta; consola.log(colors.white(colors.dim(prettyOutDir)) + writeColor(filePath.padEnd(maxLength + 2)) + colors.dim(`${kibs.toFixed(2)} kB${compressedSize}`)); } //#endregion export { printFileInfo, toArray };