-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbuild.mjs
More file actions
74 lines (64 loc) · 1.87 KB
/
build.mjs
File metadata and controls
74 lines (64 loc) · 1.87 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import fs from "fs/promises";
import { exec } from "child_process";
function runCommand(command, args = []) {
return new Promise((resolve, reject) => {
const commandArgs = args.join(",").replace(",", " ");
exec(`${command} ${commandArgs}`, async (err, stdout, stderr) => {
if (err) {
reject(`"Problem running ${command} ${commandArgs} \n ${stdout}"`)
return;
}
if (stdout.length > 0) {
console.log(stdout);
} else if (stderr.length > 0) {
console.log(stderr);
}
resolve({ stdout, stderr })
});
})
}
async function copyDir (src, dest) {
await fs.mkdir(dest, { recursive: true });
let entries = await fs.readdir(src, { withFileTypes: true });
for (let entry of entries) {
let srcPath = path.join(src, entry.name);
let destPath = path.join(dest, entry.name);
entry.isDirectory() ?
await copyDir(srcPath, destPath) :
await fs.copyFile(srcPath, destPath);
}
}
async function exists(path) {
try {
await fs.access(SYSTEM_DIR);
return true;
} catch (error) {
return false;
}
}
(async function () {
const BUILD_DIR = "./Content";
const SRC_DIR = "./src";
const SYSTEM_DIR = `${BUILD_DIR}/Datas/Scripts/System`;
const startTime = Date.now();
try {
if (await exists(SYSTEM_DIR)) {
await fs.rmdir(SYSTEM_DIR, {
recursive: true
});
}
if (process.env.CI || process.env.PRODUCTION) {
await runCommand("npx", ["tsc"]);
} else {
await runCommand("npx", ["tsc", "--incremental"]);
}
await runCommand("module-fix.sh", [], true);
await fs.copyFile(`${ SRC_DIR }/Definitions.d.ts`, `${ SYSTEM_DIR }/Definitions.d.ts`)
const endTime = Date.now() - startTime;
console.log(
`Compilation completed in ${ Math.floor(endTime / 1000) } seconds`
);
} catch (error) {
console.error(error);
}
})();