UNPKG

@roots/bud

Version:

Configurable, extensible build tools for modern single and multi-page web applications

41 lines (40 loc) 1.66 kB
import { jsx as _jsx, jsxs as _jsxs } from "@roots/bud-support/jsx-runtime"; import BudCommand from '@roots/bud/cli/commands'; import indent from '@roots/bud/cli/flags/indent'; import { Command, Option } from '@roots/bud-support/clipanion'; import get from '@roots/bud-support/get'; import { highlight } from '@roots/bud-support/highlight'; import { Box, Text } from '@roots/bud-support/ink'; /** * `bud view` command */ export default class BudViewCommand extends BudCommand { static paths = [[`view`]]; static usage = Command.Usage({ category: `debug`, description: `Explore bud object`, examples: [[`View compiled config`, `$0 view build.config`]], }); indent = indent; subject = Option.String({ name: `subject`, required: false }); async execute() { const format = await import(`@roots/bud-support/pretty-format`).then(module => module.default); await this.makeBud(); await this.bud.run(); let value = this.subject ? get(this.bud, this.subject) : this.bud; let indent = 0; switch (this.indent) { case undefined: indent = 2; break; default: indent = parseInt(this.indent); } value = format(this.subject ? get(this.bud, this.subject) : this.bud, { indent, }); if (this.color) value = highlight(value); this.renderStatic(_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "magenta", children: this.subject ?? `build.config` }), _jsx(Text, { children: ` ` }), _jsx(Text, { children: value })] })); } }