mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-30 16:14:13 +00:00
feat(cli): detect and use next version (#6093)
* feat: detect and use next version * chore: changeset
This commit is contained in:
5
.changeset/three-hornets-wash.md
Normal file
5
.changeset/three-hornets-wash.md
Normal 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
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user