import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync } from "node:fs";
import { basename, extname, join } from "node:path";
//#region src/shared/tools/copy-assets.ts
/**
* List of allowed file extensions
*/
var fileExtensionWhitelist = [
	".woff2",
	".svg",
	".img",
	".jpg",
	".jpeg",
	".png"
];
/**
* Copy file from source to destination
*
* @param source - Source path
* @param target - Destination path
* @returns
*/
function copyFileSync$1(source, target) {
	let targetFile = target;
	if (existsSync(target)) {
		if (lstatSync(target).isDirectory()) targetFile = join(target, basename(source));
	}
	if (!fileExtensionWhitelist.includes(extname(source))) return;
	copyFileSync(source, targetFile);
}
/**
* Recursively copy directory from source to destination
*
* @param source - source directory
* @param target - destination directory
*/
function copyFolderRecursiveSync(source, target) {
	let files = [];
	const targetFolder = join(target, basename(source));
	if (!existsSync(targetFolder)) mkdirSync(targetFolder);
	if (lstatSync(source).isDirectory()) {
		files = readdirSync(source);
		for (const file of files) {
			const curSource = join(source, file);
			if (lstatSync(curSource).isDirectory()) copyFolderRecursiveSync(curSource, targetFolder);
			else copyFileSync$1(curSource, targetFolder);
		}
	}
}
/**
* Copy asset directory from source to destination
*
* @param assetDir - destination directory
* @param assets - source directory
*/
var copyAssets = (assetDir, assets) => {
	if (!existsSync(assetDir)) mkdirSync(assetDir, { recursive: true });
	copyFolderRecursiveSync(assets, assetDir);
};
//#endregion
export { copyAssets };
