-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
release.js
66 lines (49 loc) · 1.99 KB
/
release.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
// Script from https://github.com/pedr0fontoura/fivem-appearance/blob/main/release.js
// Under MIT license
const {promises: fs} = require("fs");
const path = require("path");
const RELEASE_PATH = path.resolve(__dirname, "release");
const RESOURCE_PATH = path.resolve(RELEASE_PATH, "mojito_pdm");
const FILES = ["fxmanifest.lua", "config.json", "README.md", "LICENSE", "cars.json"];
const TYPESCRIPT_BUILD_SRC = path.resolve(__dirname, "resources", "dist");
const UI_BUILD_SRC = path.resolve(__dirname, "ui", "build");
const TYPESCRIPT_BUILD_DEST = path.resolve(RESOURCE_PATH, "resources", "dist");
const UI_BUILD_DEST = path.resolve(RESOURCE_PATH, "ui", "build");
async function copyDir(src, dest) {
await fs.mkdir(dest, {recursive: true});
const entries = await fs.readdir(src, {withFileTypes: true});
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
entry.isDirectory()
? await copyDir(srcPath, destPath)
: await fs.copyFile(srcPath, destPath);
}
}
async function execute() {
try {
await fs.access(RELEASE_PATH);
console.log("[mojito_pdm] Release folder exists");
console.log("[mojito_pdm] Removing release folder...");
await fs.rmdir(RELEASE_PATH, {recursive: true});
} catch (err) {
console.log(`[mojito_pdm] Release folder don't exist`);
}
console.log("[mojito_pdm] Creating release folder...");
await fs.mkdir(RESOURCE_PATH, {recursive: true});
console.log("[mojito_pdm] Copying files...");
await copyDir(TYPESCRIPT_BUILD_SRC, TYPESCRIPT_BUILD_DEST);
await copyDir(UI_BUILD_SRC, UI_BUILD_DEST);
for (const file of FILES) {
try {
await fs.copyFile(
path.join(__dirname, file),
path.join(RESOURCE_PATH, file)
);
} catch (err) {
console.log(err);
}
}
console.log("[mojito_pdm] Release created!");
}
execute();