11import { Args , Command , Options } from "@effect/cli"
2- import { Effect , pipe } from "effect"
2+ import { Effect , Schema , pipe } from "effect"
33import { 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
713export const componentNames = Args . text ( { name : "componentNames" } ) . pipe ( Args . repeated )
814
915export const isBlock = Options . boolean ( "b" )
1016export const isStyle = Options . boolean ( "s" )
1117
18+ export const allComponents = Options . boolean ( "all" ) . pipe (
19+ Options . withAlias ( "a" ) ,
20+ Options . withDefault ( false ) ,
21+ )
22+
1223export const componentType = Options . choice ( "type" , [ "ui" , "block" , "style" ] ) . pipe (
1324 Options . withAlias ( "t" ) ,
1425 Options . withDefault ( "ui" ) ,
1526)
1627
1728export 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" ) ,
0 commit comments