-
Notifications
You must be signed in to change notification settings - Fork 220
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
anttimaki
wants to merge
10
commits into
develop
Choose a base branch
from
ecosystem-integration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
81bba30
Integrate ecosystem-schema
ethangreen-dev a07afc0
Make relativeFileExclusion a required attribute for InstallationRules
anttimaki ab26bf4
Make sync script handle fetching JSON Schema and generating types
anttimaki 9b7e10b
Use latest ecosystem data from Thunderstore API
anttimaki 1ed0f42
Fix InstallationRules to work with ecosystem data
anttimaki 7097851
Fix StorePlatforms to work with ecosystem data
anttimaki 691c855
Fix PackageLoaders to work with ecosystem data
anttimaki 0630318
Fix ModLoaderVariantRecords to work with ecosystem data
anttimaki 9f65210
Fix GameManager to work with ecosystem data
anttimaki 033b802
Use latest ecosystem data including structural changes
anttimaki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
/** | ||
* 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(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.ts
to something like
ecosystemTypes.ts` so Enums can be imported instead of having to be redefined in the mod manager.There was a problem hiding this comment.
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