Skip to content

Commit 6f6ea26

Browse files
committed
feat: Support side for forge install & diagnose
1 parent ddcfe62 commit 6f6ea26

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

packages/installer/diagnose.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export interface InstallProfileIssueReport {
3030
* @param installProfile The install profile.
3131
* @param minecraftLocation The minecraft location
3232
*/
33-
export async function diagnoseInstall(installProfile: InstallProfile, minecraftLocation: MinecraftLocation) {
33+
export async function diagnoseInstall(installProfile: InstallProfile, minecraftLocation: MinecraftLocation, side: 'client' | 'server' = 'client'): Promise<InstallProfileIssueReport> {
3434
const mc = MinecraftFolder.from(minecraftLocation)
3535
const report: InstallProfileIssueReport = {
3636
minecraftLocation: mc,
3737
installProfile,
3838
issues: [],
3939
}
4040
const issues = report.issues
41-
const processors: PostProcessor[] = resolveProcessors('client', installProfile, mc)
41+
const processors: PostProcessor[] = resolveProcessors(side, installProfile, mc)
4242
await Promise.all(Version.resolveLibraries(installProfile.libraries).map(async (lib) => {
4343
const libPath = mc.getLibraryByPath(lib.download.path)
4444
const issue = await diagnoseFile({

packages/installer/forge.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,28 @@ export interface ForgeInstallerEntries {
8383
*/
8484
versionJson?: Entry
8585
/**
86-
* forge-${forgeVersion}-universal.jar
87-
*/
86+
* forge-${forgeVersion}-universal.jar
87+
*/
8888
legacyUniversalJar?: Entry
8989
/**
90-
* data/run.sh
91-
*/
90+
* data/run.sh
91+
*/
9292
runSh?: Entry
9393
/**
94-
* data/run.bat
95-
*/
94+
* data/run.bat
95+
*/
9696
runBat?: Entry
9797
/**
9898
* data/unix_args.txt
9999
*/
100100
unixArgs?: Entry
101101
/**
102-
* data/user_jvm_args.txt
103-
*/
102+
* data/user_jvm_args.txt
103+
*/
104104
userJvmArgs?: Entry
105105
/**
106-
* data/win_args.txt
107-
*/
106+
* data/win_args.txt
107+
*/
108108
winArgs?: Entry
109109
}
110110

@@ -140,6 +140,7 @@ export const DEFAULT_FORGE_MAVEN = 'http://files.minecraftforge.net/maven'
140140
* The options to install forge.
141141
*/
142142
export interface InstallForgeOptions extends LibraryOptions, InstallOptionsBase, InstallProfileOption {
143+
side?: 'client' | 'server'
143144
}
144145

145146
export class DownloadForgeInstallerTask extends DownloadTask {

packages/installer/profile.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { readFile } from 'fs/promises'
66
import { delimiter, dirname } from 'path'
77
import { ZipFile } from 'yauzl'
88
import { InstallLibraryTask, InstallSideOption, LibraryOptions } from './minecraft'
9-
import { checksum, errorToString, SpawnJavaOptions, waitProcess } from './utils'
9+
import { checksum, errorToString, missing, SpawnJavaOptions, waitProcess } from './utils'
1010

1111
export interface PostProcessor {
1212
/**
@@ -82,13 +82,17 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
8282
}
8383
return val
8484
}
85-
function normalizeVariable(val: string) {
86-
if (val && val.match(/^{.+}$/g)) { // match sth like {MAPPINGS}
87-
const key = val.substring(1, val.length - 1)
88-
return variables[key][side]
89-
}
90-
return val
85+
86+
const normalizeVariable = (val: string) => {
87+
if (!val) return val
88+
// replace "{A}/{B}, which the value of A and B are from varaiables
89+
// for example, variables = { A: "a", B: "b" }
90+
// "{A}/{B}" => "a/b"
91+
// The key variable name can be any alphabet characters and number other special characters
92+
// Another example, "{A}" => "a"
93+
return val.replace(/{([A-Za-z0-9_-]+)}/g, (_, key) => variables[key]?.[side] ?? '')
9194
}
95+
9296
// store the mapping of {VARIABLE_NAME} -> real path in disk
9397
const variables: Record<string, { client: string; server: string }> = {
9498
SIDE: {
@@ -99,6 +103,18 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
99103
client: minecraft.getVersionJar(installProfile.minecraft),
100104
server: minecraft.getVersionJar(installProfile.minecraft, 'server'),
101105
},
106+
ROOT: {
107+
client: minecraft.root,
108+
server: minecraft.root,
109+
},
110+
MINECRAFT_VERSION: {
111+
client: installProfile.minecraft,
112+
server: installProfile.minecraft,
113+
},
114+
LIBRARY_DIR: {
115+
client: minecraft.libraries,
116+
server: minecraft.libraries,
117+
},
102118
}
103119
if (installProfile.data) {
104120
for (const key in installProfile.data) {
@@ -109,12 +125,6 @@ export function resolveProcessors(side: 'client' | 'server', installProfile: Ins
109125
}
110126
}
111127
}
112-
if (variables.INSTALLER) {
113-
variables.ROOT = {
114-
client: dirname(variables.INSTALLER.client),
115-
server: dirname(variables.INSTALLER.server),
116-
}
117-
}
118128

119129
const resolveOutputs = (proc: PostProcessor, args: string[]) => {
120130
const original = proc.outputs
@@ -269,6 +279,9 @@ export class PostProcessingTask extends AbortableTask<void> {
269279

270280
protected async isInvalid(outputs: Required<PostProcessor>['outputs']) {
271281
for (const [file, expect] of Object.entries(outputs)) {
282+
if (!expect) {
283+
return missing(file)
284+
}
272285
const sha1 = await checksum(file, 'sha1').catch((e) => '')
273286
if (!sha1) return true // if file not exist, the file is not generated
274287
if (!expect) return false // if expect is empty, we just need file exists

0 commit comments

Comments
 (0)