11import { Command } from "@effect/cli"
22import { Console , Effect } from "effect"
3+ import { Command as RawCommand , FileSystem } from "@effect/platform"
4+ import { NodeFileSystem } from "@effect/platform-node"
35
4- import { FileSystem , Command as RawCommand } from "@effect/platform"
56import { REGISTRY_URL } from "~/consts"
67
78import { NodeCommandExecutor } from "@effect/platform-node"
8-
99const shadcnInit = RawCommand . make ( "shadcnClone" , "init" , `${ REGISTRY_URL } /r/default.json` ) . pipe (
1010 RawCommand . stdin ( "inherit" ) ,
1111 RawCommand . stdout ( "inherit" ) ,
@@ -16,13 +16,55 @@ export const initCommand = Command.make("init", {}, () =>
1616 Effect . gen ( function * ( ) {
1717 const fileSytem = yield * FileSystem . FileSystem
1818
19+ const componentsJsonPath = "components.json"
1920 const hasIntentUiConfig = yield * fileSytem . exists ( "intentui.json" )
20- const hasComponentJson = yield * fileSytem . exists ( "component.json" )
21+ const hasComponentsJson = yield * fileSytem . exists ( componentsJsonPath )
2122
22- if ( hasIntentUiConfig && ! hasComponentJson ) {
23+ if ( hasIntentUiConfig && ! hasComponentsJson ) {
2324 yield * Console . log ( "Migrating to new config format..." )
2425 }
2526
26- const results = yield * RawCommand . exitCode ( shadcnInit )
27- } ) . pipe ( Effect . scoped , Effect . provide ( NodeCommandExecutor . layer ) ) ,
27+ yield * RawCommand . exitCode ( shadcnInit )
28+ const exists = yield * fileSytem . exists ( componentsJsonPath )
29+
30+ if ( ! exists ) return
31+
32+ const jsonStr = yield * fileSytem . readFileString ( componentsJsonPath )
33+ const json = yield * Effect . try ( ( ) => JSON . parse ( jsonStr ) )
34+
35+ if ( ! json . tailwind ?. css ) return
36+
37+ const cssPath = json . tailwind . css
38+ const cssExists = yield * fileSytem . exists ( cssPath )
39+
40+ if ( ! cssExists ) return
41+
42+ const content = yield * fileSytem . readFileString ( cssPath )
43+
44+ const lines = content . split ( "\n" )
45+
46+ const alreadyHas = ( line : string ) => lines . some ( ( l ) => l . trim ( ) === line )
47+
48+ const injectLines = [
49+ '@import "tw-animate-css";' ,
50+ '@plugin "tailwindcss-react-aria-components";' ,
51+ ] . filter ( ( line ) => ! alreadyHas ( line ) )
52+
53+ if ( injectLines . length === 0 ) return
54+
55+ const tailwindIndex = lines . findIndex ( ( l ) => l . trim ( ) === '@import "tailwindcss";' )
56+
57+ if ( tailwindIndex === - 1 ) return
58+
59+ lines . splice ( tailwindIndex + 1 , 0 , ...injectLines )
60+
61+ const patched = lines . join ( "\n" )
62+
63+ yield * fileSytem . writeFileString ( cssPath , patched )
64+
65+ } ) . pipe (
66+ Effect . scoped ,
67+ Effect . provide ( NodeCommandExecutor . layer ) ,
68+ Effect . provide ( NodeFileSystem . layer ) ,
69+ ) ,
2870) . pipe ( Command . withDescription ( "Initializes the project and sets up necessary configurations." ) )
0 commit comments