MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / copyRecursive

Function copyRecursive

scripts/utils.js:72–102  ·  view source on GitHub ↗
(src, dest)

Source from the content-addressed store, hash-verified

70}
71
72export function copyRecursive(src, dest) {
73 try {
74 if (isFile(src)) {
75 copy(src, dest);
76 return;
77 }
78 const targetDirPath = path.resolve(dest, path.basename(src));
79 if (!fs.existsSync(targetDirPath)) {
80 fs.mkdirSync(targetDirPath);
81 }
82 if (isDir(src)) {
83 const files = fs.readdirSync(src);
84 for (let i = 0; i < files.length; i++) {
85 const childPath = path.resolve(src, files[i]);
86 if (isDir(childPath)) {
87 copyRecursive(childPath, targetDirPath);
88 } else {
89 const targetFilePath = path.resolve(
90 targetDirPath,
91 path.basename(childPath),
92 );
93 fs.writeFileSync(targetFilePath, fs.readFileSync(childPath));
94 }
95 }
96 }
97 } catch (error) {
98 throw new Error(
99 `Received an error: [${error}] while trying to copy: ${src} -> ${dest}`,
100 );
101 }
102}
103
104export function removeRecursive(filePath) {
105 try {

Callers

nothing calls this directly

Calls 4

isFileFunction · 0.85
copyFunction · 0.85
isDirFunction · 0.85
resolveMethod · 0.65

Tested by

no test coverage detected