Skip to content

Commit 55915c1

Browse files
authored
fix: Fix build UI (#58)
* chore: lib/cli/build/ui.tsx -> lib/cli/build/ui/index.tsx * chore: Create Progress component * fix: Fix build ui * chore: Add tsx to .lntstagedrc.json * chore: Remove BuildUI * chore: Add dist to biome ignore files * chore: Format * chore: Implement success() and use it
1 parent ef67413 commit 55915c1

File tree

7 files changed

+59
-82
lines changed

7 files changed

+59
-82
lines changed

.lintstagedrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"*.{ts,json}": "bunx biome check --write --unsafe --no-errors-on-unmatched"
2+
"*.{ts,tsx,json}": "bunx biome check --write --unsafe --no-errors-on-unmatched"
33
}

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"useIgnoreFile": false
77
},
88
"files": {
9-
"ignoreUnknown": false
9+
"ignoreUnknown": false,
10+
"includes": ["!dist/**"]
1011
},
1112
"formatter": {
1213
"enabled": true,

lib/cli/build/index.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as fs from "node:fs";
22
import { register } from "node:module";
33
import * as path from "node:path";
44
import { pathToFileURL } from "node:url";
5-
import { render } from "ink";
6-
import BuildUI from "./ui";
5+
import { render, Text } from "ink";
6+
import Progress from "../ui/Progress";
7+
import { success } from "../ui/message";
78

89
export async function build(args: string[]) {
910
const ghatsDir = path.resolve(process.cwd(), "node_modules/.ghats");
@@ -33,27 +34,22 @@ export async function build(args: string[]) {
3334
);
3435
}
3536

36-
const { unmount, rerender } = render(
37-
<BuildUI workflowPaths={workflowPaths} currentIndex={0} />
38-
);
37+
const { rerender, unmount } = render(null);
3938
try {
40-
for (
41-
let currentIndex = 0;
42-
currentIndex < workflowPaths.length;
43-
currentIndex++
44-
) {
45-
const workflowPath = workflowPaths[currentIndex];
46-
await _buildWorkflow(workflowPath!);
39+
for (const workflowPath of workflowPaths) {
40+
rerender(
41+
<Progress status="in-progress" title={`Building ${workflowPath}`} />
42+
);
43+
await _buildWorkflow(workflowPath);
4744
rerender(
48-
<BuildUI
49-
workflowPaths={workflowPaths}
50-
currentIndex={currentIndex + 1}
51-
/>
45+
<Progress status="done" title={getBuildTargetPath(workflowPath)} />
5246
);
5347
}
5448
} finally {
5549
unmount();
5650
}
51+
52+
success("All workflows built successfully!");
5753
}
5854

5955
async function _buildWorkflow(workflowPath: string) {

lib/cli/build/ui.tsx

Lines changed: 0 additions & 63 deletions
This file was deleted.

lib/cli/ui/Progress.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Static, Text } from "ink";
2+
import Spinner from "./Spinner";
3+
4+
export type ProgressProps = {
5+
status: "in-progress" | "done";
6+
title: string;
7+
};
8+
9+
export default function Progress({ status, title }: ProgressProps) {
10+
if (status === "in-progress") {
11+
return (
12+
<Text>
13+
<Spinner />
14+
<Text dimColor> {title}</Text>
15+
</Text>
16+
);
17+
}
18+
19+
if (status === "done") {
20+
return (
21+
<Static items={[title]}>
22+
{(title) => (
23+
<Text key={title}>
24+
<Text color="green" bold>
25+
26+
</Text>
27+
<Text bold> {title}</Text>
28+
</Text>
29+
)}
30+
</Static>
31+
);
32+
}
33+
}

lib/cli/ui/Spinner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useEffect, useState } from "react";
21
import { Text } from "ink";
2+
import { useEffect, useState } from "react";
33

44
const spinners = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
55

lib/cli/ui/message.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { render, Text } from "ink";
2+
3+
export function success(message: string) {
4+
const { unmount } = render(
5+
<Text color="green" bold>
6+
{" "}🎉 {message}
7+
</Text>
8+
);
9+
unmount();
10+
}

0 commit comments

Comments
 (0)