1
1
import { Args , Command , Options } from "@effect/cli"
2
- import { Effect , pipe } from "effect"
2
+ import { Effect , Schema , pipe } from "effect"
3
3
import { REGISTRY_URL } from "~/consts"
4
4
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"
6
12
7
13
export const componentNames = Args . text ( { name : "componentNames" } ) . pipe ( Args . repeated )
8
14
9
15
export const isBlock = Options . boolean ( "b" )
10
16
export const isStyle = Options . boolean ( "s" )
11
17
18
+ export const allComponents = Options . boolean ( "all" ) . pipe (
19
+ Options . withAlias ( "a" ) ,
20
+ Options . withDefault ( false ) ,
21
+ )
22
+
12
23
export const componentType = Options . choice ( "type" , [ "ui" , "block" , "style" ] ) . pipe (
13
24
Options . withAlias ( "t" ) ,
14
25
Options . withDefault ( "ui" ) ,
15
26
)
16
27
17
28
export const addCommand = Command . make (
18
29
"add" ,
19
- { componentNames, isBlock, isStyle, componentType } ,
20
- ( { componentNames, isBlock, isStyle, componentType } ) =>
30
+ { componentNames, isBlock, isStyle, componentType, allComponents } ,
31
+ ( { componentNames, isBlock, isStyle, componentType, allComponents } ) =>
21
32
Effect . gen ( function * ( ) {
22
33
const type = isBlock ? "block" : isStyle ? "style" : componentType
23
34
@@ -26,6 +37,27 @@ export const addCommand = Command.make(
26
37
Effect . succeed ( `${ REGISTRY_URL } /r/${ type } -${ name } .json` ) ,
27
38
) ,
28
39
)
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
+
29
61
return yield * pipe (
30
62
RawCommand . make ( "shadcnClone" , "add" , ...componentPaths ) . pipe (
31
63
RawCommand . stdin ( "inherit" ) ,
0 commit comments