import View from '@roots/bud-dashboard/components/view' import {Box, Text} from '@roots/bud-support/ink' type Data = Array | number | Record | string export interface Props { compilation?: Record config?: Record debug?: boolean } export default function Debug({compilation, debug}: Props) { if (!debug) return null if (!compilation) return null const format = (obj: Record) => Object.entries(obj ?? {}) .filter( ([k, v]) => typeof v !== `undefined` && typeof v !== `string` && typeof v !== `number` && v !== null && !(Array.isArray(v) && v.length === 0), ) .map(([k, v]) => [k, typeof v === `function` ? `function` : v]) return ( <> {format(compilation).map(([key, fields], id) => { if (typeof key !== `string`) return null return ( debug config: {`${id + 1}`} /{` `} {`${format(compilation).length}`} } head={stats: {key}} key={id} > ) })} ) } const isPrimitive = (field: unknown): field is number | string => { return typeof field === `string` || typeof field === `number` } const Fields = ({fields}: {fields: unknown}) => { if (fields === undefined) { return undefined } if (typeof fields === `boolean`) { return {`${fields}`} } if (fields === null) { return null } if (Array.isArray(fields) && fields.length === 0) { return [] } if (isPrimitive(fields)) { const preLoaderSplit = `${fields}`.split(`!`).pop() if (!preLoaderSplit) return null return ( {preLoaderSplit.split(`?`).pop()} ) } return Object.entries(fields) .filter(([k, v]) => v !== undefined && v !== null) .map(([key, fields], id) => { if (!fields) return null return ( {typeof key === `string` ? key : `-`}: ) }) }