From 6f3d5bf54ce2a5d661d2ea8499d689f13ec46d66 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Thu, 18 Aug 2022 15:09:19 +0200 Subject: [PATCH] Respect enabled setting and fix packwiz export --- README.md | 5 +++ src/commands/packwiz/export.ts | 14 ++++++--- src/modrinth/exporting.ts | 5 +-- src/packwiz/exporting.ts | 8 ++--- src/utils/path.ts | 4 +-- test-pack/exports/packwiz/config/charm.ini | 1 - test-pack/exports/packwiz/index.toml | 31 ------------------- test-pack/exports/packwiz/mods/charm.toml | 13 -------- .../exports/packwiz/mods/fabric-api.toml | 13 -------- test-pack/exports/packwiz/mods/sodium.toml | 13 -------- test-pack/exports/packwiz/options.txt | 1 - test-pack/exports/packwiz/pack.toml | 13 -------- .../packwiz/resourcepacks/better-leaves.toml | 8 ----- test-pack/src/client/mods/sodium.hm.json | 1 + .../resourcepacks/better-leaves.hm.json | 3 +- test-pack/src/server/mods/lithium.hm.json | 1 + test-pack/src/universal/mods/charm.hm.json | 1 + 17 files changed, 29 insertions(+), 106 deletions(-) delete mode 100644 test-pack/exports/packwiz/config/charm.ini delete mode 100644 test-pack/exports/packwiz/index.toml delete mode 100644 test-pack/exports/packwiz/mods/charm.toml delete mode 100644 test-pack/exports/packwiz/mods/fabric-api.toml delete mode 100644 test-pack/exports/packwiz/mods/sodium.toml delete mode 100644 test-pack/exports/packwiz/options.txt delete mode 100644 test-pack/exports/packwiz/pack.toml delete mode 100644 test-pack/exports/packwiz/resourcepacks/better-leaves.toml diff --git a/README.md b/README.md index 5916abe..dfb2ac6 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,8 @@ I developed this tool primarily for my own packs, that’s 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 diff --git a/src/commands/packwiz/export.ts b/src/commands/packwiz/export.ts index f7a46c2..c205e82 100644 --- a/src/commands/packwiz/export.ts +++ b/src/commands/packwiz/export.ts @@ -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")}`) diff --git a/src/modrinth/exporting.ts b/src/modrinth/exporting.ts index 5338717..8a9f739 100644 --- a/src/modrinth/exporting.ts +++ b/src/modrinth/exporting.ts @@ -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 = { 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 diff --git a/src/packwiz/exporting.ts b/src/packwiz/exporting.ts index 8f771b4..477ff3b 100644 --- a/src/packwiz/exporting.ts +++ b/src/packwiz/exporting.ts @@ -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) }) diff --git a/src/utils/path.ts b/src/utils/path.ts index 7663e12..50787ce 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -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) } /** diff --git a/test-pack/exports/packwiz/config/charm.ini b/test-pack/exports/packwiz/config/charm.ini deleted file mode 100644 index a17e4d4..0000000 --- a/test-pack/exports/packwiz/config/charm.ini +++ /dev/null @@ -1 +0,0 @@ -test=42 diff --git a/test-pack/exports/packwiz/index.toml b/test-pack/exports/packwiz/index.toml deleted file mode 100644 index d2208d4..0000000 --- a/test-pack/exports/packwiz/index.toml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/test-pack/exports/packwiz/mods/charm.toml b/test-pack/exports/packwiz/mods/charm.toml deleted file mode 100644 index 4a5412e..0000000 --- a/test-pack/exports/packwiz/mods/charm.toml +++ /dev/null @@ -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" \ No newline at end of file diff --git a/test-pack/exports/packwiz/mods/fabric-api.toml b/test-pack/exports/packwiz/mods/fabric-api.toml deleted file mode 100644 index 338d3f3..0000000 --- a/test-pack/exports/packwiz/mods/fabric-api.toml +++ /dev/null @@ -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" \ No newline at end of file diff --git a/test-pack/exports/packwiz/mods/sodium.toml b/test-pack/exports/packwiz/mods/sodium.toml deleted file mode 100644 index f431ec7..0000000 --- a/test-pack/exports/packwiz/mods/sodium.toml +++ /dev/null @@ -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" \ No newline at end of file diff --git a/test-pack/exports/packwiz/options.txt b/test-pack/exports/packwiz/options.txt deleted file mode 100644 index 1e3d819..0000000 --- a/test-pack/exports/packwiz/options.txt +++ /dev/null @@ -1 +0,0 @@ -option=1 diff --git a/test-pack/exports/packwiz/pack.toml b/test-pack/exports/packwiz/pack.toml deleted file mode 100644 index 678351b..0000000 --- a/test-pack/exports/packwiz/pack.toml +++ /dev/null @@ -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" \ No newline at end of file diff --git a/test-pack/exports/packwiz/resourcepacks/better-leaves.toml b/test-pack/exports/packwiz/resourcepacks/better-leaves.toml deleted file mode 100644 index 3e537cb..0000000 --- a/test-pack/exports/packwiz/resourcepacks/better-leaves.toml +++ /dev/null @@ -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" \ No newline at end of file diff --git a/test-pack/src/client/mods/sodium.hm.json b/test-pack/src/client/mods/sodium.hm.json index 437c452..d9960c5 100644 --- a/test-pack/src/client/mods/sodium.hm.json +++ b/test-pack/src/client/mods/sodium.hm.json @@ -1,4 +1,5 @@ { + "formatVersion": 1, "enabled": true, "version": { "name": "mc1.18.2-0.4.1", diff --git a/test-pack/src/client/resourcepacks/better-leaves.hm.json b/test-pack/src/client/resourcepacks/better-leaves.hm.json index 3c0887f..417041e 100644 --- a/test-pack/src/client/resourcepacks/better-leaves.hm.json +++ b/test-pack/src/client/resourcepacks/better-leaves.hm.json @@ -1,5 +1,6 @@ { - "name": "Better Leaves", + "formatVersion": 1, + "displayName": "Better Leaves", "enabled": true, "side": "client-server", "version": { diff --git a/test-pack/src/server/mods/lithium.hm.json b/test-pack/src/server/mods/lithium.hm.json index 4d01cab..2419545 100644 --- a/test-pack/src/server/mods/lithium.hm.json +++ b/test-pack/src/server/mods/lithium.hm.json @@ -1,4 +1,5 @@ { + "formatVersion": 1, "enabled": true, "version": { "name": "mc1.18.2-0.7.10", diff --git a/test-pack/src/universal/mods/charm.hm.json b/test-pack/src/universal/mods/charm.hm.json index 6df7dad..f1fd65a 100644 --- a/test-pack/src/universal/mods/charm.hm.json +++ b/test-pack/src/universal/mods/charm.hm.json @@ -1,4 +1,5 @@ { + "formatVersion": 1, "displayName": "Charm", "enabled": true, "version": {