From 8213cd7b3f581e5c66b3c80562cf7c7845eca40e Mon Sep 17 00:00:00 2001 From: Kelly Mears Date: Fri, 20 Oct 2023 13:51:02 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20improve(minor):=20bud=20dev=20d?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../@roots/bud-dashboard/src/application.tsx | 82 +++++++++++++------ .../bud-dashboard/src/components/help.tsx | 13 +++ 2 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 sources/@roots/bud-dashboard/src/components/help.tsx diff --git a/sources/@roots/bud-dashboard/src/application.tsx b/sources/@roots/bud-dashboard/src/application.tsx index d5da66f752..5a5d1d0220 100644 --- a/sources/@roots/bud-dashboard/src/application.tsx +++ b/sources/@roots/bud-dashboard/src/application.tsx @@ -16,6 +16,9 @@ import { useState, useStdout, } from '@roots/bud-support/ink' +import escapes from '@roots/bud-support/ansi-escapes' +import {isFunction} from 'lodash' +import Help from './components/help.js' export interface Props { basedir?: string @@ -168,37 +171,58 @@ export const TeletypeApplication = ({ ...props }: PropsWithChildren) => { const app = useApp() + const stdout = useStdout() + const [closed, setClosed] = useState(false) + const [compact, setCompact] = useState(props.compact) + const [debug, setDisplayDebug] = useState(props.debug) + const [displayAssets, setDisplayAssets] = useState(props.displayAssets) + const [displayEntrypoints, setDisplayEntrypoints] = useState(true) const [displayServerInfo, setDisplayServerInfo] = useState( props.displayServerInfo, ) - const [debug, setDisplayDebug] = useState(props.debug) - const [displayEntrypoints, setDisplayEntrypoints] = useState(true) - const [displayAssets, setDisplayAssets] = useState(props.displayAssets) - const [closed, setClosed] = useState(false) - const [compact, setCompact] = useState(props.compact) + const [help, setHelp] = useState(false) const [isolated, setIsolated] = useState(0) + const [refresh, setRefresh] = useState(false) useInput((key, input) => { switch (key) { case `a`: setDisplayAssets(!displayAssets) break + + case `c`: + setCompact(!compact) + break + case `e`: setDisplayEntrypoints(!displayEntrypoints) break + case `d`: setDisplayDebug(!debug) break + + case `h`: + setHelp(!help) + break + + case `q`: + setClosed(true) + break + + case `r`: + setRefresh(true) + break + case `s`: setDisplayServerInfo(!displayServerInfo) break - case `c`: - setCompact(!compact) - break + case `0`: setIsolated(0) break + default: break } @@ -212,26 +236,36 @@ export const TeletypeApplication = ({ if (input.escape) { setClosed(true) - if (close) - close((error?) => { - if (error) app.exit(error) - else app.exit() + } - exit(error ? 1 : 0) - }) + if (refresh) { + setRefresh(false) + stdout.write(escapes.clearTerminal) } + + closed && + isFunction(close) && + close((error?) => { + if (error) app.exit(error) + else app.exit() + exit(error ? 1 : 0) + }) }) return ( - + <> + + + {help && } + ) } diff --git a/sources/@roots/bud-dashboard/src/components/help.tsx b/sources/@roots/bud-dashboard/src/components/help.tsx new file mode 100644 index 0000000000..c7a266a470 --- /dev/null +++ b/sources/@roots/bud-dashboard/src/components/help.tsx @@ -0,0 +1,13 @@ +import {Box, Text} from '@roots/bud-support/ink' + +export interface Props {} + +const Help = ({}: Props) => { + return ( + + Help + + ) +} + +export default Help From 00f37461ff5a6cb7f6bfe24bdc3531388fe61943 Mon Sep 17 00:00:00 2001 From: Kelly Mears Date: Sun, 22 Oct 2023 06:58:30 -0400 Subject: [PATCH 2/2] --- .../@roots/bud-compiler/src/service/index.tsx | 44 ++--- .../@roots/bud-dashboard/src/application.tsx | 71 ++++---- .../bud-dashboard/src/components/footer.tsx | 70 ++++++++ .../bud-dashboard/src/components/help.tsx | 13 -- sources/@roots/bud-dashboard/src/service.tsx | 158 +++--------------- .../@roots/bud-dashboard/src/views/server.tsx | 2 +- .../bud-dashboard/test/service.test.tsx | 8 - sources/@roots/bud-framework/src/context.ts | 5 + sources/@roots/bud-framework/src/notifier.ts | 8 - .../bud-framework/src/registry/events.ts | 4 +- .../src/services/compiler/index.ts | 8 +- .../src/services/dashboard/index.ts | 62 +------ .../test/stylelintrc-no-extension.test.ts | 2 +- sources/@roots/bud-support/src/ink/index.ts | 1 + .../cli/commands/build/development/index.tsx | 4 +- .../bud/src/cli/commands/clean/index.tsx | 14 +- .../bud/src/cli/commands/config/index.tsx | 4 +- .../bud/src/cli/commands/doctor/index.tsx | 30 ++-- .../@roots/bud/src/cli/commands/env/index.tsx | 2 +- sources/@roots/bud/src/cli/commands/index.tsx | 68 ++++---- .../bud/src/cli/commands/view/index.tsx | 2 +- sources/@roots/bud/src/context/index.ts | 2 + 22 files changed, 232 insertions(+), 350 deletions(-) create mode 100644 sources/@roots/bud-dashboard/src/components/footer.tsx delete mode 100644 sources/@roots/bud-dashboard/src/components/help.tsx diff --git a/sources/@roots/bud-compiler/src/service/index.tsx b/sources/@roots/bud-compiler/src/service/index.tsx index dea9114764..6db984b83b 100644 --- a/sources/@roots/bud-compiler/src/service/index.tsx +++ b/sources/@roots/bud-compiler/src/service/index.tsx @@ -21,7 +21,6 @@ import {Error as DisplayError} from '@roots/bud-dashboard/components/error' import {Service} from '@roots/bud-framework/service' import {bind} from '@roots/bud-support/decorators/bind' import {BudError} from '@roots/bud-support/errors' -import {render} from '@roots/bud-support/ink' import isNull from '@roots/bud-support/lodash/isNull' import isNumber from '@roots/bud-support/lodash/isNumber' import isString from '@roots/bud-support/lodash/isString' @@ -31,11 +30,6 @@ import stripAnsi from '@roots/bud-support/strip-ansi' * {@link BudCompiler} implementation */ class Compiler extends Service implements BudCompiler { - /** - * {@link BudCompiler.compilationStats} - */ - public declare compilationStats: BudCompiler[`compilationStats`] - /** * {@link BudCompiler.config} */ @@ -73,9 +67,11 @@ class Compiler extends Service implements BudCompiler { }) if (`isBudError` in error) { - render() + this.app.context.render() } else { - render() + this.app.context.render( + , + ) } } /** @@ -88,26 +84,21 @@ class Compiler extends Service implements BudCompiler { ? `${this.app.label} (${child.name})` : child.name - this.stats = stats - - this.compilationStats = stats.toJson(statsOptions) - - this.app.dashboard.updateStats(this.compilationStats) + this.stats = stats.toJson(statsOptions) + this.app.context.render(this.app.dashboard.render(stats)) if (stats.hasErrors()) { process.exitCode = 1 - this.compilationStats.children = this.compilationStats.children?.map( - child => ({ - ...child, - errors: - child.errors && this.sourceErrors - ? this.sourceErrors(child.errors) - : child.errors ?? [], - }), - ) + this.stats.children = this.stats.children?.map(child => ({ + ...child, + errors: + child.errors && this.sourceErrors + ? this.sourceErrors(child.errors) + : child.errors ?? [], + })) - this.compilationStats.children + this.stats.children ?.filter( child => isNumber(child.errorsCount) && child.errorsCount > 0, ) @@ -131,7 +122,7 @@ class Compiler extends Service implements BudCompiler { }) } - this.compilationStats.children + this.stats.children ?.filter(child => child.errorsCount === 0) .forEach(child => { try { @@ -146,6 +137,7 @@ class Compiler extends Service implements BudCompiler { }) this.app.server?.publicUrl.href && + this.app.context.browser && this.app.notifier.openBrowser(this.app.server?.publicUrl.href) } catch (error) { this.logger.error(error) @@ -224,8 +216,8 @@ class Compiler extends Service implements BudCompiler { * In a perfect world webpack plugins would use the * `nameForCondition` property to identify the module. */ - if (ident && this.compilationStats?.children) { - module = this.compilationStats.children + if (ident && this.stats?.children) { + module = this.stats.children .flatMap(child => child?.modules) .find(module => [module?.id, module?.name].includes(ident)) } diff --git a/sources/@roots/bud-dashboard/src/application.tsx b/sources/@roots/bud-dashboard/src/application.tsx index 5a5d1d0220..5f6b316f7a 100644 --- a/sources/@roots/bud-dashboard/src/application.tsx +++ b/sources/@roots/bud-dashboard/src/application.tsx @@ -4,6 +4,7 @@ import type {StatsCompilation} from '@roots/bud-framework/config' import {exit} from 'node:process' import {Error} from '@roots/bud-dashboard/components/error' +import Footer from '@roots/bud-dashboard/components/footer' import Compilation from '@roots/bud-dashboard/views/compilation' import Debug from '@roots/bud-dashboard/views/debug' import Server from '@roots/bud-dashboard/views/server' @@ -17,13 +18,10 @@ import { useStdout, } from '@roots/bud-support/ink' import escapes from '@roots/bud-support/ansi-escapes' -import {isFunction} from 'lodash' -import Help from './components/help.js' export interface Props { basedir?: string - close?: (callback: (error?: Error | null) => any) => void - closed?: boolean + close?: (callback: (error?: Error | null) => any) => any compact?: boolean compilations?: Array> debug?: boolean @@ -35,11 +33,12 @@ export interface Props { errors?: StatsCompilation[`errors`] isolated?: number mode: Bud['mode'] + notifier?: Bud[`notifier`] proxy?: boolean proxyUrl?: URL publicDevUrl?: URL publicProxyUrl?: URL - status?: false | string + displayHelp?: boolean warnings?: StatsCompilation[`warnings`] } @@ -59,7 +58,7 @@ export const Application = ({ proxyUrl, publicDevUrl, publicProxyUrl, - status, + displayHelp, }: Props) => { const {stdout} = useStdout() @@ -99,6 +98,7 @@ export const Application = ({ return ( <> {error && } + {compilations.map((compilation, id) => ( ) => { - const app = useApp() + const onExit = useOnExit() const stdout = useStdout() - const [closed, setClosed] = useState(false) const [compact, setCompact] = useState(props.compact) const [debug, setDisplayDebug] = useState(props.debug) const [displayAssets, setDisplayAssets] = useState(props.displayAssets) @@ -183,7 +183,6 @@ export const TeletypeApplication = ({ ) const [help, setHelp] = useState(false) const [isolated, setIsolated] = useState(0) - const [refresh, setRefresh] = useState(false) useInput((key, input) => { switch (key) { @@ -191,28 +190,35 @@ export const TeletypeApplication = ({ setDisplayAssets(!displayAssets) break - case `c`: - setCompact(!compact) + case `b`: + if (notifier?.openBrowser && props.devUrl) { + notifier.openBrowser(props.devUrl?.toString()) + notifier.browserOpened = false + } break - case `e`: - setDisplayEntrypoints(!displayEntrypoints) + case `c`: + setCompact(!compact) break case `d`: setDisplayDebug(!debug) break + case `e`: + setDisplayEntrypoints(!displayEntrypoints) + break + case `h`: setHelp(!help) break case `q`: - setClosed(true) + onExit() break case `r`: - setRefresh(true) + stdout.write(escapes.clearTerminal) break case `s`: @@ -222,41 +228,23 @@ export const TeletypeApplication = ({ case `0`: setIsolated(0) break - - default: - break } new Array(9).fill(0).forEach((_, i) => { if (!props.compilations) return + key === `${i + 1}` && isolated !== i + 1 && setIsolated(Math.min(i + 1, props.compilations.length)) }) - if (input.escape) { - setClosed(true) - } - - if (refresh) { - setRefresh(false) - stdout.write(escapes.clearTerminal) - } - - closed && - isFunction(close) && - close((error?) => { - if (error) app.exit(error) - else app.exit() - exit(error ? 1 : 0) - }) + if (input.escape) onExit() }) return ( <> - - {help && } +