mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Replace ESLint, typescript-eslint, eslint-plugin-node and the flat config helpers with vite-plus, which runs Oxlint for vp lint. The rules are carried over from eslint.config.mjs by @oxlint/migrate into the lint section of the root vite.config.ts. The formatting rules ESLint deprecated run as @stylistic rules through Oxlint's JS plugin support, and disable comments naming them are updated to the @stylistic names. @stylistic understands TypeScript syntax that the core rules skipped, so the autofix adds missing semicolons and spaces in type literals and aliases. Leading | and & in multiline types stay where they were. Oxlint's node/no-sync also reports identifiers ending in Sync that are not calls. The test helper techSync is renamed and the two other names are ignored. Refs #1127 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { Static, Type } from "@sinclair/typebox";
|
|
import { FullVersionSchema, integerFullVersion, isFullVersion } from "../data/version.js";
|
|
|
|
const ARCHIVE_URL = "https://factorio.com/download/archive/";
|
|
|
|
/**
|
|
* Represents the parsed result of a factorio version
|
|
*/
|
|
export const ExternalFactorioVersionSchema = Type.Object({
|
|
stable: Type.Boolean(),
|
|
version: FullVersionSchema,
|
|
headlessUrl: Type.String(),
|
|
});
|
|
|
|
export type ExternalFactorioVersion = Static<typeof ExternalFactorioVersionSchema>;
|
|
|
|
/**
|
|
* Fetch all factorio versions that support headless
|
|
*
|
|
* @returns A list of all factorio versions and their download URL
|
|
* @throws Network errors and non-ok status responses
|
|
*/
|
|
export async function fetchFactorioVersions(): Promise<ExternalFactorioVersion[]> {
|
|
let res;
|
|
|
|
try {
|
|
res = await fetch(ARCHIVE_URL);
|
|
} catch (err) {
|
|
throw new Error(`Failed to fetch Factorio versions from ${ARCHIVE_URL}: ${err}`);
|
|
}
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`Failed to fetch Factorio versions from ${ARCHIVE_URL}: HTTP ${res.status} ${res.statusText}`);
|
|
}
|
|
|
|
const html = await res.text();
|
|
return parseFactorioVersions(html);
|
|
}
|
|
|
|
/**
|
|
* Parse all versions from the factorio archive webpage
|
|
*
|
|
* @param html The HTML content of the archive page
|
|
* @returns A list of all factorio versions and their download URL
|
|
*/
|
|
function parseFactorioVersions(html: string): ExternalFactorioVersion[] {
|
|
const versions = new Map<string, ExternalFactorioVersion>();
|
|
|
|
// Match <a class=" slot-button-inline version-button-stable " href="/download/archive/2.0.72">2.0.72</a>
|
|
// eslint-disable-next-line @stylistic/max-len
|
|
const anchorRegex = /<a[^>]*class="[^"]*version-button-(?<kind>stable|experimental)[^"]*"[^>]*href="[^"]*\/download\/archive\/(?<version>\d+\.\d+.\d+)"[^>]*>/g;
|
|
|
|
let match: RegExpExecArray | null;
|
|
const minimumMultiplayerVersion = integerFullVersion("0.12.35");
|
|
while ((match = anchorRegex.exec(html)) !== null) {
|
|
const kind = match.groups?.kind;
|
|
const version = match.groups?.version;
|
|
|
|
if (kind && version && isFullVersion(version) && integerFullVersion(version) >= minimumMultiplayerVersion) {
|
|
versions.set(version, {
|
|
version: version,
|
|
stable: kind === "stable",
|
|
headlessUrl: `https://www.factorio.com/get-download/${version}/headless/linux64`,
|
|
});
|
|
}
|
|
}
|
|
|
|
return [...versions.values()];
|
|
}
|