| 1234567891011121314151617181920212223242526272829303132 |
- import type * as M from "./lua-api.models.js";
- import { generateDataModel } from "./parse-factorio-model.ts";
- import { extractEntityAndItemTypeName } from "./prototype-tree.ts";
- const API_PATH = "https://lua-api.factorio.com/latest/prototype-api.json";
- const OUTPUT_PATH = "scripts/factorio-dump/lua-api";
- /**
- * Fetch the raw prototype‑API from Factorio.
- * Uses the global `fetch` which is available in Node 18+.
- *
- * @returns the parsed {@link M.PrototypeApi} object.
- */
- export async function getPrototypeApi(): Promise<M.PrototypeApi> {
- const response = await fetch(API_PATH, { method: "GET" });
- if (!response.ok) {
- throw new Error(`Failed to fetch API: ${response.status} ${response.statusText}`);
- }
- return (await response.json()) as M.PrototypeApi;
- }
- const run = async function (): Promise<void> {
- console.log(`Regenerating Factorio prototype models from ${API_PATH}...`);
- const api = await getPrototypeApi();
- await generateDataModel(OUTPUT_PATH, api);
- await extractEntityAndItemTypeName(OUTPUT_PATH, api);
- };
- void run();
|