mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 21:03:29 +00:00
refactor: simplify setup of asset paths
This commit is contained in:
committed by
Carlos Valente
parent
e46948772e
commit
5950551da2
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user