-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpages.js
41 lines (35 loc) · 1.29 KB
/
pages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const fs = require('fs');
const path = require('path');
// 定义源文件夹和目标文件夹
const sourceDir = path.join(__dirname, 'public');
const targetDir = path.join(__dirname, 'dist');
// 确保目标文件夹存在
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
// 递归复制文件夹内容
function copyFolderRecursive(source, target) {
// 读取源文件夹内容
const files = fs.readdirSync(source);
for (const file of files) {
const sourcePath = path.join(source, file);
const targetPath = path.join(target, file);
// 判断是文件还是文件夹
const stat = fs.statSync(sourcePath);
if (stat.isDirectory()) {
// 如果是文件夹,递归复制
if (!fs.existsSync(targetPath)) {
fs.mkdirSync(targetPath, { recursive: true });
}
copyFolderRecursive(sourcePath, targetPath);
} else {
// 如果是文件,直接复制
fs.copyFileSync(sourcePath, targetPath);
console.log(`Copied: ${sourcePath} -> ${targetPath}`);
}
}
}
// 执行复制
copyFolderRecursive(sourceDir, targetDir);
copyFolderRecursive("fake-api-server", targetDir);
console.log('All files copied from public to dist!');