@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
32 lines (31 loc) • 1.07 kB
JavaScript
import { copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from "fs";
import { join } from "path";
/**
* @param {string} src
* @param {string} dest
* @param {boolean} override
* @param {{count:number} | undefined} ctx
*/
export function copyFilesSync(src, dest, override = true, ctx = undefined) {
if (dest === null) {
console.log(`[needle-copy] - Copy ${src} to ${dest} - dest is null`)
return;
}
let exists = existsSync(src);
let stats = exists && statSync(src);
let isDirectory = exists && typeof stats != "boolean" && stats.isDirectory();
if (isDirectory) {
if (!existsSync(dest))
mkdirSync(dest, { recursive: true });
readdirSync(src).forEach(function (childItemName) {
// recurse
copyFilesSync(join(src, childItemName), join(dest, childItemName), override, ctx);
});
}
else if (override || !existsSync(dest)) {
if (ctx) {
ctx.count += 1;
}
copyFileSync(src, dest);
}
};