forked from Nexus-Mods/Vortex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreinstall.js
More file actions
148 lines (125 loc) · 3.65 KB
/
preinstall.js
File metadata and controls
148 lines (125 loc) · 3.65 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
// Preinstall script for Vortex
// Handles git submodule initialization and building FOMOD installer dependencies
const { spawn } = require("child_process");
const path = require("path");
const packageManager = "yarn";
// Detect if we're running in an offline build environment (e.g., Flatpak)
const isOfflineBuild = () => {
return (
process.env.YARN_OFFLINE_MIRROR || process.env.npm_config_offline === "true"
);
};
// Get yarn install arguments based on environment
const getInstallArgs = () => {
const args = ["install"];
if (isOfflineBuild()) {
args.push("--offline");
}
return args;
};
/**
* Runs a command and returns a promise that resolves when the command completes
* @param {string} command - The command to run
* @param {string[]} args - Command arguments
* @param {object} options - Spawn options
* @returns {Promise<void>}
*/
function runCommand(command, args, options = {}) {
return new Promise((resolve, reject) => {
console.log(`Running: ${command} ${args.join(" ")}`);
const proc = spawn(command, args, {
shell: true,
stdio: "inherit",
...options,
});
proc.on("exit", (code) => {
if (code !== 0) {
reject(
new Error(
`Command failed with exit code ${code}: ${command} ${args.join(" ")}`,
),
);
} else {
resolve();
}
});
proc.on("error", (err) => {
reject(err);
});
});
}
/**
* Build FOMOD IPC TypeScript project
* @returns {Promise<void>}
*/
async function buildFomodIPC() {
const buildConfig = process.env.VORTEX_BUILD_CONFIG || "Release";
console.log(`Building FOMOD IPC TypeScript (${buildConfig})...`);
const fomodIPCPath = path.join(
__dirname,
"extensions",
"fomod-installer",
"src",
"ModInstaller.IPC.TypeScript",
);
try {
const pkgcli =
process.platform === "win32" ? `${packageManager}.cmd` : packageManager;
// Install dependencies
await runCommand(pkgcli, getInstallArgs(), { cwd: fomodIPCPath });
// Build project
await runCommand(pkgcli, ["build", buildConfig], { cwd: fomodIPCPath });
console.log("FOMOD IPC built successfully");
} catch (err) {
console.error("Failed to build FOMOD IPC:", err.message);
throw err;
}
}
/**
* Build FOMOD Native TypeScript project
* @returns {Promise<void>}
*/
async function buildFomodNative() {
const buildConfig = process.env.VORTEX_BUILD_CONFIG || "Release";
console.log(`Building FOMOD Native TypeScript (${buildConfig})...`);
const fomodNativePath = path.join(
__dirname,
"extensions",
"fomod-installer",
"src",
"ModInstaller.Native.TypeScript",
);
try {
const pkgcli =
process.platform === "win32" ? `${packageManager}.cmd` : packageManager;
// Build native components with configuration
await runCommand(pkgcli, ["build-native", buildConfig], {
cwd: fomodNativePath,
});
// Install dependencies
await runCommand(pkgcli, getInstallArgs(), { cwd: fomodNativePath });
// Build project with configuration
await runCommand(pkgcli, ["build", buildConfig], { cwd: fomodNativePath });
console.log(`FOMOD Native built successfully (${buildConfig})`);
} catch (err) {
console.error("Failed to build FOMOD Native:", err.message);
throw err;
}
}
/**
* Main preinstall routine
*/
async function main() {
console.log("Starting preinstall script...");
try {
// Build FOMOD IPC
await buildFomodIPC();
// Build FOMOD Native
await buildFomodNative();
console.log("Preinstall completed successfully");
} catch (err) {
console.error("Preinstall failed:", err.message);
process.exit(1);
}
}
main();