Skip to content

Commit 4dd8c1f

Browse files
committed
feat(cli): allow http components to be used + only use new-york style
1 parent 944ff24 commit 4dd8c1f

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

apps/cli/src/services/commands/add.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Effect, Layer, pipe, Schema } from "effect"
1+
import { Effect, Layer } from "effect"
22
import { CliOptions } from "@cli/contexts/cli-options.js"
33
import { Doctor } from "@cli/services/commands/doctor.js"
44
import { ProjectConfig } from "../project-config.js"
@@ -25,11 +25,7 @@ class Add extends Effect.Service<Add>()("Add", {
2525
Effect.gen(function* () {
2626
yield* Effect.logDebug(`Add options: ${JSON.stringify(options, null, 2)}`)
2727

28-
const componentJson = yield* projectConfig.getComponentJson()
29-
const style = yield* pipe(
30-
componentJson.style,
31-
Schema.decodeUnknown(Schema.Union(Schema.Literal("default"), Schema.Literal("new-york")))
32-
)
28+
yield* projectConfig.getComponentJson() // ensure components.json config is valid and prompt if not
3329

3430
const components = options.all ? PROJECT_MANIFEST.components : (options.args?.components ?? [])
3531

@@ -54,10 +50,22 @@ class Add extends Effect.Service<Add>()("Add", {
5450

5551
const baseUrl =
5652
process.env.NODE_ENV === "development"
57-
? "http://localhost:3000/local/r"
58-
: "https://reactnativereusables.com/r"
53+
? "http://localhost:3000/local/r/new-york"
54+
: "https://reactnativereusables.com/r/new-york"
55+
56+
const manifestComponentsSet = new Set(
57+
PROJECT_MANIFEST.components.map((component) => component.toLocaleLowerCase())
58+
)
59+
60+
const componentUrls = components.map((component) => {
61+
const lowerCaseComponent = component.toLocaleLowerCase()
5962

60-
const componentUrls = components.map((component) => `${baseUrl}/${style}/${component}.json`)
63+
if (manifestComponentsSet.has(lowerCaseComponent)) {
64+
return `${baseUrl}/${lowerCaseComponent}.json`
65+
}
66+
67+
return component
68+
})
6169

6270
const shadcnOptions = toShadcnOptions(options)
6371

apps/cli/src/services/project-config.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,6 @@ class ProjectConfig extends Effect.Service<ProjectConfig>()("ProjectConfig", {
8181
return yield* Effect.fail(new Error("Unable to continue without a valid components.json file."))
8282
}
8383

84-
const style = options.yes
85-
? exists
86-
? "default"
87-
: "new-york"
88-
: yield* Prompt.select({
89-
message: "Which style would you like to use?",
90-
choices: exists
91-
? [
92-
{ title: "default", value: "default" },
93-
{ title: "new-york", value: "new-york" }
94-
]
95-
: ([
96-
{ title: "new-york", value: "new-york" },
97-
{ title: "default", value: "default" }
98-
] as const)
99-
})
100-
10184
const baseColor = options.yes
10285
? "neutral"
10386
: yield* Prompt.select({
@@ -191,7 +174,7 @@ class ProjectConfig extends Effect.Service<ProjectConfig>()("ProjectConfig", {
191174

192175
const newComponentJson = yield* Schema.encode(componentJsonSchema)({
193176
$schema: "https://ui.shadcn.com/schema.json",
194-
style,
177+
style: "new-york",
195178
aliases,
196179
rsc: false,
197180
tsx: true,

0 commit comments

Comments
 (0)