Skip to content

Commit b8f44f9

Browse files
committed
fix(cli): handling of base style for add command
from shadcn
1 parent ee9393d commit b8f44f9

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

packages/cli/src/commands/add.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,20 @@ export const add = new Command()
9191
}
9292

9393
let itemType: z.infer<typeof registryItemTypeSchema> | undefined
94+
let shouldInstallBaseStyle = true
9495
if (components.length > 0) {
9596
const [registryItem] = await getRegistryItems([components[0]], {
9697
config: initialConfig,
9798
})
9899
itemType = registryItem?.type
100+
shouldInstallBaseStyle
101+
= itemType !== 'registry:theme' && itemType !== 'registry:style'
99102

100103
if (isUniversalRegistryItem(registryItem)) {
101-
await addComponents(components, initialConfig, options)
104+
await addComponents(components, initialConfig, {
105+
...options,
106+
baseStyle: shouldInstallBaseStyle,
107+
})
102108
return
103109
}
104110

@@ -171,11 +177,12 @@ export const add = new Command()
171177
force: true,
172178
defaults: false,
173179
skipPreflight: false,
174-
silent: options.silent || !hasNewRegistries,
180+
silent: options.silent && !hasNewRegistries,
175181
isNewProject: false,
176182
srcDir: options.srcDir,
177183
cssVariables: options.cssVariables,
178-
baseStyle: itemType !== 'registry:theme',
184+
baseStyle: shouldInstallBaseStyle,
185+
baseColor: shouldInstallBaseStyle ? undefined : 'neutral',
179186
components: options.components,
180187
})
181188
}
@@ -238,7 +245,7 @@ export const add = new Command()
238245
if (!initHasRun) {
239246
await addComponents(options.components, config, {
240247
...options,
241-
baseStyle: itemType !== 'registry:theme',
248+
baseStyle: shouldInstallBaseStyle,
242249
})
243250
}
244251

packages/cli/src/commands/init.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
restoreFileBackup,
2929
} from '@/src/utils/file-helper'
3030
import {
31+
createConfig,
3132
DEFAULT_COMPONENTS,
3233
DEFAULT_TAILWIND_CONFIG,
3334
DEFAULT_TAILWIND_CSS,
@@ -160,15 +161,32 @@ export const init = new Command()
160161
if (components.length > 0) {
161162
// We don't know the full config at this point.
162163
// So we'll use a shadow config to fetch the first item.
163-
let shadowConfig = configWithDefaults({})
164+
let shadowConfig = configWithDefaults(
165+
createConfig({
166+
resolvedPaths: {
167+
cwd: options.cwd,
168+
},
169+
}),
170+
)
164171

165172
// Check if there's a components.json file.
166173
// If so, we'll merge with our shadow config.
167174
const componentsJsonPath = path.resolve(options.cwd, 'components.json')
168175
if (fsExtra.existsSync(componentsJsonPath)) {
169176
const existingConfig = await fsExtra.readJson(componentsJsonPath)
170177
const config = rawConfigSchema.partial().parse(existingConfig)
171-
shadowConfig = configWithDefaults(config)
178+
const baseConfig = createConfig({
179+
resolvedPaths: {
180+
cwd: options.cwd,
181+
},
182+
})
183+
shadowConfig = configWithDefaults({
184+
...config,
185+
resolvedPaths: {
186+
...baseConfig.resolvedPaths,
187+
cwd: options.cwd,
188+
},
189+
})
172190

173191
// Since components.json might not be valid at this point.
174192
// Temporarily rename components.json to allow preflight to run.
@@ -182,6 +200,7 @@ export const init = new Command()
182200
shadowConfig,
183201
{
184202
silent: true,
203+
writeFile: false,
185204
},
186205
)
187206
shadowConfig = updatedConfig
@@ -217,7 +236,7 @@ export const init = new Command()
217236
)} Project initialization completed.\nYou may now add components.`,
218237
)
219238

220-
// We need when runninng with custom cwd.
239+
// We need when running with custom cwd.
221240
deleteFileBackup(path.resolve(options.cwd, 'components.json'))
222241
logger.break()
223242
}

0 commit comments

Comments
 (0)