Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 989880f

Browse files
committed
fix
1 parent 58d23e3 commit 989880f

4 files changed

Lines changed: 90 additions & 3 deletions

File tree

src/commands/block.command.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Args, Command, Options } from "@effect/cli"
2+
import { Command as RawCommand } from "@effect/platform"
3+
import { Console, Effect, pipe } from "effect"
4+
import { BLOCKS_REGISTRY_URL } from "~/consts"
5+
import { getApiKey } from "./login.command"
6+
7+
export const blockName = Args.text({ name: "blockName" })
8+
export const blockType = Args.text({ name: "blockType" })
9+
export const blockCategory = Args.text({ name: "blockCategory" })
10+
11+
export const overwrite = Options.boolean("overwrite").pipe(
12+
Options.withAlias("o"),
13+
Options.withDefault(false),
14+
)
15+
16+
export const addBlockCommand = Command.make(
17+
"block",
18+
{ blockCategory, blockType, blockName, overwrite },
19+
({ blockCategory, blockType, blockName, overwrite }) =>
20+
Effect.gen(function* () {
21+
const apikey = yield* getApiKey
22+
23+
if (!apikey) {
24+
yield* Console.error("No API key found. Please login first.")
25+
26+
return yield* Effect.fail(new Error("No API key found. Please login first."))
27+
}
28+
29+
const componentPath = yield* pipe(
30+
Effect.succeed(
31+
`${BLOCKS_REGISTRY_URL}/api/shadcn-registry/block/${blockCategory}/${blockType}/${blockName}?apiKey=${apikey}`,
32+
),
33+
)
34+
35+
console.log(componentPath)
36+
37+
const args = ["add"]
38+
39+
if (overwrite) {
40+
args.push("--overwrite")
41+
}
42+
args.push(componentPath)
43+
44+
return yield* pipe(
45+
RawCommand.make("shadcnClone", ...args).pipe(
46+
RawCommand.stdin("inherit"),
47+
RawCommand.stdout("inherit"),
48+
RawCommand.stderr("inherit"),
49+
RawCommand.exitCode,
50+
),
51+
)
52+
}),
53+
).pipe(Command.withDescription("Adds UI components or blocks to your project."))

src/commands/login.command.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Command } from "@effect/cli"
99
import { Config, Console, Data, Effect } from "effect"
1010
import { customAlphabet } from "nanoid"
1111

12-
const FILENAME = ".intentui"
12+
export const FILENAME = ".intentui"
1313
const DOMAIN_CONFIG = Config.succeed("https://blocks.intentui.com")
1414

1515
class UserCancellationError extends Data.TaggedError("UserCancellationError")<{
@@ -77,6 +77,31 @@ const saveApiKey = (apiKey: string) =>
7777
})
7878
})
7979

80+
export const getApiKey = Effect.gen(function* () {
81+
const path = yield* getUserConfigPath
82+
const content = yield* Effect.tryPromise({
83+
try: () => FS.readFile(path, "utf8"),
84+
catch: (cause) =>
85+
new FileSystemError({
86+
message: "Failed to read API key",
87+
path,
88+
cause,
89+
}),
90+
})
91+
92+
const config = yield* Effect.try({
93+
try: () => JSON.parse(content),
94+
catch: (cause) =>
95+
new FileSystemError({
96+
message: "Invalid config file format",
97+
path,
98+
cause,
99+
}),
100+
})
101+
102+
return yield* Effect.succeed(config.key as string)
103+
})
104+
80105
export const loginCommand = Command.make("login", {}, () =>
81106
Effect.gen(function* () {
82107
yield* Console.log("Attempting to log in to Intent UI Blocks...")

src/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const REGISTRY_URL = "https://intentui.com"
2+
export const BLOCKS_REGISTRY_URL = "https://blocks.intentui.com"

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env node
1+
#! /usr/bin/env bun
22

33
import { Command } from "@effect/cli"
44
import { NodeContext, NodeRuntime } from "@effect/platform-node"
@@ -12,6 +12,7 @@ import { addCommand } from "~/commands/add.command"
1212
import { diffCommand } from "~/commands/diff.command"
1313
import { initCommand } from "~/commands/init.command"
1414
import { loginCommand } from "~/commands/login.command"
15+
import { addBlockCommand } from "./commands/block.command"
1516
import { themeCommand } from "./commands/theme.command"
1617

1718
const generateFigletText = (text: string, options: figlet.Options): Effect.Effect<string, Error> =>
@@ -64,7 +65,14 @@ const rootCommand = Command.make("root", {}, () =>
6465
)
6566

6667
const command = rootCommand.pipe(
67-
Command.withSubcommands([initCommand, addCommand, diffCommand, loginCommand, themeCommand]),
68+
Command.withSubcommands([
69+
initCommand,
70+
addCommand,
71+
diffCommand,
72+
loginCommand,
73+
themeCommand,
74+
addBlockCommand,
75+
]),
6876
)
6977

7078
const cli = Command.run(command, {

0 commit comments

Comments
 (0)