-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-build.js
61 lines (48 loc) · 1.73 KB
/
pre-build.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
import { randomBytes } from "crypto";
import { promises as fs, mkdirSync, rm, rmSync } from "fs";
import { promisify } from "util";
import { exec } from "child_process";
const execProc = promisify(exec);
try {
rmSync("./src-tauri/res/", { recursive: true }, (_) => {});
} catch {}
mkdirSync("./src-tauri/res/", { recursive: true });
async function generateCompressibleBinaryFile(filename, sizeInMB) {
const fileBuffer = Buffer.alloc(Math.round(sizeInMB * 1024 * 1024));
const blockSize = 7;
for (let i = 0; i < fileBuffer.length; i += blockSize) {
const byte = Math.round(Math.random() * 1000);
for (let j = 0; j < blockSize; j++) {
fileBuffer[i + j] = byte;
}
}
await fs.writeFile(filename, fileBuffer, "binary");
}
(async () => {
await generateCompressibleBinaryFile("./src-tauri/res/first.db", 680);
})();
(async () => {
await generateCompressibleBinaryFile("./src-tauri/res/second.bin", 0.2);
})();
(async () => {
await generateCompressibleBinaryFile("./src-tauri/res/third.db", 650);
})();
(async () => {
await generateCompressibleBinaryFile("./src-tauri/res/fourth.db", 0.15);
})();
const getTargetTriple = async () => {
const { stdout } = await execProc("rustc -vV");
const targetTriple = /host: (\S+)/g.exec(stdout)[1];
if (!targetTriple) {
throw new Error("Failed to determine platform target triple");
}
return targetTriple;
};
(async () => {
const buf = randomBytes(61 * 1024 * 1024);
const targetTriple = await getTargetTriple();
const name = "app";
const ext = process.platform === "win32" ? ".exe" : "";
const appName = `${name}-${targetTriple}${ext}`;
await fs.writeFile(`./src-tauri/res/${appName}`, buf, "binary");
})();