-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.js
73 lines (63 loc) · 2.46 KB
/
patch.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
70
71
72
73
import * as fs from "node:fs/promises";
import * as path from "node:path";
// define constants for patches and muffon folder
const patchesFolder = "./patches";
const muffonFolder = "./muffon";
// main function to patch files
async function patchFiles() {
// read all files and directories in patches folder
const files = await fs.readdir(patchesFolder, {
withFileTypes: true,
});
// process each file/directory concurrently
await Promise.all(
files.map(async (file) => {
// construct file paths
const filePath = path.join(patchesFolder, file.name);
const muffonFilePath = path.join(muffonFolder, file.name);
// check if file is a directory
if (file.isDirectory()) {
// create corresponding directory in muffon folder
await fs.mkdir(muffonFilePath, {
recursive: true,
});
// recursively patch files in subdirectory
await patchFilesRecursive(filePath, muffonFilePath);
} else {
// copy file from patches to muffon folder
await fs.copyFile(filePath, muffonFilePath);
}
}),
);
}
// recursive function to patch files in subdirectories
async function patchFilesRecursive(srcDir, destDir) {
// read all files and directories in source directory
const files = await fs.readdir(srcDir, {
withFileTypes: true,
});
// process each file/directory concurrently
await Promise.all(
files.map(async (file) => {
// construct file paths
const srcFilePath = path.join(srcDir, file.name);
const destFilePath = path.join(destDir, file.name);
// check if file is a directory
if (file.isDirectory()) {
// create corresponding directory in destination
await fs.mkdir(destFilePath, {
recursive: true,
});
// recursively patch files in subdirectory
await patchFilesRecursive(srcFilePath, destFilePath);
} else {
// copy file from source to destination
await fs.copyFile(srcFilePath, destFilePath);
}
}),
);
}
// call main function and catch any errors
patchFiles().catch((error) => {
console.error("error patching files:", error);
});