11import { Args , Command , Options } from "@effect/cli"
2- import { Console , Effect , Schema , pipe } from "effect"
3- import { REGISTRY_URL } from "~/consts"
4-
52import {
63 HttpClient ,
74 HttpClientRequest ,
85 HttpClientResponse ,
96 Command as RawCommand ,
107} from "@effect/platform"
118import chalk from "chalk"
9+ import { Console , Effect , Schema , pipe } from "effect"
10+ import { REGISTRY_URL } from "~/consts"
1211import { Component } from "~/schema/component"
1312
1413export const componentNames = Args . text ( { name : "componentNames" } ) . pipe ( Args . repeated )
1514
1615export const isBlock = Options . boolean ( "b" )
1716export const isStyle = Options . boolean ( "s" )
18-
1917export const allComponents = Options . boolean ( "all" ) . pipe (
2018 Options . withAlias ( "a" ) ,
2119 Options . withDefault ( false ) ,
2220)
23-
24- export const overwrite = Options . boolean ( "overwrite" ) . pipe ( Options . withDefault ( false ) )
25-
21+ export const overwrite = Options . boolean ( "overwrite" ) . pipe (
22+ Options . withAlias ( "o" ) ,
23+ Options . withDefault ( false ) ,
24+ )
2625export const componentType = Options . choice ( "type" , [ "ui" , "block" , "style" ] ) . pipe (
2726 Options . withAlias ( "t" ) ,
2827 Options . withDefault ( "ui" ) ,
@@ -35,43 +34,49 @@ export const addCommand = Command.make(
3534 Effect . gen ( function * ( ) {
3635 const type = isBlock ? "block" : isStyle ? "style" : componentType
3736
38- const componentPaths = yield * pipe (
39- Effect . forEach ( componentNames , ( name ) =>
40- Effect . succeed (
41- name . startsWith ( "http" )
42- ? name
43- : name . startsWith ( "-" )
44- ? null
45- : `${ REGISTRY_URL } /r/${ type } -${ name } .json`
46- ) ,
47- ) ,
48- Effect . map ( ( list ) => list . filter ( ( url ) : url is string => url !== null ) )
49- )
50-
51- if ( ! allComponents && componentPaths . length === 0 ) {
37+ if ( ! allComponents && componentNames . length === 0 ) {
5238 yield * Console . log ( chalk . red ( "No components selected" ) )
5339 yield * Console . log ( chalk . red ( "Please select a component or use --all" ) )
5440 return
5541 }
5642
5743 if ( allComponents ) {
5844 const client = yield * HttpClient . HttpClient . pipe ( )
59-
6045 const response = yield * HttpClientRequest . get ( "https://intentui.com/r/index.json" ) . pipe (
6146 client . execute ,
6247 Effect . flatMap ( HttpClientResponse . schemaBodyJson ( Schema . Array ( Component ) ) ) ,
6348 )
64-
6549 const components = response . map ( ( c ) => `${ REGISTRY_URL } /r/${ c . name } .json` )
66- componentPaths . push ( ...components )
50+ const args = [ "add" ]
51+ if ( overwrite ) args . push ( "--overwrite" )
52+ args . push ( ...components )
53+ return yield * pipe (
54+ RawCommand . make ( "shadcnClone" , ...args ) . pipe (
55+ RawCommand . stdin ( "inherit" ) ,
56+ RawCommand . stdout ( "inherit" ) ,
57+ RawCommand . stderr ( "inherit" ) ,
58+ RawCommand . exitCode ,
59+ ) ,
60+ )
6761 }
6862
69- const args = [ "add" ]
63+ const manualOverwrite =
64+ overwrite || componentNames . includes ( "--overwrite" ) || componentNames . includes ( "-o" )
65+
66+ const cleanedComponentNames = componentNames . filter (
67+ ( name ) => name !== "--overwrite" && name !== "-o" ,
68+ )
7069
71- if ( overwrite ) {
70+ const componentPaths = yield * pipe (
71+ Effect . forEach ( cleanedComponentNames , ( name ) =>
72+ Effect . succeed ( name . startsWith ( "http" ) ? name : `${ REGISTRY_URL } /r/${ type } -${ name } .json` ) ,
73+ ) ,
74+ )
75+
76+ const args = [ "add" ]
77+ if ( manualOverwrite ) {
7278 args . push ( "--overwrite" )
7379 }
74-
7580 args . push ( ...componentPaths )
7681
7782 return yield * pipe (
0 commit comments