1import fs from 'fs';
2import path from 'path';
3
4/** A basic function that copies a single file to another file location. */
5export async function copyFilePathToPathAsync(src: string, dest: string): Promise<void> {
6  const srcFile = await fs.promises.readFile(src);
7  await fs.promises.mkdir(path.dirname(dest), { recursive: true });
8  await fs.promises.writeFile(dest, srcFile);
9}
10
11/** Remove a single file (not directory). Returns `true` if a file was actually deleted. */
12export function removeFile(filePath: string): boolean {
13  try {
14    fs.unlinkSync(filePath);
15    return true;
16  } catch (error: any) {
17    // Skip if the remove did nothing.
18    if (error.code === 'ENOENT') {
19      return false;
20    }
21    throw error;
22  }
23}
24