-
Notifications
You must be signed in to change notification settings - Fork 0
/
copyDirForRelease.js
56 lines (52 loc) · 1.54 KB
/
copyDirForRelease.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const fs = require('fs');
const path = require('path');
// Define the source and destination directories
const srcDir = './';
const destDir = 'prod';
// Copy the *.production.min.js files from srcDir/dist
const distDir = path.join(srcDir, 'dist');
fs.readdir(distDir, (err, files) => {
if (err) {
console.error(err);
} else {
files.forEach(file => {
if (
file.endsWith('.production.min.js') ||
file.endsWith('.production.min.js.map')
) {
const srcFile = path.join(distDir, file);
const destFile = path.join(destDir, file);
fs.copyFile(srcFile, destFile, err => {
if (err) {
console.error(err);
} else {
console.log(`File ${srcFile} copied successfully.`);
}
});
}
});
}
});
// Copy the dist/*.d.ts files
const copyDirRecursive = (src, dest) => {
fs.mkdirSync(dest, { recursive: true });
const files = fs.readdirSync(src);
files.forEach(file => {
const srcFile = path.join(src, file);
const destFile = path.join(dest, file);
if (fs.statSync(srcFile).isDirectory()) {
copyDirRecursive(srcFile, destFile);
} else {
if (srcFile.endsWith('.d.ts')) {
fs.copyFile(srcFile, destFile, err => {
if (err) {
console.error(err);
} else {
console.log(`File ${srcFile} copied successfully.`);
}
});
}
}
});
};
copyDirRecursive(path.join(srcDir, 'dist'), path.join(destDir));