-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathpreprocess.js
More file actions
50 lines (42 loc) · 1.3 KB
/
preprocess.js
File metadata and controls
50 lines (42 loc) · 1.3 KB
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
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const srcDir = path.resolve(__dirname, '../../assets');
const destDir = path.resolve(__dirname, '../src/assets');
function deleteDirRecursive(dirPath) {
if (fs.existsSync(dirPath)) {
for (const entry of fs.readdirSync(dirPath)) {
const entryPath = path.join(dirPath, entry);
const stats = fs.lstatSync(entryPath);
if (stats.isDirectory()) {
deleteDirRecursive(entryPath);
} else {
fs.unlinkSync(entryPath);
}
}
fs.rmdirSync(dirPath);
}
}
function copyDirRecursive(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
for (const entry of fs.readdirSync(src)) {
const srcPath = path.join(src, entry);
const destPath = path.join(dest, entry);
const stats = fs.lstatSync(srcPath);
if (stats.isDirectory()) {
copyDirRecursive(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
import('../mta_highlighting/generate-lua-tmlanguage.js')
.then(() => {
deleteDirRecursive(destDir);
copyDirRecursive(srcDir, destDir);
// console.log(`Copied assets from "${srcDir}" to "${destDir}".`);
});