MCPcopy Create free account
hub / github.com/esengine/esengine / copyJsFilesRecursively

Function copyJsFilesRecursively

packages/editor-app/vite.config.ts:17–38  ·  view source on GitHub ↗

* 递归复制目录中的 JS 文件

(srcDir: string, destDir: string, relativePath: string = '')

Source from the content-addressed store, hash-verified

15 * 递归复制目录中的 JS 文件
16 */
17 function copyJsFilesRecursively(srcDir: string, destDir: string, relativePath: string = '') {
18 const entries = fs.readdirSync(srcDir, { withFileTypes: true });
19
20 for (const entry of entries) {
21 const srcPath = path.join(srcDir, entry.name);
22 const relPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
23
24 if (entry.isDirectory()) {
25 // 递归复制子目录
26 const subDestDir = path.join(destDir, entry.name);
27 if (!fs.existsSync(subDestDir)) {
28 fs.mkdirSync(subDestDir, { recursive: true });
29 }
30 copyJsFilesRecursively(srcPath, subDestDir, relPath);
31 } else if (entry.name.endsWith('.js')) {
32 // 复制 JS 文件
33 const destPath = path.join(destDir, entry.name);
34 fs.copyFileSync(srcPath, destPath);
35 console.log(`[copy-plugin-modules] Copied ${relPath}`);
36 }
37 }
38 }
39
40 return {
41 name: 'copy-plugin-modules',

Callers 1

writeBundleFunction · 0.85

Calls 2

joinMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected