-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy_data_to_dist.cjs
51 lines (42 loc) · 1.27 KB
/
copy_data_to_dist.cjs
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
42
43
44
45
46
47
48
49
50
51
const fs = require('fs');
const path = require('path');
const copyDir = (src, dest, callback) => {
const copy = (copySrc, copyDest) => {
fs.readdir(copySrc, (err, list) => {
if (err) return callback(err);
list.forEach((item) => {
const srcItem = path.resolve(copySrc, item);
const destItem = path.resolve(copyDest, item);
fs.stat(srcItem, (err, stat) => {
if (err) return callback(err);
if (stat.isFile()) {
fs.createReadStream(srcItem).pipe(fs.createWriteStream(destItem));
} else if (stat.isDirectory()) {
fs.mkdirSync(destItem, { recursive: true });
copy(srcItem, destItem);
}
});
});
});
};
fs.access(dest, (err) => {
if (err) fs.mkdirSync(dest, { recursive: true });
copy(src, dest);
});
};
const copyFile = (sourcePath, destinationPath) => {
if (!fs.existsSync(destinationPath)) {
fs.mkdirSync(destinationPath, { recursive: true });
}
const fileName = path.basename(sourcePath);
const destinationFile = path.join(destinationPath, fileName);
fs.copyFile(sourcePath, destinationFile, (err) => {
if (err) {
console.error('Error copying file:', err);
} else {
console.log('File copied successfully!');
}
});
};
copyDir('./data', './dist/data');
// copyFile('./builder.config.js', './dist/');