Add custom cursor packs and harden native postinstall builds

This commit is contained in:
insomniachooman
2026-03-26 22:39:18 +06:00
parent 1826cfec3a
commit 157af5f083
22 changed files with 635 additions and 352 deletions
+45 -19
View File
@@ -1,5 +1,5 @@
import { execSync } from "node:child_process";
import { existsSync, mkdirSync } from "node:fs";
import { existsSync, mkdirSync, rmSync } from "node:fs";
import path from "node:path";
const projectRoot = process.cwd();
@@ -25,29 +25,46 @@ function findCmake() {
// not on PATH
}
// VS 2022 bundled CMake
const vsEditions = ["Community", "Professional", "Enterprise", "BuildTools"];
for (const edition of vsEditions) {
const cmakePath = path.join(
"C:",
"Program Files",
"Microsoft Visual Studio",
"2022",
edition,
"Common7",
"IDE",
"CommonExtensions",
"Microsoft",
"CMake",
"CMake",
"bin",
"cmake.exe",
);
const standaloneCmakePaths = [
path.join("C:", "Program Files", "CMake", "bin", "cmake.exe"),
path.join("C:", "Program Files (x86)", "CMake", "bin", "cmake.exe"),
];
for (const cmakePath of standaloneCmakePaths) {
if (existsSync(cmakePath)) {
return `"${cmakePath}"`;
}
}
// VS 2022 bundled CMake
const vsRoots = [
path.join("C:", "Program Files", "Microsoft Visual Studio"),
path.join("C:", "Program Files (x86)", "Microsoft Visual Studio"),
];
const vsEditions = ["Community", "Professional", "Enterprise", "BuildTools"];
const vsVersions = ["2022", "2019"];
for (const root of vsRoots) {
for (const version of vsVersions) {
for (const edition of vsEditions) {
const cmakePath = path.join(
root,
version,
edition,
"Common7",
"IDE",
"CommonExtensions",
"Microsoft",
"CMake",
"CMake",
"bin",
"cmake.exe",
);
if (existsSync(cmakePath)) {
return `"${cmakePath}"`;
}
}
}
}
return null;
}
@@ -60,9 +77,17 @@ if (!cmake) {
}
mkdirSync(buildDir, { recursive: true });
const cacheFile = path.join(buildDir, "CMakeCache.txt");
const cacheDir = path.join(buildDir, "CMakeFiles");
function clearCmakeCache() {
rmSync(cacheFile, { force: true });
rmSync(cacheDir, { recursive: true, force: true });
}
console.log("[build-cursor-monitor] Configuring CMake...");
try {
clearCmakeCache();
execSync(`${cmake} .. -G "Visual Studio 17 2022" -A x64`, {
cwd: buildDir,
stdio: "inherit",
@@ -71,6 +96,7 @@ try {
} catch {
console.log("[build-cursor-monitor] VS 2022 generator not found, trying VS 2019...");
try {
clearCmakeCache();
execSync(`${cmake} .. -G "Visual Studio 16 2019" -A x64`, {
cwd: buildDir,
stdio: "inherit",
+45 -8
View File
@@ -1,5 +1,5 @@
import { execSync } from 'node:child_process';
import { mkdirSync, existsSync } from 'node:fs';
import { mkdirSync, existsSync, rmSync } from 'node:fs';
import path from 'node:path';
const projectRoot = process.cwd();
@@ -25,18 +25,46 @@ function findCmake() {
// not on PATH
}
// VS 2022 bundled CMake
const vsEditions = ['Community', 'Professional', 'Enterprise', 'BuildTools'];
for (const edition of vsEditions) {
const cmakePath = path.join(
'C:', 'Program Files', 'Microsoft Visual Studio', '2022', edition,
'Common7', 'IDE', 'CommonExtensions', 'Microsoft', 'CMake', 'CMake', 'bin', 'cmake.exe'
);
const standaloneCmakePaths = [
path.join('C:', 'Program Files', 'CMake', 'bin', 'cmake.exe'),
path.join('C:', 'Program Files (x86)', 'CMake', 'bin', 'cmake.exe'),
];
for (const cmakePath of standaloneCmakePaths) {
if (existsSync(cmakePath)) {
return `"${cmakePath}"`;
}
}
// VS 2022 bundled CMake
const vsRoots = [
path.join('C:', 'Program Files', 'Microsoft Visual Studio'),
path.join('C:', 'Program Files (x86)', 'Microsoft Visual Studio'),
];
const vsEditions = ['Community', 'Professional', 'Enterprise', 'BuildTools'];
const vsVersions = ['2022', '2019'];
for (const root of vsRoots) {
for (const version of vsVersions) {
for (const edition of vsEditions) {
const cmakePath = path.join(
root,
version,
edition,
'Common7',
'IDE',
'CommonExtensions',
'Microsoft',
'CMake',
'CMake',
'bin',
'cmake.exe'
);
if (existsSync(cmakePath)) {
return `"${cmakePath}"`;
}
}
}
}
return null;
}
@@ -47,9 +75,17 @@ if (!cmake) {
}
mkdirSync(buildDir, { recursive: true });
const cacheFile = path.join(buildDir, 'CMakeCache.txt');
const cacheDir = path.join(buildDir, 'CMakeFiles');
function clearCmakeCache() {
rmSync(cacheFile, { force: true });
rmSync(cacheDir, { recursive: true, force: true });
}
console.log('[build-windows-capture] Configuring CMake...');
try {
clearCmakeCache();
execSync(`${cmake} .. -G "Visual Studio 17 2022" -A x64`, {
cwd: buildDir,
stdio: 'inherit',
@@ -58,6 +94,7 @@ try {
} catch {
console.log('[build-windows-capture] VS 2022 generator not found, trying VS 2019...');
try {
clearCmakeCache();
execSync(`${cmake} .. -G "Visual Studio 16 2019" -A x64`, {
cwd: buildDir,
stdio: 'inherit',
+53
View File
@@ -0,0 +1,53 @@
import { spawnSync } from "node:child_process";
const npmExecPath = process.env.npm_execpath;
const hasNpmExecPath = typeof npmExecPath === "string" && npmExecPath.length > 0;
const npmInvoker = hasNpmExecPath
? {
command: process.execPath,
argsPrefix: [npmExecPath],
shell: false,
}
: {
command: process.platform === "win32" ? "npm.cmd" : "npm",
argsPrefix: [],
shell: process.platform === "win32",
};
function runScript(scriptName) {
console.log(`[postinstall] Running npm script: ${scriptName}`);
const result = spawnSync(npmInvoker.command, [...npmInvoker.argsPrefix, "run", scriptName], {
stdio: "inherit",
env: process.env,
shell: npmInvoker.shell,
});
if (result.error) {
console.error(
`[postinstall] Failed to start "${scriptName}" (${result.error.message}).`,
);
return false;
}
if (result.signal) {
console.error(`[postinstall] "${scriptName}" was terminated by signal ${result.signal}.`);
return false;
}
if (result.status !== 0) {
console.error(
`[postinstall] "${scriptName}" exited with code ${result.status}.`,
);
return false;
}
return true;
}
if (!runScript("rebuild:native")) {
process.exit(1);
}
if (!runScript("build:platform-native-helpers")) {
process.exit(1);
}