MCPcopy Create free account
hub / github.com/krausest/js-framework-benchmark / copyFolderRecursiveSync

Function copyFolderRecursiveSync

cli/copy.js:38–69  ·  view source on GitHub ↗

* Recursively copies the contents of one directory to another directory. * @param {string} sourcePath * @param {string} destinationPath * @returns

(sourcePath, destinationPath)

Source from the content-addressed store, hash-verified

36 * @returns
37 */
38function copyFolderRecursiveSync(sourcePath, destinationPath) {
39 if (!fs.existsSync(sourcePath) || !fs.lstatSync(sourcePath).isDirectory()) {
40 return;
41 }
42
43 // Check if folder needs to be created or integrated
44 if (!fs.existsSync(destinationPath)) {
45 fs.mkdirSync(destinationPath);
46 }
47
48 const files = fs.readdirSync(sourcePath);
49
50 for (const file of files) {
51 const srcFilePath = path.join(sourcePath, file);
52 const destFilePath = path.join(destinationPath, file);
53
54 if (!shouldInclude(srcFilePath)) {
55 continue;
56 }
57
58 const fileStats = fs.lstatSync(srcFilePath);
59
60 if (fileStats.isDirectory()) {
61 console.log(`copy dir ${srcFilePath}`);
62 copyFolderRecursiveSync(srcFilePath, destFilePath);
63 } else if (fileStats.isSymbolicLink()) {
64 console.log("**** LINK");
65 } else {
66 fs.copyFileSync(srcFilePath, destFilePath);
67 }
68 }
69} // It will be possible to replace with `fs.cpSync` if the version of Node.js >= 16.7.0.
70
71/**
72 * Reads the contents of the root directory and recursively copies the contents of each folder, unless they are excluded.

Callers 1

processDirectoriesFunction · 0.85

Calls 1

shouldIncludeFunction · 0.85

Tested by

no test coverage detected