Skip to content

Commit

Permalink
Allowing raw mod URLs in modpack
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jan 29, 2024
1 parent 22f2b7f commit 11c9ed5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Before you can execute this phase, you need a `modpack.json` file with contents
"type": "maven",
"artifact": "org.cyclops.commoncapabilities:CommonCapabilities:1.12.2-2.4.4-309",
"repo": "https://oss.jfrog.org/artifactory/simple/libs-release/"
},
{
"type": "raw",
"name": "integratedscripting-1.19.2-1.0.0-61.jar",
"url": "https://www.dropbox.com/s/mbbikni5ieyttuq/integratedscripting-1.19.2-1.0.0-61.jar?dl=1"
}
]
}
Expand Down
37 changes: 25 additions & 12 deletions lib/modloader/ModLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,32 @@ export class ModLoader {
process.stdout.write(` - ${fileName} from CurseForge...\n`);
const url = `https://minecraft.curseforge.com/api/maven/${mod.project}/${mod.artifact
.replace(/-/g, '/')}/${fileName}`;
const response = await fetch(url);
if (response.status !== 200) {
throw new Error(response.statusText + ' on ' + url);
}
await new Promise((resolve, reject) => {
response.body
.on('error', reject)
.on('end', resolve)
.pipe(fs.createWriteStream(join(modsDir, fileName)));
});
await this.downloadFile(url, fileName, modsDir);
} else if (mod.type === 'maven') {
process.stdout.write(` - ${mod.artifact} from ${mod.repo}...\n`);
await download(mod.artifact, modsDir, mod.repo);
} else if (mod.type === 'raw') {
process.stdout.write(` - ${mod.name} from ${mod.url}...\n`);
await this.downloadFile(mod.url, mod.name, modsDir);
} else {
throw new Error('Unknown mod type ' + (<any> mod).type);
}
}
}

public async downloadFile(url: string, fileName: string, modsDir: string): Promise<void> {
const response = await fetch(url);
if (response.status !== 200) {
throw new Error(response.statusText + ' on ' + url);
}
await new Promise((resolve, reject) => {
response.body
.on('error', reject)
.on('end', resolve)
.pipe(fs.createWriteStream(join(modsDir, fileName)));
});
}

/**
* Start the server and execute a command to dump all registries
*/
Expand All @@ -141,7 +148,7 @@ export class ModLoader {

// Once the loading is complete, send our command and stop the server
proc.stdout.on('data', (line: string) => {
if (line.indexOf('[Server thread/INFO]: Done') >= 0) {
if (line.indexOf('Done') >= 0 && line.indexOf('For help, type "help"') >= 0) {
process.stdout.write('Dumping registries...\n');
this.sendCommand(proc, '/cyclopscore dumpregistries');
this.sendCommand(proc, '/stop');
Expand Down Expand Up @@ -312,7 +319,7 @@ export interface IModLoaderArgs {
versionMinecraft: string;
}

export type IMod = IModMaven | IModCurseforge;
export type IMod = IModMaven | IModCurseforge | IModRaw;

export interface IModMaven {
type: 'maven';
Expand All @@ -326,3 +333,9 @@ export interface IModCurseforge {
artifact: string;
version: string;
}

export interface IModRaw {
type: 'raw';
name: string;
url: string;
}

0 comments on commit 11c9ed5

Please sign in to comment.