@sujalchoudhari/solaris-ui
Version:
A UI framework to create HTML pages with just JavaScript.
84 lines (83 loc) • 3.19 kB
TypeScript
/**
* FileManager
* -----
* A class dedicated for handling files and directories
* This class is responsible for managing project folders, copying files from source to build folders.
* @author Sujal Choudhari <sujalchoudhari@gmail.com>
*/
export default class FileManager {
/**
* Absolute path to current working directory
*/
basePath: string;
/**
* Creare a new instance of FileManager
* While creating a new instance of FileManager, base path will be automatically
* set to the current working directory.
*/
constructor(basepath?: string);
/**
* Convert relative path to absolute path
* @param relativePath The relative path of any file or directory
* @returns The abosolute path of the file or directory.
* @deprecated No not use this method. Will be removed in future versions
*/
getAbsolutePath(relativePath: string): string;
/**
* Read a file synchronously
* @param path relative path of the file or directory
* @returns the contents of the file or directory. `null`if file is not found
*/
readFile(path: string): string | null;
/**
* Create a new directory
* @param path Path at which the directory should be created. The name of the directory should be
* included in the path
*/
createDirectory(path: string): void;
/**
* Copy the directory from source to destination
* @param srcPath THe source path of the directory
* @param destPath the final destination path
*/
copyDirectory(srcPath: string, destPath: string): void;
/**
* Get a list of names of files and in the directory and its subdirectories.
* @param directoryPath The path to the directory to get the names from
* @returns A List of the names (absolute paths)
*
* @author Ansh Sharma
*/
getAllFilesInDirectory(directoryPath: string): string[];
/**
* Move a file from one directory to another
* @param srcPath Source path
* @param destPath Destination path
*/
moveFile(srcPath: string, destPath: string): void;
/**
* Copy a file to a destination
* @param srcPath Source file path
* @param destPath Destination file path
* @param srcPathType The type of the source path, relative or absolute. Default is relative
*/
copyFile(srcPath: string, destPath: string, srcPathType?: "relative" | "absolute"): void;
/**
* Create a new file at the specified path
* @param filePath New File Path, the name of file should be included in the path.
* @param contents The contents of the file to create with.
*/
createFile(filePath: string, contents: string): void;
/**
* Copy the contents of the folder into another folder including subdirectories.
* @param srcPath Source file path
* @param destPath Destination path
*/
copyTree(srcPath: string, destPath: string): void;
/**
* Delete the specified folder
* @param path Path of the directory to remove
* @param force Remove the directory forefully. Even if the directory is not empty.
*/
removeDirectory(path: string, force?: boolean): void;
}