Skip to content

fs

File system utilities.

typescript
import { checkSourceExists, ensureTargetDir, fileExists, shouldUpdateFile, copySourceToTarget, writeFileContent, readFileSync, runWithConcurrency } from '@meng-xi/vite-plugin/common'

checkSourceExists

Check if source file exists, throws if not.

typescript
async function checkSourceExists(sourcePath: string): Promise<void>

ensureTargetDir

Ensure target directory exists, create recursively if not.

typescript
async function ensureTargetDir(targetPath: string): Promise<void>

fileExists

Check if file exists.

typescript
async function fileExists(filePath: string): Promise<boolean>

shouldUpdateFile

Check if file needs update (compare mtime and size).

typescript
async function shouldUpdateFile(sourceFile: string, targetFile: string): Promise<boolean>

copySourceToTarget

Copy files or directories to target location.

typescript
async function copySourceToTarget(sourcePath: string, targetPath: string, options: CopyOptions): Promise<CopyResult>

CopyOptions

PropertyTypeDefaultDescription
recursiveboolean-Recursively copy
overwriteboolean-Overwrite existing
incrementalbooleanfalseOnly copy modified
parallelLimitnumber10Concurrency limit

CopyResult

PropertyTypeDescription
copiedFilesnumberFiles copied
skippedFilesnumberFiles skipped
copiedDirsnumberDirectories copied
executionTimenumberExecution time (ms)

writeFileContent

Write content to file.

typescript
async function writeFileContent(filePath: string, content: string): Promise<void>

readFileSync

Synchronously read file content.

typescript
function readFileSync(filePath: string): string

runWithConcurrency

Execute tasks with concurrency limit.

typescript
async function runWithConcurrency<T, R>(items: T[], handler: (item: T) => Promise<R>, concurrency: number): Promise<R[]>

Released under the MIT License.