Add workaround for PolyMC/PolyMC#1060
This commit is contained in:
parent
b8e60da181
commit
fd7e154b5e
3 changed files with 36 additions and 5 deletions
|
@ -17,6 +17,7 @@ import semver from "semver"
|
||||||
import { output } from "../output.js"
|
import { output } from "../output.js"
|
||||||
import fs from "fs-extra"
|
import fs from "fs-extra"
|
||||||
import { addModrinthMod, findModForModrinthMod, getModFileDataForModrinthVersion, isModrinthVersionCompatible, sortModrinthVersionsByPreference } from "../modrinth/utils.js"
|
import { addModrinthMod, findModForModrinthMod, getModFileDataForModrinthVersion, isModrinthVersionCompatible, sortModrinthVersionsByPreference } from "../modrinth/utils.js"
|
||||||
|
import { walk } from "@root/walk"
|
||||||
|
|
||||||
const modrinthCommand = new Command("modrinth")
|
const modrinthCommand = new Command("modrinth")
|
||||||
.alias("mr")
|
.alias("mr")
|
||||||
|
@ -311,11 +312,24 @@ modrinthCommand.command("export")
|
||||||
"Copying client-server overrides"
|
"Copying client-server overrides"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (await fs.pathExists(pack.paths.overrides["client"].toString())) await output.withLoading(
|
if (await fs.pathExists(pack.paths.overrides["client"].toString())) {
|
||||||
|
await output.withLoading(
|
||||||
fs.copy(pack.paths.overrides["client"].toString(), outputDirectory.resolve("client-overrides").toString(), { recursive: true }),
|
fs.copy(pack.paths.overrides["client"].toString(), outputDirectory.resolve("client-overrides").toString(), { recursive: true }),
|
||||||
"Copying client overrides"
|
"Copying client overrides"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Workaround for https://github.com/PolyMC/PolyMC/issues/1060
|
||||||
|
await walk(pack.paths.overrides["client"].toString(), async (error, path, dirent) => {
|
||||||
|
if (error) return
|
||||||
|
if (dirent.isDirectory()) {
|
||||||
|
const relativePath = pack.paths.overrides["client"].relative(path)
|
||||||
|
await fs.mkdirp(outputDirectory.resolve("overrides", relativePath).toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if (await fs.pathExists(pack.paths.overrides["server"].toString())) await output.withLoading(
|
if (await fs.pathExists(pack.paths.overrides["server"].toString())) await output.withLoading(
|
||||||
fs.copy(pack.paths.overrides["server"].toString(), outputDirectory.resolve("server-overrides").toString(), { recursive: true }),
|
fs.copy(pack.paths.overrides["server"].toString(), outputDirectory.resolve("server-overrides").toString(), { recursive: true }),
|
||||||
"Copying server overrides"
|
"Copying server overrides"
|
||||||
|
|
|
@ -34,6 +34,12 @@ export class Path {
|
||||||
return pathModule.isAbsolute(this.value)
|
return pathModule.isAbsolute(this.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not tested
|
||||||
|
// isDescendantOf(other: Path) {
|
||||||
|
// if (!(this.isAbsolute() && other.isAbsolute())) throw new Error("Both paths must be absolute")
|
||||||
|
// return pathModule.relative(this.value, other.value).split("/").includes("..")
|
||||||
|
// }
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return this.value
|
return this.value
|
||||||
}
|
}
|
||||||
|
|
13
src/utils.ts
13
src/utils.ts
|
@ -11,6 +11,8 @@ import addressWithCallback from "address"
|
||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
import { KeyvFile } from "keyv-file"
|
import { KeyvFile } from "keyv-file"
|
||||||
import originalGot from "got"
|
import originalGot from "got"
|
||||||
|
import { dirname } from "path"
|
||||||
|
import { without } from "lodash-es"
|
||||||
|
|
||||||
const keyvCache = new KeyvFile({
|
const keyvCache = new KeyvFile({
|
||||||
filename: paths.cache.resolve("http.json").toString(),
|
filename: paths.cache.resolve("http.json").toString(),
|
||||||
|
@ -80,14 +82,23 @@ export async function zipDirectory(directoryPath: Path, outputFilePath: Path) {
|
||||||
const zipFile = new ZipFile()
|
const zipFile = new ZipFile()
|
||||||
zipFile.outputStream.pipe(fs.createWriteStream(outputFilePath.toString()))
|
zipFile.outputStream.pipe(fs.createWriteStream(outputFilePath.toString()))
|
||||||
|
|
||||||
|
let emptyDirectories: string[] = []
|
||||||
await walk(directoryPath.toString(), async (error, path, dirent) => {
|
await walk(directoryPath.toString(), async (error, path, dirent) => {
|
||||||
if (error) return
|
if (error) return
|
||||||
if (directoryPath.toString() === path) return true
|
if (directoryPath.toString() === path) return true
|
||||||
if (dirent.name.startsWith(".")) return false
|
if (dirent.name.startsWith(".")) return false
|
||||||
|
|
||||||
if (dirent.isFile()) zipFile.addFile(path, directoryPath.relative(path).toString(), { compress: true })
|
if (dirent.isDirectory()) {
|
||||||
|
emptyDirectories.push(path)
|
||||||
|
} else if (dirent.isFile()) {
|
||||||
|
zipFile.addFile(path, directoryPath.relative(path).toString(), { compress: true })
|
||||||
|
} else return
|
||||||
|
|
||||||
|
emptyDirectories = without(emptyDirectories, dirname(path))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
emptyDirectories.forEach(p => zipFile.addEmptyDirectory(directoryPath.relative(p).toString()))
|
||||||
|
|
||||||
zipFile.end()
|
zipFile.end()
|
||||||
await pEvent(zipFile.outputStream, "close")
|
await pEvent(zipFile.outputStream, "close")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue