-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
63 lines (52 loc) · 1.74 KB
/
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
62
63
// This script used to build the tauri project
const fs = require("fs/promises");
const path = require("path");
const { exec } = require("child_process");
const execAsync = (command) => {
return new Promise((resolve) => {
exec(command, (error, stdout, stderr) => {
if (error) {
resolve(error);
return;
}
if (stderr) {
resolve(stderr);
return;
}
resolve(stdout);
});
});
};
const rootDir = path.resolve(__dirname);
const tauriDir = path.resolve(rootDir, "src-tauri");
const packageJson = require(path.resolve(rootDir, "package.json"));
const tauriConfig = require(path.resolve(tauriDir, "tauri.conf.json"));
const build = async () => {
// Step 1: Copy package.json > version to tauri.conf.json > package > version
console.log(`[build] Versions synchronizing...`);
tauriConfig.package.version = packageJson.version;
await fs.writeFile(
path.resolve(tauriDir, "tauri.conf.json"),
JSON.stringify(tauriConfig, null, 4)
);
// Step 2: Build the tauri project
console.log(`[build] Building...`);
await execAsync("npm run tauri build");
// Step 3: Copy <project>/<tauri>/target/release/bundle/msi/*.msi to rootDir without version/locale.
console.log(`[build] Copying msi file...`);
const msiFiles = await fs.readdir(
path.resolve(tauriDir, "target/release/bundle/msi")
);
const msiFile = msiFiles.find((file) => file.endsWith(".msi"));
const msiFilePath = path.resolve(
tauriDir,
"target/release/bundle/msi",
msiFile
);
const newMsiFileName = msiFile.split("_")[0] + ".msi";
const newMsiFilePath = path.resolve(rootDir, newMsiFileName);
await fs.copyFile(msiFilePath, newMsiFilePath);
console.log(`[build] Done!`);
process.exit(0);
};
build();