Skip to content

Commit 978411c

Browse files
committed
feat: add theme command
1 parent f60808a commit 978411c

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

bun.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"@effect/cli": "^0.60.1",
88
"@effect/platform": "^0.81.1",
99
"@effect/platform-bun": "^0.62.1",
10+
"chalk": "^5.4.1",
1011
"effect": "^3.14.22",
12+
"figlet": "^1.8.1",
1113
"nanoid": "^5.1.5",
1214
"rc9": "^2.1.2",
1315
"shadcn": "^2.5.0",
@@ -19,6 +21,7 @@
1921
"@commitlint/config-conventional": "^19.8.1",
2022
"@release-it/conventional-changelog": "^10.0.1",
2123
"@types/bun": "latest",
24+
"@types/figlet": "^1.7.0",
2225
"husky": "^9.1.7",
2326
"release-it": "^19.0.2",
2427
"rimraf": "^6.0.1",
@@ -341,6 +344,8 @@
341344

342345
"@types/cookie": ["@types/cookie@0.6.0", "", {}, "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA=="],
343346

347+
"@types/figlet": ["@types/figlet@1.7.0", "", {}, "sha512-KwrT7p/8Eo3Op/HBSIwGXOsTZKYiM9NpWRBJ5sVjWP/SmlS+oxxRvJht/FNAtliJvja44N3ul1yATgohnVBV0Q=="],
348+
344349
"@types/node": ["@types/node@22.15.3", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-lX7HFZeHf4QG/J7tBZqrCAXwz9J5RD56Y6MpP0eJkka8p+K0RY/yBTW7CYFJ4VGCclxqOLKmiGP5juQc6MKgcw=="],
345350

346351
"@types/normalize-package-data": ["@types/normalize-package-data@2.4.4", "", {}, "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA=="],
@@ -573,6 +578,8 @@
573578

574579
"fetch-blob": ["fetch-blob@3.2.0", "", { "dependencies": { "node-domexception": "^1.0.0", "web-streams-polyfill": "^3.0.3" } }, "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ=="],
575580

581+
"figlet": ["figlet@1.8.1", "", { "bin": { "figlet": "bin/index.js" } }, "sha512-kEC3Sme+YvA8Hkibv0NR1oClGcWia0VB2fC1SlMy027cwe795Xx40Xiv/nw/iFAwQLupymWh+uhAAErn/7hwPg=="],
582+
576583
"fill-range": ["fill-range@7.1.1", "", { "dependencies": { "to-regex-range": "^5.0.1" } }, "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg=="],
577584

578585
"find-my-way-ts": ["find-my-way-ts@0.1.5", "", {}, "sha512-4GOTMrpGQVzsCH2ruUn2vmwzV/02zF4q+ybhCIrw/Rkt3L8KWcycdC6aJMctJzwN4fXD4SD5F/4B9Sksh5rE0A=="],

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@commitlint/config-conventional": "^19.8.1",
3737
"@release-it/conventional-changelog": "^10.0.1",
3838
"@types/bun": "latest",
39+
"@types/figlet": "^1.7.0",
3940
"husky": "^9.1.7",
4041
"release-it": "^19.0.2",
4142
"rimraf": "^6.0.1",
@@ -45,7 +46,9 @@
4546
"@effect/cli": "^0.60.1",
4647
"@effect/platform": "^0.81.1",
4748
"@effect/platform-bun": "^0.62.1",
49+
"chalk": "^5.4.1",
4850
"effect": "^3.14.22",
51+
"figlet": "^1.8.1",
4952
"nanoid": "^5.1.5",
5053
"rc9": "^2.1.2",
5154
"shadcn": "^2.5.0"

src/commands/add.command.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { Command as RawCommand } from "@effect/platform"
66

77
export const componentNames = Args.text({ name: "componentNames" }).pipe(Args.repeated)
88

9-
export const componentType = Options.choice("type", ["ui", "block"]).pipe(Options.withDefault("ui"))
9+
export const componentType = Options.choice("type", ["ui", "block", "style"]).pipe(
10+
Options.withDefault("ui"),
11+
)
1012

1113
export const addCommand = Command.make("add", { componentNames, componentType }, (config) =>
1214
Effect.gen(function* () {

src/commands/theme.command.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Args, Command } from "@effect/cli"
2+
import { Effect } from "effect"
3+
import { REGISTRY_URL } from "~/consts"
4+
5+
import { Command as RawCommand } from "@effect/platform"
6+
7+
export const theme = Args.text({ name: "theme" })
8+
9+
export const themeCommand = Command.make("theme", { theme }, (config) =>
10+
Effect.gen(function* () {
11+
const themePath = `${REGISTRY_URL}/r/style/${config.theme}`
12+
13+
const exitCode = yield* RawCommand.make("bunx", "shadcn", "add", themePath).pipe(
14+
RawCommand.stdin("inherit"),
15+
RawCommand.stdout("inherit"),
16+
RawCommand.stderr("inherit"),
17+
RawCommand.exitCode,
18+
)
19+
}),
20+
).pipe(Command.withDescription("Adds UI components or blocks to your project."))

src/index.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,67 @@ import { Command } from "@effect/cli"
55
import { BunContext, BunRuntime } from "@effect/platform-bun"
66
import { Console, Effect } from "effect"
77

8+
import chalk from "chalk"
9+
import figlet from "figlet"
10+
811
import { addCommand } from "~/commands/add.command"
912
import { diffCommand } from "~/commands/diff.command"
1013
import { initCommand } from "~/commands/init.command"
1114
import { loginCommand } from "~/commands/login.command"
15+
import { themeCommand } from "./commands/theme.command"
16+
17+
const generateFigletText = (text: string, options: figlet.Options): Effect.Effect<string, Error> =>
18+
Effect.async<string, Error>((resume) => {
19+
figlet.text(text, options, (error, data) => {
20+
if (error) {
21+
resume(Effect.fail(new Error(error.message)))
22+
} else if (data) {
23+
resume(Effect.succeed(data))
24+
} else {
25+
resume(Effect.fail(new Error("Figlet returned undefined data")))
26+
}
27+
})
28+
})
1229

1330
const rootCommand = Command.make("root", {}, () =>
1431
Effect.gen(function* () {
15-
yield* Console.log("IntentUI CLI is ready to use!")
32+
const figletOptions: figlet.Options = {
33+
font: "Standard",
34+
horizontalLayout: "default",
35+
}
36+
37+
const intentTextEffect = generateFigletText("Intent", figletOptions)
38+
const uiTextEffect = generateFigletText("UI", figletOptions)
39+
40+
const [intentText, uiText] = yield* Effect.all([intentTextEffect, uiTextEffect]).pipe(
41+
Effect.catchAll(() => Effect.succeed([chalk.bold.cyan("Intent"), chalk.bold.magenta("UI")])),
42+
)
43+
44+
const intentLines = intentText.split("\n")
45+
const uiLines = uiText.split("\n")
46+
const maxLength = Math.max(intentLines.length, uiLines.length)
47+
const isFigletOutput = intentText.includes("\n")
48+
49+
for (let i = 0; i < maxLength; i++) {
50+
const intentLine = intentLines[i] || ""
51+
const uiLine = uiLines[i] || ""
52+
if (isFigletOutput) {
53+
yield* Console.log(`${chalk.bold.cyan(intentLine.padEnd(20))}${chalk.bold.magenta(uiLine)}`)
54+
} else {
55+
yield* Console.log(`${intentLine} ${uiLine}`)
56+
}
57+
}
58+
59+
yield* Console.log("")
60+
yield* Console.log(chalk.bold.yellow("IntentUI CLI is ready to use!"))
61+
yield* Console.log("")
1662
}),
1763
)
1864

1965
const command = rootCommand.pipe(
20-
Command.withSubcommands([initCommand, addCommand, diffCommand, loginCommand]),
66+
Command.withSubcommands([initCommand, addCommand, diffCommand, loginCommand, themeCommand]),
2167
)
2268

23-
// Set up the CLI application
2469
const cli = Command.run(command, {
2570
name: "IntentUI Cli",
2671
version: "v0.0.1",

0 commit comments

Comments
 (0)