Respect enabled setting and fix packwiz export

This commit is contained in:
Moritz Ruth 2022-08-18 15:09:19 +02:00
parent 2d1f3156c9
commit 6f3d5bf54c
17 changed files with 29 additions and 106 deletions

View file

@ -33,3 +33,8 @@ I developed this tool primarily for my own packs, thats why its missing some
Nevertheless, if you want a feature added, feel free to [create an issue](https://github.com/horizr/cli/issues/new).
A pull request would be even better.
Features I have in mind:
- List disabled source files
- Allow disabling static source files by adding `.disabled` to their name
- Import packwiz packs

View file

@ -21,8 +21,12 @@ export const exportCommand = new Command("export")
let i = 0
for (const metaFile of pack.metaFiles) {
i++
loader.setText(`Exporting ${kleur.yellow(metaFile.getDisplayString())} (${i}/${pack.metaFiles.length})`)
await writeAndIndexMetaFile(indexedFiles, outputDirectoryPath, metaFile)
if (!metaFile.content.enabled) continue
await output.withLoading(
writeAndIndexMetaFile(indexedFiles, outputDirectoryPath, metaFile),
`Exporting ${kleur.yellow(metaFile.getDisplayString())} (${i}/${pack.metaFiles.length})`
)
}
i = 0
@ -30,8 +34,10 @@ export const exportCommand = new Command("export")
i++
if (staticSourceFile.side !== "universal" && staticSourceFile.side !== side) continue
loader.setText(`Exporting ${kleur.yellow(staticSourceFile.relativePath.toString())} (${i}/${pack.metaFiles.length})`)
await writeAndIndexStaticSourceFile(indexedFiles, outputDirectoryPath, staticSourceFile)
await output.withLoading(
writeAndIndexStaticSourceFile(indexedFiles, outputDirectoryPath, staticSourceFile),
`Exporting ${kleur.yellow(staticSourceFile.relativePath.toString())} (${i}/${pack.metaFiles.length})`
)
}
loader.setText(`Creating ${kleur.yellow("index.toml")} and ${kleur.yellow("pack.toml")}`)

View file

@ -3,6 +3,7 @@ import { output } from "../utils/output.js"
import fs from "fs-extra"
import { Side, usePack } from "../pack.js"
import kleur from "kleur"
import { mapNotNull } from "../utils/collections.js"
const overridesDirectoryNameBySide: Record<Side, string> = {
client: "client-overrides",
@ -25,7 +26,7 @@ export async function generateOutputDirectory(outputDirectoryPath: AbsolutePath)
minecraft: pack.manifest.versions.minecraft,
"fabric-loader": pack.manifest.versions.fabric
},
files: pack.metaFiles.map(metaFile => ({
files: mapNotNull(pack.metaFiles, metaFile => metaFile.content.enabled ? ({
path: metaFile.effectivePath.toString(),
hashes: {
sha1: metaFile.content.version.hashes.sha1,
@ -39,7 +40,7 @@ export async function generateOutputDirectory(outputDirectoryPath: AbsolutePath)
metaFile.content.version.downloadUrl
],
fileSize: metaFile.content.version.size
}))
}) : null)
}, { spaces: 2 })
let i = 0

View file

@ -53,17 +53,17 @@ export async function writeAndIndexMetaFile(indexedFiles: IndexedFile[], outputD
url = ${JSON.stringify(metaFile.content.version.downloadUrl)}${updateSection}
`
const effectiveOutputPath = metaFile.effectivePath
const relativeOutputPath = metaFile.effectivePath
.parent()
.joinedWith(metaFile.effectivePath.getBasename().slice(0, -1 * META_FILE_EXTENSION.length) + "toml")
.joinedWith(metaFile.absolutePath.getBasename(META_FILE_EXTENSION) + ".toml")
const outputPath = outputDirectoryPath.resolve(effectiveOutputPath)
const outputPath = outputDirectoryPath.resolve(relativeOutputPath)
await fs.mkdirp(outputPath.parent().toString())
await fs.writeFile(outputPath.toString(), content)
indexedFiles.push({
path: metaFile.effectivePath,
path: relativeOutputPath,
isMeta: true,
sha512HashHex: await computeSha512HexHash(content)
})

View file

@ -94,8 +94,8 @@ export class AbsolutePath implements AbstractPath {
return this.pathString === (typeof other === "string" ? pathModule.normalize(other) : other.toString())
}
getBasename(): string {
return pathModule.basename(this.pathString)
getBasename(stripExtension?: string): string {
return pathModule.basename(this.pathString, "." + stripExtension)
}
/**

View file

@ -1 +0,0 @@
test=42

View file

@ -1,31 +0,0 @@
hash-format = "sha512"
[[files]]
file = "mods/sodium.hm.json"
hash = "955b4e74bc9b1988cdbcfa659fb977997ebf99dbd701e4b2aa6175cacd4a763b39399ea5e16db5536cb59708e0f9ce84746c1611519c0689d640da6752b496e3"
metafile = true
[[files]]
file = "resourcepacks/better-leaves.hm.json"
hash = "81fc1a6887ad61e4ed5662d7173efd743280bd2ad640fdebd495b30ee915bdbe9b2882b55ca7dabac155ba1e4520ad3957f76cc1ac98dce0ef7087d3c07beed9"
metafile = true
[[files]]
file = "mods/charm.hm.json"
hash = "c388539aa188902f671e27de1bf8306ded8ed1ba7dc5cb3a9fd3b6f13895a789255d36c025b1ef2172c6123d99e28201660c83657d7d36a318c4387249c69931"
metafile = true
[[files]]
file = "mods/fabric-api.hm.json"
hash = "c9ca7daa8ed64738ddd1fa4d334e14e768623322e25f6f8eb38ac616bbef1b3823e55136b22ff7f1e88adec98b44b2ebdb6981ccff0c7e6f1acd4ca91f82c594"
metafile = true
[[files]]
file = "options.txt"
hash = "41ab8c11939b9379f97739cd998a44dae98f92fd3715253d14d979987a22e8ca7c5799396efc3951e16597346c590ae0bbbbf31dba9d7004c4459a3930322f20"
metafile = false
[[files]]
file = "config/charm.ini"
hash = "21ed919c05480f55d202dc97c33ae55d897acec162ac75d5f62d914ce5a18fbaac83dc631d4690896e3b6135da1305d0f3f73e1df3b54fbc777b186367ba421d"
metafile = false

View file

@ -1,13 +0,0 @@
name = "Charm"
filename = "charm-fabric-1.18.2-4.2.0.jar"
side = "both"
[download]
hash-format = "sha512"
hash = "3c8cd08ab1e37dcbf0f5a956cd20d84c98e58ab49fdc13faafb9c2af4dbf7fba7c8328cb5365997fe4414cfc5cb554ed13b3056a22df1c6bd335594f380facb6"
url = "https://cdn.modrinth.com/data/pOQTcQmj/versions/4.2.0+1.18.2/charm-fabric-1.18.2-4.2.0.jar"
[update]
[update.modrinth]
mod-id = "pOQTcQmj"
version = "BT9G1Jjs"

View file

@ -1,13 +0,0 @@
name = "Fabric API"
filename = "fabric-api-0.58.0+1.18.2.jar"
side = "both"
[download]
hash-format = "sha512"
hash = "92317b8d48b20d1b370ab67e4954d1db4861b8fb561935edc0c0fc8a525fefbd3c159f3cfbf83ec3455e3179561fab554645138c6d79f5f597abea77dc1a03ed"
url = "https://cdn.modrinth.com/data/P7dR8mSH/versions/0.58.0+1.18.2/fabric-api-0.58.0%2B1.18.2.jar"
[update]
[update.modrinth]
mod-id = "P7dR8mSH"
version = "4XRtXhtL"

View file

@ -1,13 +0,0 @@
name = "Sodium"
filename = "sodium-fabric-mc1.18.2-0.4.1+build.15.jar"
side = "client"
[download]
hash-format = "sha512"
hash = "86eb4db8fdb9f0bb06274c4f150b55273b5b770ffc89e0ba68011152a231b79ebe0b1adda0dd194f92cdcb386f7a60863d9fee5d15c1c3547ffa22a19083a1ee"
url = "https://cdn.modrinth.com/data/AANobbMI/versions/mc1.18.2-0.4.1/sodium-fabric-mc1.18.2-0.4.1%2Bbuild.15.jar"
[update]
[update.modrinth]
mod-id = "AANobbMI"
version = "74Y5Z8fo"

View file

@ -1 +0,0 @@
option=1

View file

@ -1,13 +0,0 @@
name = "Test"
author = "John Doe"
description = "A test pack for testing the horizr CLI. It is not intended for playing."
pack-format = "packwiz:1.1.0"
[versions]
minecraft = "1.18.2"
fabric = "0.14.7"
[index]
file = "index.toml"
hash-format = "sha512"
hash = "8173efc3a86743de3b35e88cb01fbe10f12b13ce4c99fd730abaeb81ee88d736078cc2dfcf45a12b36ded174c73ac59304f6074b2ec916babc5c941adc170299"

View file

@ -1,8 +0,0 @@
name = "better-leaves.hm.json"
filename = "Better-Leaves.zip"
side = "client"
[download]
hash-format = "sha512"
hash = "7a1a5f925251db5cd19e3ce44f5acdf3941221b20e40c253b8c451adaa406c4d4d66dd424244802e34029f4a14ed2594f4e1c550c7c48dc365c8d9ebfc0cd817"
url = "https://mediafiles.forgecdn.net/files/3814/725/Better-Leaves-7.0-1.13%2B.zip"

View file

@ -1,4 +1,5 @@
{
"formatVersion": 1,
"enabled": true,
"version": {
"name": "mc1.18.2-0.4.1",

View file

@ -1,5 +1,6 @@
{
"name": "Better Leaves",
"formatVersion": 1,
"displayName": "Better Leaves",
"enabled": true,
"side": "client-server",
"version": {

View file

@ -1,4 +1,5 @@
{
"formatVersion": 1,
"enabled": true,
"version": {
"name": "mc1.18.2-0.7.10",

View file

@ -1,4 +1,5 @@
{
"formatVersion": 1,
"displayName": "Charm",
"enabled": true,
"version": {