-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-build.js
41 lines (33 loc) · 967 Bytes
/
post-build.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 path = require("path")
const fs = require("fs")
const sourceDir = "dist/library"
const targetDir = "dist"
function copyFilesRecursively(source, target) {
fs.readdirSync(source).forEach((file) => {
const sourceFile = path.join(source, file)
const targetFile = path.join(target, file)
if (fs.lstatSync(sourceFile).isDirectory()) {
if (!fs.existsSync(targetFile)) {
fs.mkdirSync(targetFile)
}
copyFilesRecursively(sourceFile, targetFile)
} else {
fs.copyFileSync(sourceFile, targetFile)
}
})
}
function deleteFilesRecursively(directory) {
if (fs.existsSync(directory)) {
fs.readdirSync(directory).forEach((file, index) => {
const currentPath = path.join(directory, file)
if (fs.lstatSync(currentPath).isDirectory()) {
deleteFilesRecursively(currentPath)
} else {
fs.unlinkSync(currentPath)
}
})
fs.rmdirSync(directory)
}
}
copyFilesRecursively(sourceDir, targetDir)
deleteFilesRecursively(sourceDir)