Home / Function/ runInit() — ui Function Reference

runInit() — ui Function Reference

Architecture documentation for the runInit() function in init.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  56c01a63_5907_6b2d_a507_d935d5ec6f68["runInit()"]
  f50d8e38_92d7_c930_5ca6_b71673ceb658["init.ts"]
  56c01a63_5907_6b2d_a507_d935d5ec6f68 -->|defined in| f50d8e38_92d7_c930_5ca6_b71673ceb658
  d6e73ad2_74c9_dd43_c275_b68a987b6b66["create()"]
  d6e73ad2_74c9_dd43_c275_b68a987b6b66 -->|calls| 56c01a63_5907_6b2d_a507_d935d5ec6f68
  f8868a17_e9a2_805a_984b_553ed4170019["init()"]
  f8868a17_e9a2_805a_984b_553ed4170019 -->|calls| 56c01a63_5907_6b2d_a507_d935d5ec6f68
  deb79baf_3feb_e923_c41b_0555c842f472["promptForMinimalConfig()"]
  56c01a63_5907_6b2d_a507_d935d5ec6f68 -->|calls| deb79baf_3feb_e923_c41b_0555c842f472
  5cb14ea1_4ee8_7cc2_958b_1c4740f7e8b9["promptForConfig()"]
  56c01a63_5907_6b2d_a507_d935d5ec6f68 -->|calls| 5cb14ea1_4ee8_7cc2_958b_1c4740f7e8b9
  style 56c01a63_5907_6b2d_a507_d935d5ec6f68 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/commands/init.ts lines 271–410

export async function runInit(
  options: z.infer<typeof initOptionsSchema> & {
    skipPreflight?: boolean
  }
) {
  let projectInfo
  let newProjectTemplate
  if (!options.skipPreflight) {
    const preflight = await preFlightInit(options)
    if (preflight.errors[ERRORS.MISSING_DIR_OR_EMPTY_PROJECT]) {
      const { projectPath, template } = await createProject(options)
      if (!projectPath) {
        process.exit(1)
      }
      options.cwd = projectPath
      options.isNewProject = true
      newProjectTemplate = template
      // Re-get project info for the newly created project.
      projectInfo = await getProjectInfo(options.cwd)
    } else {
      projectInfo = preflight.projectInfo
    }
  } else {
    projectInfo = await getProjectInfo(options.cwd)
  }

  if (newProjectTemplate === "next-monorepo") {
    options.cwd = path.resolve(options.cwd, "apps/web")
    return await getConfig(options.cwd)
  }

  const projectConfig = await getProjectConfig(options.cwd, projectInfo)

  let config = projectConfig
    ? await promptForMinimalConfig(projectConfig, options)
    : await promptForConfig(await getConfig(options.cwd))

  if (!options.yes) {
    const { proceed } = await prompts({
      type: "confirm",
      name: "proceed",
      message: `Write configuration to ${highlighter.info(
        "components.json"
      )}. Proceed?`,
      initial: true,
    })

    if (!proceed) {
      process.exit(0)
    }
  }

  // Prepare the list of components to be added.
  const components = [
    // "index" is the default shadcn style.
    // Why index? Because when style is true, we read style from components.json and fetch that.
    // i.e new-york from components.json then fetch /styles/new-york/index.
    // TODO: Fix this so that we can extend any style i.e --style=new-york.
    ...(options.baseStyle ? ["index"] : []),
    ...(options.components ?? []),
  ]

  // Ensure registries are configured for the components we're about to add.
  const fullConfigForRegistry = await resolveConfigPaths(options.cwd, config)
  const { config: configWithRegistries } = await ensureRegistriesInConfig(
    components,
    fullConfigForRegistry,
    {
      silent: true,
    }
  )

  // Update config with any new registries found.
  if (configWithRegistries.registries) {
    config.registries = configWithRegistries.registries
  }

  const componentSpinner = spinner(`Writing components.json.`).start()
  const targetPath = path.resolve(options.cwd, "components.json")
  const backupPath = `${targetPath}${FILE_BACKUP_SUFFIX}`

Subdomains

Called By

Frequently Asked Questions

What does runInit() do?
runInit() is a function in the ui codebase, defined in packages/shadcn/src/commands/init.ts.
Where is runInit() defined?
runInit() is defined in packages/shadcn/src/commands/init.ts at line 271.
What does runInit() call?
runInit() calls 2 function(s): promptForConfig, promptForMinimalConfig.
What calls runInit()?
runInit() is called by 2 function(s): create, init.

Analyze Your Own Codebase

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

Try Supermodel Free