-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.js
33 lines (28 loc) · 926 Bytes
/
copy.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
const fs = require('fs');
const path = require('path');
const publicSrcDir = path.join(__dirname, 'public');
const distDir = path.join(__dirname, 'dist');
if (!fs.existsSync(path.join(distDir, 'public'))) {
fs.mkdirSync(path.join(distDir, 'public'), { recursive: true });
}
function copyFiles(src, dest) {
const stats = fs.statSync(src);
if (stats.isDirectory()) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
fs.readdirSync(src).forEach((file) => {
const srcFile = path.join(src, file);
const destFile = path.join(dest, file);
copyFiles(srcFile, destFile);
});
} else {
fs.copyFileSync(src, dest);
}
}
fs.readdirSync(publicSrcDir).forEach(file => {
const srcFile = path.join(publicSrcDir, file);
const destFile = path.join(distDir, 'public', file);
copyFiles(srcFile, destFile);
});
console.log('Public folders copied successfully!');