feat(cli): detect and use next version (#6093)

* feat: detect and use next version

* chore: changeset
This commit is contained in:
shadcn
2024-12-16 23:53:40 +04:00
committed by GitHub
parent 1ff01b1bb5
commit c8fda09a63
8 changed files with 44 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
---
"shadcn": patch
---
detect and use next version

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -69,7 +69,7 @@ ChartContainer.displayName = "Chart"
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
([_, config]) => config.theme || config.color
([, config]) => config.theme || config.color
)
if (!colorConfig.length) {

View File

@@ -69,7 +69,7 @@ ChartContainer.displayName = "Chart"
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
([_, config]) => config.theme || config.color
([, config]) => config.theme || config.color
)
if (!colorConfig.length) {

View File

@@ -116,6 +116,7 @@ export const add = new Command()
cwd: options.cwd,
force: options.overwrite,
srcDir: options.srcDir,
components: options.components,
})
if (!projectPath) {
logger.break()

View File

@@ -1,8 +1,10 @@
import path from "path"
import { initOptionsSchema } from "@/src/commands/init"
import { getPackageManager } from "@/src/utils/get-package-manager"
import { handleError } from "@/src/utils/handle-error"
import { highlighter } from "@/src/utils/highlighter"
import { logger } from "@/src/utils/logger"
import { fetchRegistry } from "@/src/utils/registry"
import { spinner } from "@/src/utils/spinner"
import { execa } from "execa"
import fs from "fs-extra"
@@ -10,13 +12,38 @@ import prompts from "prompts"
import { z } from "zod"
export async function createProject(
options: Pick<z.infer<typeof initOptionsSchema>, "cwd" | "force" | "srcDir">
options: Pick<
z.infer<typeof initOptionsSchema>,
"cwd" | "force" | "srcDir" | "components"
>
) {
options = {
srcDir: false,
...options,
}
let nextVersion = "14.2.16"
const isRemoteComponent =
options.components?.length === 1 &&
!!options.components[0].match(/\/chat\/b\//)
if (options.components && isRemoteComponent) {
try {
const [result] = await fetchRegistry(options.components)
const { meta } = z
.object({
meta: z.object({
nextVersion: z.string(),
}),
})
.parse(result)
nextVersion = meta.nextVersion
} catch (error) {
logger.break()
handleError(error)
}
}
if (!options.force) {
const { proceed } = await prompts({
type: "confirm",
@@ -93,10 +120,14 @@ export async function createProject(
`--use-${packageManager}`,
]
if (nextVersion.startsWith("15")) {
args.push("--turbopack")
}
try {
await execa(
"npx",
["create-next-app@14.2.16", projectPath, "--silent", ...args],
[`create-next-app@${nextVersion}`, projectPath, "--silent", ...args],
{
cwd: options.cwd,
}

View File

@@ -170,7 +170,7 @@ export async function getItemTargetPath(
)
}
async function fetchRegistry(paths: string[]) {
export async function fetchRegistry(paths: string[]) {
try {
const results = await Promise.all(
paths.map(async (path) => {