refactor: migrate to common eslint+prettier configs (#4168)

* refactor: migrate to common eslint+prettier configs

* fix: prettier frontend

* feat: config changes

* fix: lint issues

* fix: lint

* fix: type imports

* fix: cyclical import issue

* fix: lockfile

* fix: missing dep

* fix: switch to tabs

* fix: continue switch to tabs

* fix: rustfmt parity

* fix: moderation lint issue

* fix: lint issues

* fix: ui intl

* fix: lint issues

* Revert "fix: rustfmt parity"

This reverts commit cb99d2376c321d813d4b7fc7e2a213bb30a54711.

* feat: revert last rs
This commit is contained in:
Cal H.
2025-08-14 21:48:38 +01:00
committed by GitHub
parent 82697278dc
commit 2aabcf36ee
702 changed files with 101360 additions and 102020 deletions

View File

@@ -1,214 +1,214 @@
import JSZip from "jszip";
import TOML from "@ltd/j-toml";
import TOML from '@ltd/j-toml'
import JSZip from 'jszip'
export const createDataPackVersion = async function (
project,
version,
primaryFile,
members,
allGameVersions,
loaders,
project,
version,
primaryFile,
members,
allGameVersions,
loaders,
) {
// force version to start with number, as required by FML
const newVersionNumber = version.version_number.match(/^\d/)
? version.version_number
: `1-${version.version_number}`;
// force version to start with number, as required by FML
const newVersionNumber = version.version_number.match(/^\d/)
? version.version_number
: `1-${version.version_number}`
const newSlug = `mr_${project.slug.replace("-", "_").replace(/\W/g, "")}`.substring(0, 63);
const newSlug = `mr_${project.slug.replace('-', '_').replace(/\W/g, '')}`.substring(0, 63)
const iconPath = `${project.slug}_pack.png`;
const iconPath = `${project.slug}_pack.png`
const config = useRuntimeConfig();
const config = useRuntimeConfig()
const fabricModJson = {
schemaVersion: 1,
id: newSlug,
version: newVersionNumber,
name: project.title,
description: project.description,
authors: members.map((x) => x.name),
contact: {
homepage: `${config.public.siteUrl}/${project.project_type}/${project.slug ?? project.id}`,
},
license: project.license.id,
icon: iconPath,
environment: "*",
depends: {
"fabric-resource-loader-v0": "*",
},
};
const fabricModJson = {
schemaVersion: 1,
id: newSlug,
version: newVersionNumber,
name: project.title,
description: project.description,
authors: members.map((x) => x.name),
contact: {
homepage: `${config.public.siteUrl}/${project.project_type}/${project.slug ?? project.id}`,
},
license: project.license.id,
icon: iconPath,
environment: '*',
depends: {
'fabric-resource-loader-v0': '*',
},
}
const quiltModJson = {
schema_version: 1,
quilt_loader: {
group: "com.modrinth",
id: newSlug,
version: newVersionNumber,
metadata: {
name: project.title,
description: project.description,
contributors: members.reduce(
(acc, x) => ({
...acc,
[x.name]: x.role,
}),
{},
),
contact: {
homepage: `${config.public.siteUrl}/${project.project_type}/${
project.slug ?? project.id
}`,
},
icon: iconPath,
},
intermediate_mappings: "net.fabricmc:intermediary",
depends: [
{
id: "quilt_resource_loader",
versions: "*",
unless: "fabric-resource-loader-v0",
},
],
},
};
const quiltModJson = {
schema_version: 1,
quilt_loader: {
group: 'com.modrinth',
id: newSlug,
version: newVersionNumber,
metadata: {
name: project.title,
description: project.description,
contributors: members.reduce(
(acc, x) => ({
...acc,
[x.name]: x.role,
}),
{},
),
contact: {
homepage: `${config.public.siteUrl}/${project.project_type}/${
project.slug ?? project.id
}`,
},
icon: iconPath,
},
intermediate_mappings: 'net.fabricmc:intermediary',
depends: [
{
id: 'quilt_resource_loader',
versions: '*',
unless: 'fabric-resource-loader-v0',
},
],
},
}
const cutoffIndex = allGameVersions.findIndex((x) => x.version === "1.18.2");
const cutoffIndex = allGameVersions.findIndex((x) => x.version === '1.18.2')
let maximumIndex = Number.MIN_VALUE;
for (const val of version.game_versions) {
const index = allGameVersions.findIndex((x) => x.version === val);
if (index > maximumIndex) {
maximumIndex = index;
}
}
let maximumIndex = Number.MIN_VALUE
for (const val of version.game_versions) {
const index = allGameVersions.findIndex((x) => x.version === val)
if (index > maximumIndex) {
maximumIndex = index
}
}
const newForge = maximumIndex < cutoffIndex;
const newForge = maximumIndex < cutoffIndex
const forgeModsToml = {
modLoader: newForge ? "lowcodefml" : "javafml",
loaderVersion: newForge ? "[40,)" : "[25,)",
license: project.license.id,
showAsResourcePack: false,
mods: [
{
modId: newSlug,
version: newVersionNumber,
displayName: project.title,
description: project.description,
logoFile: iconPath,
updateJSONURL: `${config.public.apiBaseUrl.replace("/v2/", "")}/updates/${
project.id
}/forge_updates.json`,
credits: "Generated by Modrinth",
authors: members.map((x) => x.name).join(", "),
displayURL: `${config.public.siteUrl}/${project.project_type}/${
project.slug ?? project.id
}`,
},
],
};
const forgeModsToml = {
modLoader: newForge ? 'lowcodefml' : 'javafml',
loaderVersion: newForge ? '[40,)' : '[25,)',
license: project.license.id,
showAsResourcePack: false,
mods: [
{
modId: newSlug,
version: newVersionNumber,
displayName: project.title,
description: project.description,
logoFile: iconPath,
updateJSONURL: `${config.public.apiBaseUrl.replace('/v2/', '')}/updates/${
project.id
}/forge_updates.json`,
credits: 'Generated by Modrinth',
authors: members.map((x) => x.name).join(', '),
displayURL: `${config.public.siteUrl}/${project.project_type}/${
project.slug ?? project.id
}`,
},
],
}
if (project.source_url) {
quiltModJson.quilt_loader.metadata.contact.sources = project.source_url;
fabricModJson.contact.sources = project.source_url;
}
if (project.source_url) {
quiltModJson.quilt_loader.metadata.contact.sources = project.source_url
fabricModJson.contact.sources = project.source_url
}
if (project.issues_url) {
quiltModJson.quilt_loader.metadata.contact.issues = project.issues_url;
fabricModJson.contact.issues = project.issues_url;
forgeModsToml.issueTrackerURL = project.issues_url;
}
if (project.issues_url) {
quiltModJson.quilt_loader.metadata.contact.issues = project.issues_url
fabricModJson.contact.issues = project.issues_url
forgeModsToml.issueTrackerURL = project.issues_url
}
const neoModsToml = {
...forgeModsToml,
modLoader: "javafml",
loaderVersion: "[1,)",
mods: forgeModsToml.mods.map((mod) => ({
...mod,
updateJSONURL: mod.updateJSONURL + "?neoforge=only",
})),
};
const neoModsToml = {
...forgeModsToml,
modLoader: 'javafml',
loaderVersion: '[1,)',
mods: forgeModsToml.mods.map((mod) => ({
...mod,
updateJSONURL: mod.updateJSONURL + '?neoforge=only',
})),
}
const primaryFileData = await (await fetch(primaryFile.url)).blob();
const primaryFileData = await (await fetch(primaryFile.url)).blob()
const primaryZipReader = new JSZip();
await primaryZipReader.loadAsync(primaryFileData);
const primaryZipReader = new JSZip()
await primaryZipReader.loadAsync(primaryFileData)
if (loaders.includes("fabric")) {
primaryZipReader.file("fabric.mod.json", JSON.stringify(fabricModJson));
}
if (loaders.includes("quilt")) {
primaryZipReader.file("quilt.mod.json", JSON.stringify(quiltModJson));
}
if (loaders.includes("forge")) {
primaryZipReader.file("META-INF/mods.toml", TOML.stringify(forgeModsToml, { newline: "\n" })); // eslint-disable-line import/no-named-as-default-member
}
if (loaders.includes("neoforge")) {
primaryZipReader.file(
"META-INF/neoforge.mods.toml",
TOML.stringify(neoModsToml, { newline: "\n" }), // eslint-disable-line import/no-named-as-default-member
);
}
if (loaders.includes('fabric')) {
primaryZipReader.file('fabric.mod.json', JSON.stringify(fabricModJson))
}
if (loaders.includes('quilt')) {
primaryZipReader.file('quilt.mod.json', JSON.stringify(quiltModJson))
}
if (loaders.includes('forge')) {
primaryZipReader.file('META-INF/mods.toml', TOML.stringify(forgeModsToml, { newline: '\n' }))
}
if (loaders.includes('neoforge')) {
primaryZipReader.file(
'META-INF/neoforge.mods.toml',
TOML.stringify(neoModsToml, { newline: '\n' }),
)
}
if (!newForge && loaders.includes("forge")) {
const classFile = new Uint8Array(
await (
await fetch("https://cdn.modrinth.com/wrapper/ModrinthWrapperRestiched.class")
).arrayBuffer(),
);
if (!newForge && loaders.includes('forge')) {
const classFile = new Uint8Array(
await (
await fetch('https://cdn.modrinth.com/wrapper/ModrinthWrapperRestiched.class')
).arrayBuffer(),
)
let binary = "";
for (let i = 0; i < classFile.byteLength; i++) {
binary += String.fromCharCode(classFile[i]);
}
let binary = ''
for (let i = 0; i < classFile.byteLength; i++) {
binary += String.fromCharCode(classFile[i])
}
let sanitizedId = project.id;
let sanitizedId = project.id
if (project.id.match(/^(\d+)/g)) {
sanitizedId = "_" + sanitizedId;
}
if (project.id.match(/^(\d+)/g)) {
sanitizedId = '_' + sanitizedId
}
sanitizedId = sanitizedId.substring(0, 8);
sanitizedId = sanitizedId.substring(0, 8)
binary = binary
.replace(
String.fromCharCode(32) + "needs1to1be1changed1modrinth1mod",
String.fromCharCode(newSlug.length) + newSlug,
)
.replace("/wrappera/", `/${sanitizedId}/`);
binary = binary
.replace(
String.fromCharCode(32) + 'needs1to1be1changed1modrinth1mod',
String.fromCharCode(newSlug.length) + newSlug,
)
.replace('/wrappera/', `/${sanitizedId}/`)
const newArr = [];
for (let i = 0; i < binary.length; i++) {
newArr.push(binary.charCodeAt(i));
}
const newArr = []
for (let i = 0; i < binary.length; i++) {
newArr.push(binary.charCodeAt(i))
}
primaryZipReader.file(
`com/modrinth/${sanitizedId}/ModrinthWrapper.class`,
new Uint8Array(newArr),
);
}
primaryZipReader.file(
`com/modrinth/${sanitizedId}/ModrinthWrapper.class`,
new Uint8Array(newArr),
)
}
const resourcePack = version.files.find((x) => x.file_type === "required-resource-pack");
const resourcePack = version.files.find((x) => x.file_type === 'required-resource-pack')
const resourcePackData = resourcePack ? await (await fetch(resourcePack.url)).blob() : null;
const resourcePackData = resourcePack ? await (await fetch(resourcePack.url)).blob() : null
if (resourcePackData) {
const resourcePackReader = new JSZip();
await resourcePackReader.loadAsync(resourcePackData);
if (resourcePackData) {
const resourcePackReader = new JSZip()
await resourcePackReader.loadAsync(resourcePackData)
for (const [path, file] of Object.entries(resourcePackReader.files)) {
if (!primaryZipReader.file(path) && !path.includes(".mcassetsroot")) {
primaryZipReader.file(path, await file.async("uint8array"));
}
}
}
for (const [path, file] of Object.entries(resourcePackReader.files)) {
if (!primaryZipReader.file(path) && !path.includes('.mcassetsroot')) {
primaryZipReader.file(path, await file.async('uint8array'))
}
}
}
if (primaryZipReader.file("pack.png")) {
primaryZipReader.file(iconPath, await primaryZipReader.file("pack.png").async("uint8array"));
}
if (primaryZipReader.file('pack.png')) {
primaryZipReader.file(iconPath, await primaryZipReader.file('pack.png').async('uint8array'))
}
return await primaryZipReader.generateAsync({
type: "blob",
mimeType: "application/java-archive",
});
};
return await primaryZipReader.generateAsync({
type: 'blob',
mimeType: 'application/java-archive',
})
}