-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp-file..js
38 lines (34 loc) · 1.05 KB
/
cp-file..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
const fs = require('fs');
const ncp = require('ncp').ncp;
const path = require('path');
const pathArray = [
{
sourcePath: `${process.cwd()}/src/data/GeoLite2-City.mmdb`,
destinationPath: `${process.cwd()}/dist/data/GeoLite2-City.mmdb`,
},
{
sourcePath: `${process.cwd()}/README.md`,
destinationPath: `${process.cwd()}/dist/README.md`,
},
{
sourcePath: `${process.cwd()}/LICENSE`,
destinationPath: `${process.cwd()}/dist/LICENSE`,
}
];
let count = 1;
pathArray.forEach(file => {
// Ensure the destination directory exists
const destinationDir = path.dirname(file.destinationPath);
if (!fs.existsSync(destinationDir)) {
fs.mkdirSync(destinationDir, { recursive: true });
}
// Copy the MMDB file
ncp(file.sourcePath, file.destinationPath, (err) => {
if (err) {
console.error('>>Error copying MMDB file:', err);
} else {
console.log(`>${count}/${pathArray.length} files copied successfully.`);
count++;
}
});
})