Skip to content

Commit 314769d

Browse files
committed
refactor(ui): simplify scripts with Bun native APIs
- Replace execa/globby with Bun.spawn and Bun.Glob - Rename scripts to remove redundant ui- prefix - Use import.meta.dirname instead of fileURLToPath - Switch root scripts from --filter to --cwd for cleaner output
1 parent 059d420 commit 314769d

File tree

11 files changed

+91
-89
lines changed

11 files changed

+91
-89
lines changed

bun.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@
217217
"devDependencies": {
218218
"@types/react": "^19.2.7",
219219
"@types/react-dom": "^19.2.3",
220-
"execa": "^9.6.1",
221-
"globby": "^16.0.0",
222220
"tailwindcss": "^4.1.17",
223221
"typescript": "~5.9.3",
224222
},

docs/ui-components.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ This installs 37 components including:
9999

100100
Components are organized in the `packages/ui` workspace:
101101

102-
```
102+
```bash
103103
packages/ui/
104-
├── components/ # Component files
104+
├── components/ # Component files
105105
│ ├── ui/ # shadcn/ui components
106106
│ │ ├── button.tsx
107107
│ │ ├── card.tsx
@@ -110,10 +110,10 @@ packages/ui/
110110
├── lib/
111111
│ └── utils.ts # Shared utilities (cn function)
112112
├── scripts/ # Management scripts
113-
│ ├── ui-add.ts # Add components
114-
│ ├── ui-list.ts # List components
115-
│ ├── ui-update.ts # Update components
116-
│ └── ui-essentials.ts # Install essentials
113+
│ ├── add.ts # Add components
114+
│ ├── list.ts # List components
115+
│ ├── update.ts # Update components
116+
│ └── essentials.ts # Install essentials
117117
└── package.json
118118
```
119119

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
"api:build:docker": "docker build --tag api:latest -f ./apps/api/Dockerfile .",
4040
"api:test": "bun --filter @repo/api test",
4141
"api:deploy": "bun --filter @repo/api deploy",
42-
"ui:add": "bun --filter @repo/ui ui:add",
43-
"ui:list": "bun --filter @repo/ui ui:list",
44-
"ui:update": "bun --filter @repo/ui ui:update",
45-
"ui:essentials": "bun --filter @repo/ui ui:essentials",
42+
"ui:add": "bun --cwd packages/ui add",
43+
"ui:list": "bun --cwd packages/ui list",
44+
"ui:update": "bun --cwd packages/ui update",
45+
"ui:essentials": "bun --cwd packages/ui essentials",
4646
"email:dev": "bun --filter @repo/email dev",
4747
"email:build": "bun --filter @repo/email build",
4848
"email:export": "bun --filter @repo/email export"

packages/ui/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,25 @@ Consuming apps **must** include UI package paths in their Tailwind CSS v4 config
175175

176176
```bash
177177
# From project root
178-
bun run ui:add button # Add a single component
179-
bun run ui:add button card # Add multiple components
180-
bun run ui:essentials # Install curated essential components (37 components)
178+
bun ui:add button # Add a single component
179+
bun ui:add button card # Add multiple components
180+
bun ui:essentials # Install curated essential components
181181

182182
# From packages/ui directory
183-
bun run ui:add dialog
183+
bun run add dialog
184184
```
185185

186186
### Listing Components
187187

188188
```bash
189-
bun run ui:list # Show all installed components with metadata
189+
bun ui:list # Show all installed components with metadata
190190
```
191191

192192
### Updating Components
193193

194194
```bash
195-
bun run ui:update # Update all components to latest versions
196-
bun run ui:update button # Update specific component
195+
bun ui:update # Update all components to latest versions
196+
bun ui:update button # Update specific component
197197
```
198198

199199
### Essential Components
@@ -207,8 +207,8 @@ The `ui:essentials` script installs a curated set of 37 components perfect for m
207207
- **Data Display**: avatar, tooltip, popover
208208

209209
```bash
210-
bun run ui:essentials --list # Preview components without installing
211-
bun run ui:essentials # Install all essential components
210+
bun ui:essentials --list # Preview components without installing
211+
bun ui:essentials # Install all essential components
212212
```
213213

214214
All scripts include:

packages/ui/components/checkbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const Checkbox = React.forwardRef<
1111
<CheckboxPrimitive.Root
1212
ref={ref}
1313
className={cn(
14-
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
14+
"grid place-content-center peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
1515
className,
1616
)}
1717
{...props}
1818
>
1919
<CheckboxPrimitive.Indicator
20-
className={cn("flex items-center justify-center text-current")}
20+
className={cn("grid place-content-center text-current")}
2121
>
2222
<Check className="h-4 w-4" />
2323
</CheckboxPrimitive.Indicator>

packages/ui/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
"dev": "tsc --watch",
2525
"lint": "eslint . --max-warnings 0",
2626
"type-check": "tsc --noEmit",
27-
"ui:list": "bun scripts/ui-list.ts",
28-
"ui:update": "bun scripts/ui-update.ts",
29-
"ui:add": "bun scripts/ui-add.ts",
30-
"ui:essentials": "bun scripts/ui-essentials.ts"
27+
"add": "bun scripts/add.ts",
28+
"list": "bun scripts/list.ts",
29+
"update": "bun scripts/update.ts",
30+
"essentials": "bun scripts/essentials.ts"
3131
},
3232
"peerDependencies": {
3333
"react": ">=19.2.1",
@@ -52,8 +52,6 @@
5252
"devDependencies": {
5353
"@types/react": "^19.2.7",
5454
"@types/react-dom": "^19.2.3",
55-
"execa": "^9.6.1",
56-
"globby": "^16.0.0",
5755
"tailwindcss": "^4.1.17",
5856
"typescript": "~5.9.3"
5957
},
File renamed without changes.
File renamed without changes.

packages/ui/scripts/format-utils.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
#!/usr/bin/env bun
22

3-
import { dirname, join } from "node:path";
4-
import { fileURLToPath } from "node:url";
5-
import { execa } from "execa";
6-
import { globby } from "globby";
3+
import { join } from "node:path";
4+
import { Glob } from "bun";
75

86
/**
9-
* Execute a command using execa with proper error handling
7+
* Execute a command with inherited stdio
108
*/
119
export async function execCommand(
1210
command: string,
1311
args: string[],
1412
): Promise<void> {
15-
try {
16-
await execa(command, args, {
17-
stdio: "inherit",
18-
});
19-
} catch (error) {
20-
const message = error instanceof Error ? error.message : String(error);
21-
throw new Error(
22-
`Command failed: ${command} ${args.join(" ")} - ${message}`,
23-
);
13+
const proc = Bun.spawn([command, ...args], {
14+
stdio: ["inherit", "inherit", "inherit"],
15+
});
16+
17+
const exitCode = await proc.exited;
18+
if (exitCode !== 0) {
19+
throw new Error(`Command failed: ${command} ${args.join(" ")}`);
2420
}
2521
}
2622

@@ -29,23 +25,25 @@ export async function execCommand(
2925
*/
3026
export async function formatGeneratedFiles(): Promise<void> {
3127
try {
32-
const __dirname = dirname(fileURLToPath(import.meta.url));
33-
const componentFiles = await globby(
34-
join(__dirname, "../components/**/*.{ts,tsx}"),
35-
{
36-
absolute: true,
37-
},
38-
);
28+
const componentsDir = join(import.meta.dirname, "../components");
29+
30+
const glob = new Glob("**/*.{ts,tsx}");
31+
const componentFiles: string[] = [];
32+
33+
for await (const file of glob.scan({
34+
cwd: componentsDir,
35+
absolute: true,
36+
})) {
37+
componentFiles.push(file);
38+
}
3939

4040
if (componentFiles.length === 0) {
4141
return;
4242
}
4343

4444
console.log("🎨 Formatting generated files with Prettier...");
4545

46-
await execa("bunx", ["prettier", "--write", ...componentFiles], {
47-
stdio: "inherit",
48-
});
46+
await execCommand("bunx", ["prettier", "--write", ...componentFiles]);
4947

5048
console.log("✨ Files formatted successfully");
5149
} catch (error) {

packages/ui/scripts/ui-list.ts renamed to packages/ui/scripts/list.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import { existsSync } from "node:fs";
44
import { readdir, stat } from "node:fs/promises";
5-
import { basename, dirname, join } from "node:path";
6-
import { fileURLToPath } from "node:url";
5+
import { basename, join } from "node:path";
76

87
interface ComponentInfo {
98
name: string;
@@ -26,8 +25,7 @@ async function listComponents(): Promise<void> {
2625
console.log("📋 shadcn/ui Component Inventory");
2726
console.log("=============================\n");
2827

29-
const __dirname = dirname(fileURLToPath(import.meta.url));
30-
const componentsDir = join(__dirname, "../components");
28+
const componentsDir = join(import.meta.dirname, "../components");
3129

3230
if (!existsSync(componentsDir)) {
3331
console.log(`❌ Components directory not found: ${componentsDir}`);

0 commit comments

Comments
 (0)