Repository navigation
Expand file tree
/
Copy pathpostbuild.js
More file actions
161 lines (141 loc) 路 6.03 KB
/
Copy pathpostbuild.js
File metadata and controls
161 lines (141 loc) 路 6.03 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import fs from "node:fs";
import path from "node:path";
const args = process.argv.slice(2);
const buildType = args[0];
// cef-dll-sys drops the CEF runtime next to the exe, but only when its build script runs
const targetDir = path.join(process.cwd(), "target", buildType);
const targetResourcesDir = path.join(targetDir, "resources");
const distDir = path.join(targetDir, "dist");
const linux = process.platform === "linux";
const windowsRuntimeFiles = [
"libcef.dll",
"chrome_elf.dll",
"d3dcompiler_47.dll",
"dxcompiler.dll",
"dxil.dll",
"libEGL.dll",
"libGLESv2.dll",
"vk_swiftshader.dll",
"vk_swiftshader_icd.json",
"vulkan-1.dll",
"icudtl.dat",
"resources.pak",
"chrome_100_percent.pak",
"chrome_200_percent.pak",
"v8_context_snapshot.bin",
];
const linuxRuntimeFiles = [
"libcef.so",
"libEGL.so",
"libGLESv2.so",
"libvk_swiftshader.so",
"libvulkan.so.1",
"vk_swiftshader_icd.json",
"icudtl.dat",
"resources.pak",
"chrome_100_percent.pak",
"chrome_200_percent.pak",
"v8_context_snapshot.bin",
];
const cefRuntimeFiles = linux ? linuxRuntimeFiles : windowsRuntimeFiles;
const vcRuntimeFiles = linux ? [] : ["msvcp140.dll", "vcruntime140.dll", "vcruntime140_1.dll"];
// the windows dll crates, not built on linux
const hostFiles = linux ? [] : ["render.dll"];
/**
* @param {string} source
* @param {string} destination
* @return {boolean}
*/
function copyIfExists(source, destination){
if (!fs.existsSync(source)) return false;
fs.mkdirSync(path.dirname(destination), { recursive: true });
fs.copyFileSync(source, destination);
return true;
}
/**
* @param {string} source
* @param {string} destination
*/
function copyDirAll(source, destination){
fs.mkdirSync(destination, { recursive: true });
for (const entry of fs.readdirSync(source, { withFileTypes: true })){
const sourcePath = path.join(source, entry.name);
const destPath = path.join(destination, entry.name);
if (entry.isDirectory()) copyDirAll(sourcePath, destPath);
else fs.copyFileSync(sourcePath, destPath);
}
}
/**
* CEF distribution matching the cef-dll-sys version in Cargo.lock, fallback source for the runtime
*
* @return {string|null}
*/
function findCefDistribution(){
const lock = fs.readFileSync(path.join(process.cwd(), "Cargo.lock"), "utf8");
const cefVersion = /name = "cef-dll-sys"\r?\nversion = "[^"+]+\+([^"]+)"/.exec(lock)?.[1];
const buildDir = path.join(targetDir, "build");
if (!cefVersion || !fs.existsSync(buildDir)) return null;
const matches = [];
for (const entry of fs.readdirSync(buildDir)){
if (!entry.startsWith("cef-dll-sys-")) continue;
const dir = path.join(buildDir, entry, "out", linux ? "cef_linux_x86_64" : "cef_windows_x86_64");
const archive = path.join(dir, "archive.json");
if (!fs.existsSync(archive)) continue;
if (!String(JSON.parse(fs.readFileSync(archive, "utf8")).name).startsWith(`cef_binary_${cefVersion}+`)) continue;
matches.push({ dir, time: fs.statSync(archive).mtimeMs });
}
return matches.sort((a, b) => b.time - a.time)[0]?.dir ?? null;
}
try {
fs.mkdirSync(targetResourcesDir, { recursive: true });
const cefDistribution = findCefDistribution();
if (cefDistribution){
for (const file of cefRuntimeFiles){
const destination = path.join(targetDir, file);
if (!fs.existsSync(destination)) copyIfExists(path.join(cefDistribution, file), destination);
}
const locales = path.join(targetDir, "locales");
if (!fs.existsSync(locales)) copyDirAll(path.join(cefDistribution, "locales"), locales);
}
else console.warn("No CEF distribution for the cef-dll-sys version in Cargo.lock found in the build dir.");
for (const file of vcRuntimeFiles){
const destination = path.join(targetDir, file);
if (!fs.existsSync(destination)) copyIfExists(path.join(process.cwd(), "resources", "vcredist", file), destination);
}
copyIfExists(path.join(process.cwd(), "target", "bundle_version"), path.join(targetResourcesDir, "bundle_version"));
copyIfExists(path.join(process.cwd(), "target", "bundle.js"), path.join(targetResourcesDir, "bundle.js"));
if (!linux && !copyIfExists(path.join(targetDir, "obs_kute_capture.dll"), path.join(targetResourcesDir, "obs-kute-capture.dll"))){
console.warn("OBS plugin was not built; skipping bundled plugin copy.");
}
// our patched libcef (aim freeze fixes) over the stock one. same CEF version, so headers and wrapper still match
const patchedCefDir = path.join(process.cwd(), "resources", linux ? "cef-linux" : "cef");
if (fs.existsSync(patchedCefDir)){
for (const file of fs.readdirSync(patchedCefDir)){
const source = path.join(patchedCefDir, file);
// no git lfs = tiny pointer file, never ship that
if (fs.statSync(source).size < 1024){
console.warn(`${file} in resources/cef is a git lfs pointer, run "git lfs pull". Keeping the stock file.`);
continue;
}
fs.copyFileSync(source, path.join(targetDir, file));
}
}
// installer payload, everything but the exe (the wxs points at that directly)
fs.rmSync(distDir, { recursive: true, force: true });
fs.mkdirSync(distDir, { recursive: true });
// missing file = installer that can't start, so fail instead of warn
const missing = [...cefRuntimeFiles, ...vcRuntimeFiles, ...hostFiles].filter(
(file) => !copyIfExists(path.join(targetDir, file), path.join(distDir, file)),
);
if (fs.existsSync(path.join(targetDir, "locales"))) copyDirAll(path.join(targetDir, "locales"), path.join(distDir, "locales"));
else missing.push("locales/");
copyDirAll(targetResourcesDir, path.join(distDir, "resources"));
if (missing.length > 0){
console.error(`Missing from ${targetDir}: ${missing.join(", ")}`);
process.exitCode = 1;
}
}
catch (error){
console.error("cannot copy", error);
process.exitCode = 1;
}