-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_move.js
69 lines (59 loc) · 1.96 KB
/
build_move.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
57
58
59
60
61
62
63
64
65
66
67
68
69
const fs = require('fs');
const path = require('path');
function copyFileSync(source, target) {
let targetFile = target;
// If target is a directory, a new file with the same name will be created in it
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source));
}
}
fs.writeFileSync(targetFile, fs.readFileSync(source));
}
function copyFolderRecursiveSync(source, target) {
let files = [];
// Check if folder needs to be created or integrated
const targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder, { recursive: true });
}
// Copy
if (fs.lstatSync(source).isDirectory()) {
files = fs.readdirSync(source);
files.forEach((file) => {
const curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder);
} else {
copyFileSync(curSource, targetFolder);
}
});
}
}
// Create build directory if it doesn't exist
const buildDir = 'build';
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir, { recursive: true });
}
// Define the files and folders to copy
const itemsToCopy = [
'static',
'src',
'DigSig.php',
'LICENSE.md',
'composer.json'
];
// Copy each item to the build directory
itemsToCopy.forEach((item) => {
const fullPath = path.resolve(item);
if (fs.existsSync(fullPath)) {
if (fs.lstatSync(fullPath).isDirectory()) {
copyFolderRecursiveSync(fullPath, buildDir);
} else {
copyFileSync(fullPath, path.join(buildDir, path.basename(item)));
}
} else {
console.warn(`Warning: ${item} does not exist and will not be copied.`);
}
});
console.log('Files and folders have been copied to the build directory.');