"Add Windows installer and driver training rewards"
This commit is contained in:
27
scripts/preinstall.js
Normal file
27
scripts/preinstall.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const path = require("path");
|
||||
|
||||
const [major] = process.versions.node.split(".").map(Number);
|
||||
const supportedArchitectures = new Set(["x64", "arm64"]);
|
||||
|
||||
if (!Number.isInteger(major) || major < 22 || major >= 27) {
|
||||
console.error("");
|
||||
console.error(`[install] Unsupported Node.js version: ${process.version}`);
|
||||
console.error("[install] Install Node.js 22 or 24 LTS, then run npm install again.");
|
||||
console.error("[install] Windows: double-click windows\\install.bat or run windows\\setup.ps1.");
|
||||
console.error("");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (process.platform === "win32" && !supportedArchitectures.has(process.arch)) {
|
||||
console.error(`[install] Unsupported Windows architecture: ${process.arch}`);
|
||||
console.error("[install] Use 64-bit Windows 11 on x64 or arm64.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const projectPath = path.resolve(__dirname, "..");
|
||||
if (process.platform === "win32" && /[^\x20-\x7e]/.test(projectPath)) {
|
||||
console.warn(`[install] Warning: project path contains non-ASCII characters: ${projectPath}`);
|
||||
console.warn("[install] If a native dependency fails, move the project to C:\\Live_RC.");
|
||||
}
|
||||
|
||||
console.log(`[install] Node ${process.version}, npm lifecycle, ${process.platform}/${process.arch}: OK`);
|
||||
51
scripts/verify-install.js
Normal file
51
scripts/verify-install.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const root = path.resolve(__dirname, "..");
|
||||
|
||||
function fail(message, error) {
|
||||
console.error(`[verify] ${message}`);
|
||||
if (error) {
|
||||
console.error(`[verify] ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
if (process.platform === "win32") {
|
||||
console.error("[verify] Retry with windows\\install.bat.");
|
||||
console.error("[verify] Native fallback: run C:\\Program Files\\nodejs\\install_tools.bat as Administrator.");
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
require("express");
|
||||
} catch (error) {
|
||||
fail("Express could not be loaded.", error);
|
||||
}
|
||||
|
||||
try {
|
||||
const Database = require("better-sqlite3");
|
||||
const db = new Database(":memory:");
|
||||
const row = db.prepare("SELECT 1 AS ok").get();
|
||||
db.close();
|
||||
if (row?.ok !== 1) {
|
||||
fail("SQLite verification query returned an unexpected result.");
|
||||
}
|
||||
} catch (error) {
|
||||
fail("better-sqlite3 could not be loaded or initialized.", error);
|
||||
}
|
||||
|
||||
for (const directory of ["data", "logs"]) {
|
||||
fs.mkdirSync(path.join(root, directory), { recursive: true });
|
||||
}
|
||||
|
||||
if (process.platform === "win32") {
|
||||
const ammcDir = path.join(root, "AMMC", "windows64");
|
||||
const requiredFiles = ["ammc-amb.exe", "ammc.dll", "MyLapsSDK.dll"];
|
||||
const missingFiles = requiredFiles.filter((file) => !fs.existsSync(path.join(ammcDir, file)));
|
||||
if (missingFiles.length > 0) {
|
||||
fail(`Bundled AMMC runtime is incomplete: ${missingFiles.join(", ")}`);
|
||||
}
|
||||
console.log(`[verify] AMMC Windows runtime: ${ammcDir}`);
|
||||
}
|
||||
|
||||
console.log(`[verify] Express and SQLite: OK (${process.platform}/${process.arch}, Node ${process.version})`);
|
||||
console.log("[verify] Installation is ready. Start with: npm start");
|
||||
Reference in New Issue
Block a user