-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
598 additions
and
850 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,64 @@ | ||
/** | ||
* Writes data to a file at the specified path. | ||
* @param {string} path - The path to the file. | ||
* @param {string} data - The data to write to the file. | ||
* @returns {Promise<any>} A Promise that resolves when the file is written successfully. | ||
*/ | ||
const writeFile: (path: string, data: string) => Promise<any> = (path, data) => | ||
global.core.api?.writeFile(path, data) | ||
|
||
/** | ||
* Checks whether the path is a directory. | ||
* @param path - The path to check. | ||
* @returns {boolean} A boolean indicating whether the path is a directory. | ||
*/ | ||
const isDirectory = (path: string): Promise<boolean> => global.core.api?.isDirectory(path) | ||
const writeFileSync = (...args: any[]) => global.core.api?.writeFileSync(...args) | ||
|
||
/** | ||
* Reads the contents of a file at the specified path. | ||
* @param {string} path - The path of the file to read. | ||
* @returns {Promise<any>} A Promise that resolves with the contents of the file. | ||
*/ | ||
const readFile: (path: string) => Promise<any> = (path) => global.core.api?.readFile(path) | ||
const readFileSync = (...args: any[]) => global.core.api?.readFileSync(...args) | ||
/** | ||
* Check whether the file exists | ||
* @param {string} path | ||
* @returns {boolean} A boolean indicating whether the path is a file. | ||
*/ | ||
const exists = (path: string): Promise<boolean> => global.core.api?.exists(path) | ||
const existsSync = (...args: any[]) => global.core.api?.existsSync(...args) | ||
/** | ||
* List the directory files | ||
* @param {string} path - The path of the directory to list files. | ||
* @returns {Promise<any>} A Promise that resolves with the contents of the directory. | ||
*/ | ||
const listFiles: (path: string) => Promise<any> = (path) => global.core.api?.listFiles(path) | ||
const readdirSync = (...args: any[]) => global.core.api?.readdirSync(...args) | ||
/** | ||
* Creates a directory at the specified path. | ||
* @param {string} path - The path of the directory to create. | ||
* @returns {Promise<any>} A Promise that resolves when the directory is created successfully. | ||
*/ | ||
const mkdir: (path: string) => Promise<any> = (path) => global.core.api?.mkdir(path) | ||
const mkdirSync = (...args: any[]) => global.core.api?.mkdirSync(...args) | ||
|
||
/** | ||
* Removes a directory at the specified path. | ||
* @param {string} path - The path of the directory to remove. | ||
* @returns {Promise<any>} A Promise that resolves when the directory is removed successfully. | ||
*/ | ||
const rmdir: (path: string) => Promise<any> = (path) => global.core.api?.rmdir(path) | ||
const rmdirSync = (...args: any[]) => | ||
global.core.api?.rmdirSync(...args, { recursive: true, force: true }) | ||
/** | ||
* Deletes a file from the local file system. | ||
* @param {string} path - The path of the file to delete. | ||
* @returns {Promise<any>} A Promise that resolves when the file is deleted. | ||
*/ | ||
const deleteFile: (path: string) => Promise<any> = (path) => global.core.api?.deleteFile(path) | ||
const unlinkSync = (...args: any[]) => global.core.api?.unlinkSync(...args) | ||
|
||
/** | ||
* Appends data to a file at the specified path. | ||
* @param path path to the file | ||
* @param data data to append | ||
*/ | ||
const appendFile: (path: string, data: string) => Promise<any> = (path, data) => | ||
global.core.api?.appendFile(path, data) | ||
|
||
const copyFile: (src: string, dest: string) => Promise<any> = (src, dest) => | ||
global.core.api?.copyFile(src, dest) | ||
const appendFileSync = (...args: any[]) => global.core.api?.appendFileSync(...args) | ||
|
||
/** | ||
* Reads a file line by line. | ||
* @param {string} path - The path of the file to read. | ||
* @returns {Promise<any>} A promise that resolves to the lines of the file. | ||
* Copy file sync. | ||
*/ | ||
const readLineByLine: (path: string) => Promise<any> = (path) => | ||
global.core.api?.readLineByLine(path) | ||
const copyFileSync = (...args: any[]) => global.core.api?.copyFileSync(...args) | ||
|
||
// TODO: Export `dummy` fs functions automatically | ||
// Currently adding these manually | ||
export const fs = { | ||
isDirectory, | ||
writeFile, | ||
readFile, | ||
exists, | ||
listFiles, | ||
mkdir, | ||
rmdir, | ||
deleteFile, | ||
appendFile, | ||
readLineByLine, | ||
copyFile, | ||
writeFileSync, | ||
readFileSync, | ||
existsSync, | ||
readdirSync, | ||
mkdirSync, | ||
rmdirSync, | ||
unlinkSync, | ||
appendFileSync, | ||
copyFileSync, | ||
} |
Oops, something went wrong.