Skip to content

Commit bcf1a9f

Browse files
authored
Merge pull request #1895 from ebkr/desynced-sync
Parametrize the sync script to support only updating type definitions
2 parents 9917b11 + da75548 commit bcf1a9f

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

scripts/sync.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,33 @@ const ECOSYSTEM_DATA_TYPES_PATH = "./src/assets/data/ecosystemTypes.ts";
1111
/**
1212
* This script synchronizes the in-repo ecosystem schema JSON to the latest
1313
* version and generates matching TypeScript types.
14+
*
15+
* To only generate the TypeScript types without syncing with the
16+
* Thunderstore API, use `yarn sync -- --types-only`
1417
*/
1518
async function updateSchema() {
16-
console.log("Updating ecosystem.json...");
17-
const response = await fetch(ECOSYSTEM_DATA_URL);
18-
if (response.status !== 200) {
19-
throw new Error(`Received non-200 status from schema API: ${response.status}`);
20-
}
21-
const data = Buffer.from(await response.arrayBuffer());
22-
fs.writeFileSync(ECOSYSTEM_DATA_PATH, data);
19+
let schema: Buffer;
20+
21+
if (process.argv.includes('--types-only')) {
22+
console.log("Skipping API update, reading JSON schema from disk...");
23+
schema = fs.readFileSync(ECOSYSTEM_JSON_SCHEMA_PATH);
24+
} else {
25+
console.log("Updating ecosystem.json...");
26+
const response = await fetch(ECOSYSTEM_DATA_URL);
27+
if (response.status !== 200) {
28+
throw new Error(`Received non-200 status from schema API: ${response.status}`);
29+
}
30+
const data = Buffer.from(await response.arrayBuffer());
31+
fs.writeFileSync(ECOSYSTEM_DATA_PATH, data);
2332

24-
console.log("Updating ecosystemJsonSchema.json...");
25-
const schemaResponse = await fetch(ECOSYSTEM_JSON_SCHEMA_URL);
26-
if (schemaResponse.status !== 200) {
27-
throw new Error(`Received non-200 status from schema API: ${schemaResponse.status}`);
33+
console.log("Updating ecosystemJsonSchema.json...");
34+
const schemaResponse = await fetch(ECOSYSTEM_JSON_SCHEMA_URL);
35+
if (schemaResponse.status !== 200) {
36+
throw new Error(`Received non-200 status from schema API: ${schemaResponse.status}`);
37+
}
38+
schema = Buffer.from(await schemaResponse.arrayBuffer());
39+
fs.writeFileSync(ECOSYSTEM_JSON_SCHEMA_PATH, schema);
2840
}
29-
const schema = Buffer.from(await schemaResponse.arrayBuffer());
30-
fs.writeFileSync(ECOSYSTEM_JSON_SCHEMA_PATH, schema);
3141

3242
console.log("Updating ecosystemTypes.ts...");
3343
const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());

0 commit comments

Comments
 (0)