Skip to content

Commit

Permalink
slightly improve version sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Dec 10, 2023
1 parent 9c80df9 commit 3c1f724
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/helpers/choiceEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function textureChoiceEmbed(
const mappedResults: SelectMenuComponentOptionData[] = [];
for (const result of results) {
mappedResults.push({
label: `[#${result.id}] (${result.paths[0].versions.sort(minecraftSorter).reverse()[0]}) ${
label: `[#${result.id}] (${result.paths[0].versions.sort(minecraftSorter).at(-1)}) ${
result.name
}`,
description: result.paths[0].name,
Expand Down
18 changes: 7 additions & 11 deletions src/helpers/functions/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { join, normalize } from "path";
import blacklistedTextures from "@json/blacklisted_textures.json";
import axios from "axios";
import { FaithfulPack } from "@interfaces/firestorm";
import minecraftSorter from "@utility/minecraftSorter";

// starting from process.cwd()
export const BASE_REPOS_PATH = "repos";
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function computeMissingResults(
const defaultPath = join(basePath, getNameFromGit(defaultRepo));
const requestPath = join(basePath, getNameFromGit(requestRepo));

// CLONE REPO IF NOT ALREADY CLONED
// clone repos if not already done (saves a lot of init lol)
if (!existsSync(defaultPath)) {
await callback(`Downloading default ${edition} pack...`);
mkdirSync(defaultPath, { recursive: true });
Expand All @@ -76,9 +77,10 @@ export async function computeMissingResults(
await axios.get(`${client.tokens.apiUrl}textures/versions/${edition}`)
).data;
// latest version if versions doesn't include version (unexisting/unsupported)
if (!versions.includes(version)) version = versions[0];
if (!versions.includes(version)) version = versions.sort(minecraftSorter).at(-1);
await callback(`Updating packs with latest version of \`${version}\` known...`);

// same steps are used for both packs
const steps = [
"git stash",
"git remote update",
Expand All @@ -87,16 +89,10 @@ export async function computeMissingResults(
`git pull`,
];

// same steps, just with different packs
await Promise.all([
series(structuredClone(steps), {
cwd: defaultPath,
}),
series(structuredClone(steps), {
cwd: requestPath,
}),
]);
await series(structuredClone(steps), { cwd: defaultPath });
await series(structuredClone(steps), { cwd: requestPath });

// now both repos are pointing to the same version and are ready to compare
await callback("Searching for differences...");

const editionFilter = blacklistedTextures[edition].map(normalize);
Expand Down

0 comments on commit 3c1f724

Please sign in to comment.