Skip to content

Commit 6ca46d2

Browse files
committed
fix(preset-cli): Clean up logic to display upgrade checks in console
1 parent a31a7a7 commit 6ca46d2

7 files changed

Lines changed: 831 additions & 831 deletions

File tree

packages/plugin-console/src/components/console-builtin.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,6 @@ export function DividerFunctionDeclaration() {
25272527
<TSDocExample>
25282528
{`divider({ width: 50, border: "primary" }); // Writes a divider line of width 50 with primary border.`}
25292529
</TSDocExample>
2530-
25312530
<TSDocParam name="options">
25322531
{`Options for formatting the divider line.`}
25332532
</TSDocParam>
@@ -2782,14 +2781,9 @@ export function SpinnerFunctionDeclaration() {
27822781
}
27832782
27842783
const streamsToHook = new Set([this.#stream]);
2785-
if (this.#stream === process.stdout || this.#stream === process.stderr) {
2786-
if (isInteractive(process.stdout)) {
2787-
streamsToHook.add(process.stdout);
2788-
}
2789-
2790-
if (isInteractive(process.stderr)) {
2791-
streamsToHook.add(process.stderr);
2792-
}
2784+
if (isInteractive && (this.#stream === process.stdout || this.#stream === process.stderr)) {
2785+
streamsToHook.add(process.stdout);
2786+
streamsToHook.add(process.stderr);
27932787
}
27942788
27952789
for (const stream of streamsToHook) {
@@ -2838,15 +2832,14 @@ export function SpinnerFunctionDeclaration() {
28382832
}
28392833
28402834
#stopWithIcon(icon: string, message: string) {
2841-
return this.stop(\`\${icon} \${message ?? this.#message}\`);
2835+
return this.stop(\` \${icon} \${message ?? this.#message}\`);
28422836
}
28432837
28442838
#render() {
28452839
if (this.#isDeferringRender) {
28462840
return;
28472841
}
28482842
2849-
const useSynchronizedOutput = isInteractive;
28502843
if (this.#currentFrame === -1 || Date.now() - this.#lastSpinnerFrameTime >= this.#interval) {
28512844
this.#currentFrame = ++this.#currentFrame % this.#frames.length;
28522845
this.#lastSpinnerFrameTime = Date.now();
@@ -2857,7 +2850,7 @@ export function SpinnerFunctionDeclaration() {
28572850
display += "\\n";
28582851
}
28592852
2860-
if (useSynchronizedOutput) {
2853+
if (isInteractive) {
28612854
this.#withSynchronizedOutput(() => {
28622855
this.clear();
28632856
this.#write(display);

packages/preset-cli/src/components/banner-function-declaration.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export function BannerFunctionDeclaration(
115115
footer={footer.value}
116116
variant={variant}
117117
consoleFnName={consoleFnName}
118-
command={command}>
118+
command={command}
119+
insertNewlineAfterDescription>
119120
{code`const titleLines = [${titleLines.value
120121
.map(line => JSON.stringify(line.trim()))
121122
.join(", ")}];
@@ -242,7 +243,9 @@ export function BannerFunctionDeclaration(
242243
<ElseClause>{code`spinner.success("Currently running the latest version of ${getAppTitle(
243244
context,
244245
true
245-
)}.");`}</ElseClause>
246+
)}.");
247+
writeLine("");
248+
`}</ElseClause>
246249
</IfStatement>
247250
</Show>
248251
</FunctionDeclaration>

packages/preset-cli/src/components/command-entry.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function CommandEntry(props: CommandEntryProps) {
8585
prompts: "prompts"
8686
})}
8787
builtinImports={defu(builtinImports ?? {}, {
88-
env: ["env", "isDevelopment", "isDebug"],
88+
env: ["env", "isDevelopment", "isDebug", "paths"],
8989
console: [
9090
"debug",
9191
"info",
@@ -96,7 +96,8 @@ export function CommandEntry(props: CommandEntryProps) {
9696
"colors",
9797
"stripAnsi",
9898
"writeLine",
99-
"splitText"
99+
"splitText",
100+
"createSpinner"
100101
],
101102
utils: [
102103
"useApp",

packages/preset-cli/src/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const plugin = <TContext extends CLIPresetContext = CLIPresetContext>(
7878
builtinImports={{
7979
console: [
8080
"info",
81+
"debug",
8182
"warn",
8283
"help",
8384
"error",
@@ -88,7 +89,8 @@ export const plugin = <TContext extends CLIPresetContext = CLIPresetContext>(
8889
"colors",
8990
"writeLine",
9091
"splitText",
91-
"stripAnsi"
92+
"stripAnsi",
93+
"createSpinner"
9294
],
9395
utils: [
9496
"useApp",
@@ -111,7 +113,8 @@ export const plugin = <TContext extends CLIPresetContext = CLIPresetContext>(
111113
"checkForUpdates",
112114
"isCheckForUpdatesRequired",
113115
"upgrade"
114-
]
116+
],
117+
env: ["env", "paths"]
115118
}}
116119
prefix={
117120
<>

packages/preset-script/src/components/banner-function-declaration.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export interface BannerFunctionBodyDeclarationProps extends BannerFunctionDeclar
106106
description: string;
107107
insertNewlineBeforeCommand?: boolean;
108108
insertNewlineBeforeBanner?: boolean;
109+
insertNewlineAfterDescription?: boolean;
109110
}
110111

111112
/**
@@ -127,7 +128,8 @@ export function BannerFunctionBodyDeclaration(
127128
command,
128129
children,
129130
insertNewlineBeforeCommand = false,
130-
insertNewlineBeforeBanner = true
131+
insertNewlineBeforeBanner = true,
132+
insertNewlineAfterDescription = false
131133
} = props;
132134

133135
const theme = useTheme();
@@ -255,7 +257,17 @@ export function BannerFunctionBodyDeclaration(
255257
theme.borderStyles.banner.outline[variant].right
256258
}"), { consoleFn: console.${consoleFnName} });
257259
});
258-
260+
${
261+
insertNewlineAfterDescription
262+
? `writeLine(colors.border.banner.outline.${variant}("${
263+
theme.borderStyles.banner.outline[variant].left
264+
}") + " ".repeat(Math.max(process.stdout.columns - ${
265+
bannerPadding.value
266+
})) + colors.border.banner.outline.${variant}("${
267+
theme.borderStyles.banner.outline[variant].right
268+
}"), { consoleFn: console.${consoleFnName} });`
269+
: ""
270+
}
259271
writeLine(colors.border.banner.outline.${variant}("${
260272
theme.borderStyles.banner.outline[variant].bottomLeft
261273
}") + ${

0 commit comments

Comments
 (0)