Home / Function/ createProject() — ui Function Reference

createProject() — ui Function Reference

Architecture documentation for the createProject() function in create-project.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  ee4c31b0_cc12_35da_90d1_168cb9e6c7f0["createProject()"]
  f570a109_148e_1b68_ffd0_6e7f2f8ca03d["create-project.ts"]
  ee4c31b0_cc12_35da_90d1_168cb9e6c7f0 -->|defined in| f570a109_148e_1b68_ffd0_6e7f2f8ca03d
  15eda161_afa0_52f7_da93_62b0a8c2e3ea["createNextProject()"]
  ee4c31b0_cc12_35da_90d1_168cb9e6c7f0 -->|calls| 15eda161_afa0_52f7_da93_62b0a8c2e3ea
  e89cc6ee_836f_1ddc_f90e_984178e4153e["createMonorepoProject()"]
  ee4c31b0_cc12_35da_90d1_168cb9e6c7f0 -->|calls| e89cc6ee_836f_1ddc_f90e_984178e4153e
  bc16475b_7b3b_d826_a651_6590edfd95f4["createViteProject()"]
  ee4c31b0_cc12_35da_90d1_168cb9e6c7f0 -->|calls| bc16475b_7b3b_d826_a651_6590edfd95f4
  a91ea13e_5803_048b_5539_8d46c24f175a["createStartProject()"]
  ee4c31b0_cc12_35da_90d1_168cb9e6c7f0 -->|calls| a91ea13e_5803_048b_5539_8d46c24f175a
  style ee4c31b0_cc12_35da_90d1_168cb9e6c7f0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/utils/create-project.ts lines 25–169

export async function createProject(
  options: Pick<
    z.infer<typeof initOptionsSchema>,
    "cwd" | "name" | "force" | "srcDir" | "components" | "template"
  >
) {
  options = {
    srcDir: false,
    ...options,
  }

  let template: keyof typeof TEMPLATES =
    options.template && TEMPLATES[options.template as keyof typeof TEMPLATES]
      ? (options.template as keyof typeof TEMPLATES)
      : "next"
  let projectName: string =
    options.name ??
    (template === TEMPLATES.next ||
    template === TEMPLATES.vite ||
    template === TEMPLATES.start
      ? "my-app"
      : "my-monorepo")
  let nextVersion = "latest"

  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

      // Force template to next for remote components.
      template = TEMPLATES.next
    } catch (error) {
      logger.break()
      handleError(error)
    }
  }

  if (!options.force) {
    const { type, name } = await prompts([
      {
        type: options.template || isRemoteComponent ? null : "select",
        name: "type",
        message: `The path ${highlighter.info(
          options.cwd
        )} does not contain a package.json file.\n  Would you like to start a new project?`,
        choices: [
          { title: "Next.js", value: "next" },
          { title: "Next.js (Monorepo)", value: "next-monorepo" },
          { title: "Vite", value: "vite" },
          { title: "TanStack Start", value: "start" },
        ],
        initial: 0,
      },
      {
        type: options.name ? null : "text",
        name: "name",
        message: "What is your project named?",
        initial: projectName,
        format: (value: string) => value.trim(),
        validate: (value: string) =>
          value.length > 128
            ? `Name should be less than 128 characters.`
            : true,
      },
    ])

    template = type ?? template
    projectName = name ?? projectName
  }

Subdomains

Frequently Asked Questions

What does createProject() do?
createProject() is a function in the ui codebase, defined in packages/shadcn/src/utils/create-project.ts.
Where is createProject() defined?
createProject() is defined in packages/shadcn/src/utils/create-project.ts at line 25.
What does createProject() call?
createProject() calls 4 function(s): createMonorepoProject, createNextProject, createStartProject, createViteProject.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free