index.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import type * as M from "./lua-api.models.js";
  2. import { generateDataModel } from "./parse-factorio-model.ts";
  3. import { extractEntityAndItemTypeName } from "./prototype-tree.ts";
  4. const API_PATH = "https://lua-api.factorio.com/latest/prototype-api.json";
  5. const OUTPUT_PATH = "scripts/factorio-dump/lua-api";
  6. /**
  7. * Fetch the raw prototype‑API from Factorio.
  8. * Uses the global `fetch` which is available in Node 18+.
  9. *
  10. * @returns the parsed {@link M.PrototypeApi} object.
  11. */
  12. export async function getPrototypeApi(): Promise<M.PrototypeApi> {
  13. const response = await fetch(API_PATH, { method: "GET" });
  14. if (!response.ok) {
  15. throw new Error(`Failed to fetch API: ${response.status} ${response.statusText}`);
  16. }
  17. return (await response.json()) as M.PrototypeApi;
  18. }
  19. const run = async function (): Promise<void> {
  20. console.log(`Regenerating Factorio prototype models from ${API_PATH}...`);
  21. const api = await getPrototypeApi();
  22. await generateDataModel(OUTPUT_PATH, api);
  23. await extractEntityAndItemTypeName(OUTPUT_PATH, api);
  24. };
  25. void run();