Skip to content

Commit

Permalink
Merge pull request #44 from thunderstore-io/autolist-default-packages
Browse files Browse the repository at this point in the history
Added autolistPackageIds
  • Loading branch information
MythicManiac authored Sep 5, 2024
2 parents e3309e1 + 62b5b5f commit 31772e3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions games/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface ThunderstoreCommunityDefinition {
};
discordUrl?: string;
wikiUrl?: string;
autolistPackageIds?: string[];
}

export interface GameDefinition {
Expand Down
24 changes: 24 additions & 0 deletions games/src/schema/autolistPackages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const AUTOLIST_PACKAGE_CHOICES = [
{
value: "BepInEx-BepInExPack",
name: "BepInEx 5 (use this for Unity mono games)",
},
{
value: "BepInEx-BepInExPack_IL2CPP",
name: "BepInEx 6 IL2CPP (use this for Unity IL2CPP games)",
},
{
value: "Thunderstore-unreal_shimloader",
name: "Unreal Engine shimloader",
},
{
value: "LavaGang-MelonLoader",
name: "MelonLoader",
},
];

const AUTOLIST_PACKAGE_IDS = AUTOLIST_PACKAGE_CHOICES.map((x) => x.value);

export function isAutolistPackageValid(autolistPackageId: string): boolean {
return AUTOLIST_PACKAGE_IDS.indexOf(autolistPackageId) > -1;
}
12 changes: 12 additions & 0 deletions games/src/schema/validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { isAutolistPackageValid } from "./autolistPackages";

const slug = z.string().regex(new RegExp(/^[a-z0-9](-?[a-z0-9])*$/));

Expand All @@ -20,6 +21,7 @@ const communitySchema = z.strictObject({
),
wikiUrl: z.string().optional(),
discordUrl: z.string().optional(),
autolistPackageIds: z.array(z.string()).optional(),
});

export type CommunitySchemaType = z.infer<typeof communitySchema>;
Expand Down Expand Up @@ -96,5 +98,15 @@ export function validateSchemaJson(schemaJson: any): SchemaType {
}
});

Object.entries(parsed.communities).forEach(([key, community]) => {
(community.autolistPackageIds ?? []).forEach((packageId) => {
if (!isAutolistPackageValid(packageId)) {
throw new Error(
`Invalid autolist package ID "${packageId}" defined for community "${key}"`
);
}
});
});

return parsed;
}
9 changes: 8 additions & 1 deletion games/src/scripts/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { GameDefinition } from "../models";
import { v4 as uuid } from "uuid";
import fs from "fs";
import * as yaml from "js-yaml";
import { input } from "@inquirer/prompts";
import { input, checkbox } from "@inquirer/prompts";
import _ from "lodash";
import { AUTOLIST_PACKAGE_CHOICES } from "../schema/autolistPackages";

const displayName = await input({
message: "Display name for the community",
Expand All @@ -23,6 +24,11 @@ const wikiUrl = await input({
default: "",
});

const autolistPackageIds = await checkbox({
message: "Automatically list package",
choices: AUTOLIST_PACKAGE_CHOICES,
});

const game: GameDefinition = {
uuid: uuid(),
label: identifier,
Expand Down Expand Up @@ -68,6 +74,7 @@ const game: GameDefinition = {
},
wikiUrl: wikiUrl || undefined,
discordUrl: discordUrl || undefined,
autolistPackageIds: autolistPackageIds || undefined,
},
};

Expand Down

0 comments on commit 31772e3

Please sign in to comment.