Skip to content

Commit 656320d

Browse files
committed
feat: add all command
1 parent 505b2f2 commit 656320d

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

src/commands/add.command.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
import { Args, Command, Options } from "@effect/cli"
2-
import { Effect, pipe } from "effect"
2+
import { Effect, Schema, pipe } from "effect"
33
import { REGISTRY_URL } from "~/consts"
44

5-
import { Command as RawCommand } from "@effect/platform"
5+
import {
6+
HttpClient,
7+
HttpClientRequest,
8+
HttpClientResponse,
9+
Command as RawCommand,
10+
} from "@effect/platform"
11+
import { Component } from "~/schema/component"
612

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

915
export const isBlock = Options.boolean("b")
1016
export const isStyle = Options.boolean("s")
1117

18+
export const allComponents = Options.boolean("all").pipe(
19+
Options.withAlias("a"),
20+
Options.withDefault(false),
21+
)
22+
1223
export const componentType = Options.choice("type", ["ui", "block", "style"]).pipe(
1324
Options.withAlias("t"),
1425
Options.withDefault("ui"),
1526
)
1627

1728
export const addCommand = Command.make(
1829
"add",
19-
{ componentNames, isBlock, isStyle, componentType },
20-
({ componentNames, isBlock, isStyle, componentType }) =>
30+
{ componentNames, isBlock, isStyle, componentType, allComponents },
31+
({ componentNames, isBlock, isStyle, componentType, allComponents }) =>
2132
Effect.gen(function* () {
2233
const type = isBlock ? "block" : isStyle ? "style" : componentType
2334

@@ -26,6 +37,27 @@ export const addCommand = Command.make(
2637
Effect.succeed(`${REGISTRY_URL}/r/${type}-${name}.json`),
2738
),
2839
)
40+
41+
if (allComponents) {
42+
const client = yield* HttpClient.HttpClient.pipe()
43+
44+
const response = yield* HttpClientRequest.get("http://localhost:3000/r/index.json").pipe(
45+
client.execute,
46+
Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Array(Component))),
47+
)
48+
49+
return yield* RawCommand.make(
50+
"shadcnClone",
51+
"add",
52+
...response.map((c) => `https://intentui.com/r/${c.name}.json`),
53+
).pipe(
54+
RawCommand.stdin("inherit"),
55+
RawCommand.stdout("inherit"),
56+
RawCommand.stderr("inherit"),
57+
RawCommand.exitCode,
58+
)
59+
}
60+
2961
return yield* pipe(
3062
RawCommand.make("shadcnClone", "add", ...componentPaths).pipe(
3163
RawCommand.stdin("inherit"),

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Console, Effect } from "effect"
77
import chalk from "chalk"
88
import figlet from "figlet"
99

10+
import { FetchHttpClient } from "@effect/platform"
1011
import { addCommand } from "~/commands/add.command"
1112
import { diffCommand } from "~/commands/diff.command"
1213
import { initCommand } from "~/commands/init.command"
@@ -71,4 +72,9 @@ const cli = Command.run(command, {
7172
version: "v2.9.0",
7273
})
7374

74-
cli(process.argv).pipe(Effect.scoped, Effect.provide(NodeContext.layer), NodeRuntime.runMain)
75+
cli(process.argv).pipe(
76+
Effect.scoped,
77+
Effect.provide(NodeContext.layer),
78+
Effect.provide(FetchHttpClient.layer),
79+
NodeRuntime.runMain,
80+
)

src/schema/component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Schema as S } from "effect"
2+
3+
export const ComponentType = S.Literal("registry:component")
4+
5+
export class File extends S.Class<File>("File")({
6+
path: S.String,
7+
type: ComponentType,
8+
}) {}
9+
10+
export class Component extends S.Class<Component>("Registry:Component")({
11+
name: S.String,
12+
type: ComponentType,
13+
title: S.String,
14+
description: S.String,
15+
dependencies: S.Array(S.String),
16+
registryDependencies: S.Array(S.String),
17+
files: S.Array(File),
18+
}) {}

0 commit comments

Comments
 (0)