Skip to content

Thunderstore ecosystem integration #1724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@node-steam/vdf": "^2.1.0",
"@quasar/extras": "^1.0.0",
"adm-zip": "^0.5.5",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"async-lock": "^1.2.6",
"axios": "^0.24.0",
"bulma": "^0.9.4",
Expand Down Expand Up @@ -107,6 +109,7 @@
"majestic": "^1.2.24",
"minimist": "^1.2.2",
"mock-require": "^3.0.3",
"quicktype-core": "^23.0.171",
"sass": "^1.70.0",
"sass-loader": "^10.2.1",
"sinon": "^11.1.1",
Expand Down
41 changes: 35 additions & 6 deletions scripts/sync.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import fs from "fs";

import {FetchingJSONSchemaStore, InputData, JSONSchemaInput, quicktype} from "quicktype-core";

const ECOSYSTEM_DATA_URL = "https://thunderstore.io/api/experimental/schema/dev/latest/";
const ECOSYSTEM_JSON_SCHEMA_URL = "https://thunderstore.io/api/experimental/schema/ecosystem-json-schema/latest/";
const ECOSYSTEM_DATA_PATH = "./src/assets/data/ecosystem.json";
const ECOSYSTEM_JSON_SCHEMA_PATH = "./src/assets/data/ecosystemJsonSchema.json";
const ECOSYSTEM_DATA_TYPES_PATH = "./src/assets/data/ecosystem.d.ts";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm considering changing this from ecosystem.d.tsto something likeecosystemTypes.ts` so Enums can be imported instead of having to be redefined in the mod manager.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now done in #1751


/**
* This script synchronizes the in-repo ecosystem schema JSON to the latest
* version.
* version and generates matching TypeScript types.
*/

async function updateSchema() {
console.log("Updating games.json...")
const response = await fetch("https://thunderstore.io/api/experimental/schema/dev/latest/");
console.log("Updating ecosystem.json...");
const response = await fetch(ECOSYSTEM_DATA_URL);
if (response.status !== 200) {
throw new Error(`Received non-200 status from schema API: ${response.status}`);
}
const data = Buffer.from(await response.arrayBuffer());
fs.writeFileSync("./src/assets/data/games.json", data);
console.log("Done!");
fs.writeFileSync(ECOSYSTEM_DATA_PATH, data);

console.log("Updating ecosystemJsonSchema.json...");
const schemaResponse = await fetch(ECOSYSTEM_JSON_SCHEMA_URL);
if (schemaResponse.status !== 200) {
throw new Error(`Received non-200 status from schema API: ${schemaResponse.status}`);
}
const schema = Buffer.from(await schemaResponse.arrayBuffer());
fs.writeFileSync(ECOSYSTEM_JSON_SCHEMA_PATH, schema);

console.log("Updating ecosystem.d.ts...");
const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());
await schemaInput.addSource({name: "ThunderstoreEcosystem", schema: schema.toString()});
const inputData = new InputData();
inputData.addInput(schemaInput);
const types = await quicktype({
inputData,
lang: "typescript",
leadingComments: [{descriptionBlock: [
"This file is automatically generated by the sync.ts script.",
"Do not edit it manually.",
]}],
});
fs.writeFileSync(ECOSYSTEM_DATA_TYPES_PATH, types.lines.join("\n"));
}

updateSchema();
Loading
Loading