From da75548dddefab4fc21070ec9e3afd871f8d5086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Thu, 28 Aug 2025 10:51:18 +0300 Subject: [PATCH] Parametrize the sync script to support only updating type definitions This can be used to test changes while developing without having to merge experimental changes to the Thunderstore ecosystem schema API. --- scripts/sync.ts | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/scripts/sync.ts b/scripts/sync.ts index 8f97d9749..49493c4cb 100644 --- a/scripts/sync.ts +++ b/scripts/sync.ts @@ -11,23 +11,33 @@ const ECOSYSTEM_DATA_TYPES_PATH = "./src/assets/data/ecosystemTypes.ts"; /** * This script synchronizes the in-repo ecosystem schema JSON to the latest * version and generates matching TypeScript types. + * + * To only generate the TypeScript types without syncing with the + * Thunderstore API, use `yarn sync -- --types-only` */ async function updateSchema() { - 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(ECOSYSTEM_DATA_PATH, data); + let schema: Buffer; + + if (process.argv.includes('--types-only')) { + console.log("Skipping API update, reading JSON schema from disk..."); + schema = fs.readFileSync(ECOSYSTEM_JSON_SCHEMA_PATH); + } else { + 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(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}`); + 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}`); + } + schema = Buffer.from(await schemaResponse.arrayBuffer()); + fs.writeFileSync(ECOSYSTEM_JSON_SCHEMA_PATH, schema); } - const schema = Buffer.from(await schemaResponse.arrayBuffer()); - fs.writeFileSync(ECOSYSTEM_JSON_SCHEMA_PATH, schema); console.log("Updating ecosystemTypes.ts..."); const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());