Skip to content

Commit

Permalink
feat(cli): detect and use next version (#6093)
Browse files Browse the repository at this point in the history
* feat: detect and use next version

* chore: changeset
  • Loading branch information
shadcn authored Dec 16, 2024
1 parent 1ff01b1 commit c8fda09
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-hornets-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": patch
---

detect and use next version
2 changes: 1 addition & 1 deletion apps/www/public/r/styles/default/chart.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/public/r/styles/new-york/chart.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/www/registry/default/ui/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/www/registry/new-york/ui/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/shadcn/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
35 changes: 33 additions & 2 deletions packages/shadcn/src/utils/create-project.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
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"
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",
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shadcn/src/utils/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit c8fda09

Please sign in to comment.