Home / File/ cli.spec.ts — vite Source File

cli.spec.ts — vite Source File

Architecture documentation for cli.spec.ts, a typescript file in the vite codebase. 4 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  7cbe649b_da11_1a9e_67ab_1b05652f2411["cli.spec.ts"]
  e6032fbc_44cf_58d6_868d_dd15106c18c5["node:fs"]
  7cbe649b_da11_1a9e_67ab_1b05652f2411 --> e6032fbc_44cf_58d6_868d_dd15106c18c5
  51e96894_3556_ed5c_1ede_97d449867adf["node:path"]
  7cbe649b_da11_1a9e_67ab_1b05652f2411 --> 51e96894_3556_ed5c_1ede_97d449867adf
  e4bc57e8_546b_c84b_ee54_df323bec2a01["execa"]
  7cbe649b_da11_1a9e_67ab_1b05652f2411 --> e4bc57e8_546b_c84b_ee54_df323bec2a01
  a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"]
  7cbe649b_da11_1a9e_67ab_1b05652f2411 --> a340ba46_b2b7_3048_3bb3_6907a74c8464
  style 7cbe649b_da11_1a9e_67ab_1b05652f2411 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs'
import path from 'node:path'
import type { SyncOptions } from 'execa'
import { execaCommandSync } from 'execa'
import { afterEach, beforeAll, expect, test } from 'vitest'

const CLI_PATH = path.join(import.meta.dirname, '..')

const projectName = 'test-app'
const genPath = path.join(import.meta.dirname, projectName)
const genPathWithSubfolder = path.join(
  import.meta.dirname,
  'subfolder',
  projectName,
)

const run = (args: string[], options?: SyncOptions) => {
  return execaCommandSync(`node ${CLI_PATH} ${args.join(' ')}`, {
    env: { ...process.env, _VITE_TEST_CLI: 'true' },
    ...options,
  })
}

// Helper to create a non-empty directory
const createNonEmptyDir = (overrideFolder?: string) => {
  // Create the temporary directory
  const newNonEmptyFolder = overrideFolder || genPath
  fs.mkdirSync(newNonEmptyFolder, { recursive: true })

  // Create a package.json file
  const pkgJson = path.join(newNonEmptyFolder, 'package.json')
  fs.writeFileSync(pkgJson, '{ "foo": "bar" }')
}

// Vue 3 starter template
const templateFiles = fs
  .readdirSync(path.join(CLI_PATH, 'template-vue'))
  // _gitignore is renamed to .gitignore
  .map((filePath) => (filePath === '_gitignore' ? '.gitignore' : filePath))
  .sort()

// React starter template
const templateFilesReact = fs
  .readdirSync(path.join(CLI_PATH, 'template-react'))
  // _gitignore is renamed to .gitignore
  .map((filePath) => (filePath === '_gitignore' ? '.gitignore' : filePath))
  .sort()

const clearAnyPreviousFolders = () => {
  if (fs.existsSync(genPath)) {
    fs.rmSync(genPath, { recursive: true, force: true })
  }
  if (fs.existsSync(genPathWithSubfolder)) {
    fs.rmSync(genPathWithSubfolder, { recursive: true, force: true })
  }
}

beforeAll(() => clearAnyPreviousFolders())
afterEach(() => clearAnyPreviousFolders())

// ... (198 more lines)

Subdomains

Dependencies

  • execa
  • node:fs
  • node:path
  • vitest

Frequently Asked Questions

What does cli.spec.ts do?
cli.spec.ts is a source file in the vite codebase, written in typescript. It belongs to the ProjectScaffolder domain, CLIPrompts subdomain.
What functions are defined in cli.spec.ts?
cli.spec.ts defines 5 function(s): clearAnyPreviousFolders, createNonEmptyDir, run, templateFiles, templateFilesReact.
What does cli.spec.ts depend on?
cli.spec.ts imports 4 module(s): execa, node:fs, node:path, vitest.
Where is cli.spec.ts in the architecture?
cli.spec.ts is located at packages/create-vite/__tests__/cli.spec.ts (domain: ProjectScaffolder, subdomain: CLIPrompts, directory: packages/create-vite/__tests__).

Analyze Your Own Codebase

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

Try Supermodel Free