|
1 | 1 | #!/usr/bin/env bun
|
2 | 2 |
|
3 | 3 | import { program, Option } from '@commander-js/extra-typings';
|
4 |
| -import { CurseForgeRepository, LocalSolutionFinder, LoggerConfig, ModLoader, ModrinthRepository, LogLevel, Constraints, Solution, ModMetadata, RepositoryUtil, ModRepositoryName, RemoteModQueryService, IModQueryService, IRepository } from 'mclib'; |
| 4 | +import { CurseForgeRepository, LocalSolutionFinder, LoggerConfig, ModLoader, ModrinthRepository, LogLevel, Constraints, Solution, ModMetadata, RepositoryUtil, ModRepositoryName, RemoteModQueryService, IModQueryService, IRepository, LocalModQueryService } from 'mclib'; |
5 | 5 | import { readFileSync } from 'fs';
|
6 | 6 | import pino from 'pino';
|
7 | 7 |
|
@@ -33,8 +33,14 @@ async function fetchWrapper(input: RequestInfo | URL, options?: RequestInit): Pr
|
33 | 33 | return response;
|
34 | 34 | }
|
35 | 35 |
|
36 |
| -function getModQueryService(selectedRepos?: string[]) { |
37 |
| - return new RemoteModQueryService(fetchWrapper, "http://127.0.0.1:3000", getRepositories(selectedRepos)); |
| 36 | +function getModQueryService(selectedRepos?: string[], remoteUrl?: string) { |
| 37 | + if (remoteUrl) { |
| 38 | + logger.info(`Using remote mod query service at ${remoteUrl}`); |
| 39 | + return new RemoteModQueryService(fetchWrapper, remoteUrl, getRepositories(selectedRepos)); |
| 40 | + } else { |
| 41 | + logger.info('Using local mod query service'); |
| 42 | + return new LocalModQueryService(getRepositories(selectedRepos)); |
| 43 | + } |
38 | 44 | }
|
39 | 45 | function getRepositories(selectedRepos?: string[]): IRepository[] {
|
40 | 46 | const repoMap = {
|
@@ -67,6 +73,7 @@ interface CliOptions {
|
67 | 73 | details: boolean;
|
68 | 74 | nbSolutions: number;
|
69 | 75 | sinytra: boolean;
|
| 76 | + remote?: string; |
70 | 77 | }
|
71 | 78 |
|
72 | 79 | function validateCliOptions(options: CliOptions) {
|
@@ -198,8 +205,9 @@ program
|
198 | 205 | .option('-n, --nb-solutions <number>', 'Number of solutions to output', (value) => parseInt(value, 10), 3)
|
199 | 206 | .option('--sinytra', 'Inject forge and neoforge into fabric-compatible releases', false)
|
200 | 207 | .option('-r, --repository <repo...>', 'Repositories to use (modrinth, curseforge)')
|
| 208 | + .option('--remote <url>', 'Remote server URL to query mods', '') |
201 | 209 | .action(async (cliOptions: CliOptions & { repository?: string[] }) => {
|
202 |
| - const modQueryService = getModQueryService(cliOptions.repository); |
| 210 | + const modQueryService = getModQueryService(cliOptions.repository, cliOptions.remote); |
203 | 211 | validateCliOptions(cliOptions);
|
204 | 212 |
|
205 | 213 | const requestedMods = await getMods(modQueryService, cliOptions);
|
|
0 commit comments