-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.mjs
More file actions
58 lines (47 loc) · 1.73 KB
/
esbuild.mjs
File metadata and controls
58 lines (47 loc) · 1.73 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
51
52
53
54
55
56
57
58
import { accessSync, constants as fsconsts, mkdirSync, readdirSync, rmSync } from "node:fs";
import { copyFile } from "node:fs/promises";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
/** @typedef {import("fs").Dirent} Dirent */
/** @typedef {import("esbuild").BuildResult} BuildResult */
const modFolders = ["actions", "events", "extensions"];
/** @type {Promise<void>[]} */
const copyTasks = [];
/** @type {Promise<BuildResult>[]} */
const buildTasks = [];
for (const modFolder of modFolders) {
const modFiles = readdirSync(modFolder).filter(isMod);
rmSync(join("dist", modFolder), { recursive: true, force: true });
mkdirSync(join("dist", modFolder), { recursive: true });
for (const modFile of modFiles) {
const buildFile = join(modFolder, modFile.replace(/\.mod\.js$/, ".build.mjs"));
try {
accessSync(buildFile, fsconsts.R_OK);
// Execute build file
buildTasks.push(import(pathToFileURL(buildFile).toString()).then(file => file.build()));
} catch (_) {
// No build file, copy raw file
copyTasks.push(copyFile(join(modFolder, modFile), join("dist", modFolder, modFile)));
}
}
}
(async() => {
await Promise.all(copyTasks);
const buildResults = await Promise.all(buildTasks);
for (const result of buildResults) {
if (result.errors.length > 0) {
console.error(result.errors);
}
if (result.warnings.length > 0) {
console.error(result.warnings);
}
}
})();
/**
* Check if a file is a mod file
* @param {string} file File name
* @returns {boolean} Whether the file is a mod file
*/
function isMod(file) {
return file.endsWith(".mod.js");
}