mirror of
https://git.bits.team/Bits/mod-manager.git
synced 2025-07-07 11:39:43 -04:00
Compare commits
6 Commits
2bd38816ad
...
master
Author | SHA1 | Date | |
---|---|---|---|
9afa90963a | |||
117fe9f9a9 | |||
c91ad26f60 | |||
518398d626 | |||
c43554597f | |||
7bbf90fc53 |
@ -81,7 +81,8 @@ cp -r build/flat/* "$INSTALL_DIR" || exit
|
|||||||
|
|
||||||
# Creating executable
|
# Creating executable
|
||||||
info "Creating executable..."
|
info "Creating executable..."
|
||||||
echo "node $INSTALL_DIR/index.js \$@" > $BINARY_PATH || exit
|
echo "#!/bin/sh" > $BINARY_PATH || exit
|
||||||
|
echo "node $INSTALL_DIR/index.js \$@" >> $BINARY_PATH || exit
|
||||||
chmod +x $BINARY_PATH || exit
|
chmod +x $BINARY_PATH || exit
|
||||||
|
|
||||||
# Cleaning up
|
# Cleaning up
|
||||||
|
@ -64,7 +64,7 @@ export default class ModManager {
|
|||||||
|
|
||||||
Mods.registerSource(new ModrinthSource())
|
Mods.registerSource(new ModrinthSource())
|
||||||
Mods.registerSource(new CurseforgeSource(), "CURSEFORGE_API_KEY")
|
Mods.registerSource(new CurseforgeSource(), "CURSEFORGE_API_KEY")
|
||||||
Mods.registerSource(new ForgejoSource(), "FORGEJO_API_KEY")
|
Mods.registerSource(new ForgejoSource(), "FORGEJO_API_KEY", true)
|
||||||
|
|
||||||
this.program.showSuggestionAfterError();
|
this.program.showSuggestionAfterError();
|
||||||
this.program.showHelpAfterError();
|
this.program.showHelpAfterError();
|
||||||
|
@ -13,13 +13,13 @@ import chalk from "chalk";
|
|||||||
export default class Mods {
|
export default class Mods {
|
||||||
private static readonly MOD_SOURCES: Array<ModSource> = [];
|
private static readonly MOD_SOURCES: Array<ModSource> = [];
|
||||||
|
|
||||||
public static registerSource(source: ModSource, envVar?: string) {
|
public static registerSource(source: ModSource, envVar?: string, suppressWarning?: boolean) {
|
||||||
if (envVar != undefined) {
|
if (envVar && !process.env.hasOwnProperty(envVar)) {
|
||||||
if (!process.env.hasOwnProperty(envVar)) {
|
if (!suppressWarning)
|
||||||
PrintUtils.warn(`${source.getSourceName()} could not be registered as a mod source, as the required environment variable ${envVar} was not detected. Functionality related to ${source.getSourceName()} will be skipped.`)
|
PrintUtils.warn(`${source.getSourceName()} could not be registered as a mod source, as the required environment variable ${envVar} was not detected. Functionality related to ${source.getSourceName()} will be skipped.`)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.MOD_SOURCES.push(source);
|
this.MOD_SOURCES.push(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import ModSource from "./mod_source.js";
|
import ModSource from "./mod_source.js";
|
||||||
import Util from "../../util/util.js";
|
import Util from "../../util/util.js";
|
||||||
import { ForgejoFile, ForgejoFiles, ForgejoPackage as ForgejoSearchResponse } from "../../types/forgejo.js";
|
import { ForgejoFile, ForgejoFiles, ForgejoPackage } from "../../types/forgejo.js";
|
||||||
import { parse } from "properties-parser"
|
|
||||||
import ModNotFoundError from "../../errors/mod_not_found_error.js";
|
import ModNotFoundError from "../../errors/mod_not_found_error.js";
|
||||||
import MinecraftUtils from "../../util/minecraft_utils.js";
|
import MinecraftUtils from "../../util/minecraft_utils.js";
|
||||||
import { format } from "util";
|
import { format } from "util";
|
||||||
@ -13,11 +12,22 @@ import DownloadError from "../../errors/download_error.js";
|
|||||||
export default class ForgejoSource implements ModSource {
|
export default class ForgejoSource implements ModSource {
|
||||||
private static readonly BASE_URL: string = "https://git.bits.team/api/v1";
|
private static readonly BASE_URL: string = "https://git.bits.team/api/v1";
|
||||||
private static readonly SEARCH_URL: string = ForgejoSource.BASE_URL + "/packages/Bits"
|
private static readonly SEARCH_URL: string = ForgejoSource.BASE_URL + "/packages/Bits"
|
||||||
private static readonly VERSION_URL: string = ForgejoSource.BASE_URL + "/repos/%s/%s/media/gradle.properties"
|
|
||||||
private static readonly REPO_URL: string = ForgejoSource.BASE_URL + "/repositories/%s"
|
private static readonly REPO_URL: string = ForgejoSource.BASE_URL + "/repositories/%s"
|
||||||
private static readonly FILES_URL: string = ForgejoSource.BASE_URL + "/packages/%s/%s/%s/%s/files"
|
private static readonly FILES_URL: string = ForgejoSource.BASE_URL + "/packages/%s/%s/%s/%s/files"
|
||||||
|
private static readonly MC_VERSION_REGEX: RegExp = /(?<=-)[\d.]+(?:-[\w]+)?(?=-)/;
|
||||||
|
private static readonly BRANCH_REGEX: RegExp = /^([^-\s]+)/;
|
||||||
|
|
||||||
private async findPackage(query: string, mcVersion: string): Promise<{package: ForgejoSearchResponse, project_id: string} | undefined> {
|
private match(packageVersion: string, regex: RegExp): string {
|
||||||
|
const match = regex.exec(packageVersion)
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
return match[0]
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async findPackage(query: string, mcVersion: string): Promise<{package: ForgejoPackage, project_id: string} | undefined> {
|
||||||
let page = 1;
|
let page = 1;
|
||||||
let pagesLeft = true;
|
let pagesLeft = true;
|
||||||
while (pagesLeft) {
|
while (pagesLeft) {
|
||||||
@ -27,19 +37,13 @@ export default class ForgejoSource implements ModSource {
|
|||||||
q: query,
|
q: query,
|
||||||
page
|
page
|
||||||
}
|
}
|
||||||
const response: ForgejoSearchResponse[] = await this.makeRequest(ForgejoSource.SEARCH_URL, params);
|
const response: ForgejoPackage[] = await this.makeRequest(ForgejoSource.SEARCH_URL, params);
|
||||||
|
|
||||||
for (const mod of response) {
|
for (const mod of response) {
|
||||||
const versionParams = {
|
const packageVersion = this.match(mod.version, ForgejoSource.MC_VERSION_REGEX)
|
||||||
ref: mod.version
|
const branch = this.match(mod.version, ForgejoSource.BRANCH_REGEX);
|
||||||
}
|
|
||||||
|
|
||||||
const url = format(ForgejoSource.VERSION_URL, mod.owner.username, mod.repository.name)
|
if (packageVersion == mcVersion && branch == mod.repository.default_branch) {
|
||||||
|
|
||||||
const versionResponse = await this.makeRequest(url, versionParams).catch(_ => "");
|
|
||||||
const ver = parse(versionResponse)
|
|
||||||
|
|
||||||
if (ver["minecraft_version"] == mcVersion) {
|
|
||||||
return {
|
return {
|
||||||
package: mod,
|
package: mod,
|
||||||
project_id: mod.repository.id.toString()
|
project_id: mod.repository.id.toString()
|
||||||
@ -57,7 +61,7 @@ export default class ForgejoSource implements ModSource {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(query: string = "BitsVanilla"): Promise<string> {
|
async search(query: string): Promise<string> {
|
||||||
const mcVersion = await MinecraftUtils.getCurrentMinecraftVersion();
|
const mcVersion = await MinecraftUtils.getCurrentMinecraftVersion();
|
||||||
|
|
||||||
let mod = await this.findPackage(query, mcVersion);
|
let mod = await this.findPackage(query, mcVersion);
|
||||||
@ -94,11 +98,13 @@ export default class ForgejoSource implements ModSource {
|
|||||||
getSourceName(): string {
|
getSourceName(): string {
|
||||||
return "Forgejo";
|
return "Forgejo";
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProjectName(id: string): Promise<string> {
|
async getProjectName(id: string): Promise<string> {
|
||||||
const response = await this.makeRequest(format(ForgejoSource.REPO_URL, id))
|
const response = await this.makeRequest(format(ForgejoSource.REPO_URL, id))
|
||||||
return response.name;
|
return response.name;
|
||||||
}
|
}
|
||||||
async getLatestVersion(id: string = "34", mcVersion: string = "24w13a"): Promise<Version> {
|
|
||||||
|
async getLatestVersion(id: string, mcVersion: string): Promise<Version> {
|
||||||
const projectName = await this.getProjectName(id)
|
const projectName = await this.getProjectName(id)
|
||||||
|
|
||||||
const mod = await this.findPackage(projectName, mcVersion)
|
const mod = await this.findPackage(projectName, mcVersion)
|
||||||
|
Reference in New Issue
Block a user