refactor: simplify setup of asset paths

This commit is contained in:
Carlos Valente
2024-10-13 13:53:55 +02:00
committed by Carlos Valente
parent e46948772e
commit 5950551da2
17 changed files with 177 additions and 144 deletions
+22 -2
View File
@@ -1,5 +1,5 @@
import { existsSync, mkdirSync } from 'fs';
import { readdir } from 'fs/promises';
import { readdir, copyFile } from 'fs/promises';
import { basename, extname, join, parse } from 'path';
/**
@@ -80,8 +80,28 @@ export function getFileNameFromPath(filePath: string): string {
}
/**
* Utility naivly checks for paths on whether it includes directories
* Utility naively checks for paths on whether it includes directories
*/
export function isPath(filePath: string): boolean {
return filePath !== basename(filePath);
}
/**
* Recursively copies a directory and its contents.
* @param {string} src - The source directory.
* @param {string} dest - The destination directory.
*/
export async function copyDirectory(src: string, dest: string) {
const entries = await readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
if (entry.isDirectory()) {
await copyDirectory(srcPath, destPath);
} else {
await copyFile(srcPath, destPath);
}
}
}