import { OutputFile } from "../tokens/types.js"; import { CopyOptions, PathLike } from "node:fs"; /** A directory to clean, and the directories in it to keep. */ export type CleanDir = { dir: string; keep: string[]; }; /** * Deletes everything in each `dir` except the directories in its `keep`, and the directories they are in, which are * cleaned the same way. Symlinks are deleted and never followed, so nothing outside `dir` is deleted. * * Everything to delete in every directory is found first, including everything in the directories that are deleted, * and nothing is deleted until that has succeeded. So when something can't be read or deleted, e.g. without * permission, cleaning stops before deleting anything. Only changes made to the files by something else while the * CLI runs can still stop it halfway. * * Directories are matched by what they are on disk, not by their paths. So a kept directory is found however its * path is written: with other letter case on case-insensitive file systems such as on Windows and macOS, or through * symlinks outside `dir`. Kept directories that aren't in `dir`, or don't exist, are ignored. * * `dir` can't be a symlink, and a kept directory can't be reached through a symlink in `dir`, since that symlink * would be deleted. The CLI checks both before cleaning, and stops with an error instead. */ export declare function cleanDirs(dirs: CleanDir[]): Promise; /** Deletes everything in `dir` except the directories in `keep`. See `cleanDirs`. */ export declare const removeAllExcept: (dir: string, keep: string[]) => Promise; /** The files, directories and symlinks that cleaning `dir` deletes, without deleting anything. */ export declare function findToDelete(dir: string, keep: string[]): Promise; declare class FileSystem { private isInitialized; private dry; private verbose; /** Default working directory is where the process was started */ workingDir: string; outDir: string; /** Initialize the file system */ init({ dry, outdir, verbose }: { dry?: boolean; outdir?: string; verbose?: boolean; }): void; /** * Creates a directory if it does not already exist. * * @param dir - The path of the directory to create. * * @returns A promise that resolves when the operation is complete. * If the directory already exists or `dry` is `true`, the promise resolves immediately. */ mkdir: (dir: PathLike) => Promise; writeFile: (path: PathLike, data: string) => Promise; cp: (src: string, dest: string, filter?: CopyOptions["filter"]) => Promise; copyFile: (src: PathLike, dest: PathLike) => Promise; cleanDir: (dir: string) => Promise; /** * Deletes what's in each `dir`, except the directories in its `keep`. Nothing is deleted until everything to delete * has been found, also in a dry run, so that a dry run stops with the same errors. See `cleanDirs`. */ cleanDirs: (dirs: CleanDir[]) => Promise; readFile: (path: PathLike, allowFileNotFound?: boolean) => Promise; readdir: (path: PathLike) => Promise; writeFiles: (files: OutputFile[], outDir: string, log?: boolean) => Promise; } /** * An abstraction of Node's file system API and helper functions for Designsystemet CLI interaction with the file system. * * Allows dry-running destructive operations, logging and store relevant file system state. */ export declare const dsfs: FileSystem; export {};