Skip to content

Commit

Permalink
add version aliases and change package command
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Jan 23, 2021
1 parent 0b57749 commit 16ee97a
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .run/CLI generateSchema.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="CLI generateSchema" type="JetRunConfigurationType">
<module name="voodoo-parent.voodoo.main" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="--log trace generate schema" />
<option name="PROGRAM_PARAMETERS" value="--log trace generateSchema" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI pack fabricPack all.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="CLI package fabricPack all" type="JetRunConfigurationType">
<module name="voodoo-parent.voodoo.main" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="package --id fabricPack -t voodoo -t mmc-voodoo -t mmc-fat -t server -t curse" />
<option name="PROGRAM_PARAMETERS" value="package fabricPack/modpack.meta.json voodoo mmc-voodoo mmc-fat server curse" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI pack fabricPack voodoo.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration default="false" name="CLI package fabricPack voodoo" type="JetRunConfigurationType">
<module name="voodoo-parent.voodoo.main" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="package --id fabricPack -t voodoo" />
<option name="PROGRAM_PARAMETERS" value="package fabricPack/modpack.meta.json voodoo" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
Expand Down
6 changes: 3 additions & 3 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ voodoo launch multimc magicpack/v0.0.1.voodoo.json
## Packaging and Upload

```bash
voodoo package --id magicpack --target voodoo --target mmc-voodoo --target server
voodoo package magicpack/modpack/meta.json voodoo mmc-voodoo server
```

this created `/_upload/voodoo/`, `/_upload/multimc-voodoo` and `/_upload/server/`
Expand All @@ -265,9 +265,9 @@ upload the content of `/_upload/voodoo/` to `$uploadBaseUrl` (configured in `/ma
make sure to *NOT DELETE* existing files on the fileserver

example with `"uploadBaseUrl": "https://mydomain.com/mc/"`
`/_upload/voodoo/packages.json` should be accessible from `https://mydomain.com/mc/packages.json`
`/_upload/voodoo/magicpack.json` should be accessible from `https://mydomain.com/mc/magicpack.json`

`/_upload/multimc-voodoo` contains multimc instances that selfupdate (TODO: currently it create a zip for each version, but they all selfupdate?)
`/_upload/multimc-voodoo` contains multimc instances that selfupdate

### Deploy server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ object PackageBuilder : KLogging() {
installerLocation: String,
modpackTitle: String = modpackId,
modpackVersion: String,
versionAlias: Map<String, String> = mapOf(),
gameVersion: String,
modLoader: Modloader,
objectsLocation: String = "objects",
userFiles: FnPatternList = FnPatternList(),
features: List<FeatureWithPattern> = listOf(),
prettyPrint: Boolean = true
prettyPrint: Boolean = true,
) {
val manifestDest: File = outputPath.resolve("${modpackId}_${modpackVersion}.json")
val versionlistingFile: File = outputPath.resolve("$modpackId.json")
Expand Down Expand Up @@ -143,10 +144,14 @@ object PackageBuilder : KLogging() {
location = manifestDest.toRelativeUnixPath(versionlistingFile.absoluteFile.parentFile)
)

//TODO: add updateChannels to version listing
// add aliases / updateChannels to version listing

val aliasEntries = versionAlias
.filterValues { version -> version == modpackVersion }.keys
.map { alias -> alias to versionEntry }

val newVersionListing = versionsListing.copy(
versions = versionsListing.versions + (modpackVersion to versionEntry)
versions = versionsListing.versions + (modpackVersion to versionEntry) + aliasEntries
)

versionlistingFile.writeText(
Expand Down
3 changes: 2 additions & 1 deletion pack/src/main/kotlin/voodoo/Pack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ object Pack : KLogging() {
CursePack
).associateBy { it.id }

suspend fun pack(stopwatch: Stopwatch, modpack: LockPack, uploadBaseDir: File, packer: AbstractPack) = stopwatch {
suspend fun pack(stopwatch: Stopwatch, modpack: LockPack, config: PackConfig, uploadBaseDir: File, packer: AbstractPack) = stopwatch {
val output = with(packer) { uploadBaseDir.getOutputFolder(id = modpack.id, version = modpack.version) }
output.mkdirs()

packer.pack(
stopwatch = "${packer.label}-timer".watch,
modpack = modpack,
config = config,
output = output,
uploadBaseDir = uploadBaseDir,
clean = true
Expand Down
3 changes: 1 addition & 2 deletions pack/src/main/kotlin/voodoo/pack/AbstractPack.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package voodoo.pack

import com.eyeem.watchadoin.Stopwatch
import mu.KLogging
import voodoo.data.lock.LockPack
import voodoo.util.Directories
import java.io.File

/**
Expand All @@ -23,6 +21,7 @@ abstract class AbstractPack(open val id: String) {
abstract suspend fun pack(
stopwatch: Stopwatch,
modpack: LockPack,
config: PackConfig,
output: File,
uploadBaseDir: File,
clean: Boolean = true
Expand Down
1 change: 1 addition & 0 deletions pack/src/main/kotlin/voodoo/pack/CursePack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object CursePack : AbstractPack("curse") {
override suspend fun pack(
stopwatch: Stopwatch,
modpack: LockPack,
config: PackConfig,
output: File,
uploadBaseDir: File,
clean: Boolean
Expand Down
1 change: 1 addition & 0 deletions pack/src/main/kotlin/voodoo/pack/MMCFatPack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object MMCFatPack : AbstractPack("mmc-fat") {
override suspend fun pack(
stopwatch: Stopwatch,
modpack: LockPack,
config: PackConfig,
output: File,
uploadBaseDir: File,
clean: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import voodoo.util.Directories
import voodoo.util.blankOr
import voodoo.util.maven.MavenUtil
import voodoo.util.packToZip
import voodoo.util.unixPath
import java.io.File
import java.net.URI
import kotlin.system.exitProcess
Expand All @@ -22,6 +21,7 @@ object MMCSelfupdatingPackVoodoo : AbstractPack("mmc-voodoo") {
override suspend fun pack(
stopwatch: Stopwatch,
modpack: LockPack,
config: PackConfig,
output: File,
uploadBaseDir: File,
clean: Boolean
Expand Down
8 changes: 8 additions & 0 deletions pack/src/main/kotlin/voodoo/pack/PackConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package voodoo.pack

import kotlinx.serialization.Serializable

@Serializable
data class PackConfig(
val versionAlias: Map<String, String> = mapOf()
)
5 changes: 1 addition & 4 deletions pack/src/main/kotlin/voodoo/pack/ServerPack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package voodoo.pack

import com.eyeem.watchadoin.Stopwatch
import mu.KotlinLogging
import voodoo.data.lock.LockEntry
import voodoo.data.lock.LockPack
import voodoo.util.Directories
import voodoo.util.maven.MavenUtil
import voodoo.util.packToZip
import voodoo.util.toJson
import voodoo.util.unixPath
import java.io.File

/**
Expand All @@ -26,6 +22,7 @@ object ServerPack : AbstractPack("server") {
override suspend fun pack(
stopwatch: Stopwatch,
modpack: LockPack,
config: PackConfig,
output: File,
uploadBaseDir: File,
clean: Boolean
Expand Down
5 changes: 2 additions & 3 deletions pack/src/main/kotlin/voodoo/pack/VoodooPackager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import voodoo.provider.Providers
import voodoo.util.*
import voodoo.util.maven.MavenUtil
import java.io.File
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

/**
* Created by nikky on 30/03/18.
Expand All @@ -33,6 +30,7 @@ object VoodooPackager : AbstractPack("voodoo") {
override suspend fun pack(
stopwatch: Stopwatch,
modpack: LockPack,
config: PackConfig,
output: File,
uploadBaseDir: File,
clean: Boolean
Expand Down Expand Up @@ -250,6 +248,7 @@ object VoodooPackager : AbstractPack("voodoo") {
installerLocation = installer.toRelativeString(output).replace('\\', '/'),
modpackTitle = modpack.title ?: modpack.id,
modpackVersion = modpack.version,
versionAlias = config.versionAlias,
gameVersion = modpack.mcVersion,
// thumb = thumb, // TODO:
modLoader = modloader,
Expand Down
2 changes: 1 addition & 1 deletion samples/fabricpack/lock/0.0.2/lock.pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"installer": "0.6.1.51"
},
"version": "0.0.2",
"icon": "icon_fabricPack.png",
"icon": "../local/256.png",
"packOptions": {
"uploadUrl": "https://nikky.moe/.mc/voodoo/fabricPack"
},
Expand Down
2 changes: 1 addition & 1 deletion samples/fabricpack/lock/0.0.3/lock.pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"installer": "0.6.1.51"
},
"version": "0.0.3",
"icon": "icon_fabricPack.png",
"icon": "../local/256.png",
"packOptions": {
"uploadUrl": "https://nikky.moe/.mc/voodoo/fabricPack"
},
Expand Down
Binary file added samples/fabricpack/lock/local/256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion samples/fabricpack/modpack.meta.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"$schema": "../schema/metaPack.schema.json",
"title": "FabricPack Test",
"icon": "icon_fabricPack.png",
"icon": "../local/256.png",
"authors": [
"nikky"
],
"packConfig": {
"versionAlias": {
"latest": "0.0.3"
}
},
"uploadBaseUrl": "https://nikky.moe/.mc/voodoo/"
}
43 changes: 31 additions & 12 deletions voodoo/src/main/kotlin/voodoo/cli/PackageCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.eyeem.watchadoin.saveAsHtml
import com.eyeem.watchadoin.saveAsSvg
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.requireObject
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.arguments.validate
import com.github.ajalt.clikt.parameters.options.multiple
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
Expand All @@ -17,8 +20,11 @@ import mu.KotlinLogging
import mu.withLoggingContext
import voodoo.Pack
import voodoo.data.lock.LockPack
import voodoo.pack.MetaPack
import voodoo.pack.VersionPack
import voodoo.util.SharedFolders
import voodoo.util.VersionComparator
import voodoo.util.json
import java.io.File

class PackageCommand(): CliktCommand(
Expand All @@ -28,17 +34,27 @@ class PackageCommand(): CliktCommand(
private val logger = KotlinLogging.logger {}
val cliContext by requireObject<CLIContext>()

val id by option(
"--id",
help = "pack id"
).required()
.validate {
require(it.isNotBlank()) { "id must not be blank" }
require(it.matches("""[\w_]+""".toRegex())) { "modpack id must not contain special characters" }
val metaPackFile by argument(
"META_FILE",
"path to ${MetaPack.FILENAME} file"
).file(mustExist = true, canBeFile = true, canBeDir = false)
.validate { file ->
require(file.name == MetaPack.FILENAME) {
"file $file does not end with ${VersionPack.extension}"
}
}

val packTargets by option(
"--target", "-t"
// val id by option(
// "--id",
// help = "pack id"
// ).required()
// .validate {
// require(it.isNotBlank()) { "id must not be blank" }
// require(it.matches("""[\w_]+""".toRegex())) { "modpack id must not contain special characters" }
// }

val packTargets by argument(
"TARGET", "pack targets"
).choice(Pack.packMap)
.multiple()

Expand All @@ -51,10 +67,13 @@ class PackageCommand(): CliktCommand(
val stopwatch = Stopwatch(commandName)

val rootDir = cliContext.rootDir
val baseDir = rootDir.resolve(id)
// val baseDir = rootDir.resolve(id)

stopwatch {
val baseDir = metaPackFile.absoluteFile.parentFile
val id = baseDir.name

stopwatch {
val metaPack = json.decodeFromString(MetaPack.serializer(), metaPackFile.readText())
val uploadDir = uploadDirOption ?: SharedFolders.UploadDir.get(id)

packTargets.toSet().forEach { packTarget ->
Expand All @@ -68,7 +87,7 @@ class PackageCommand(): CliktCommand(
withLoggingContext("version" to lockpack.version) {
launch(MDCContext() + CoroutineName("package-version-${lockpack.version}")) {
// TODO: pass pack method (enum / object)
Pack.pack("pack-${packTarget.id}".watch, lockpack, uploadDir, packTarget)
Pack.pack("pack-${packTarget.id}".watch, lockpack, metaPack.packConfig, uploadDir, packTarget)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions voodoo/src/main/kotlin/voodoo/pack/MetaPack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class MetaPack (
val title: String? = null,
val authors: List<String> = listOf(),
val icon: String = "icon.png",
val packConfig: PackConfig = PackConfig(),
// upload location //TODO: ensure this upload path is unique (or append $id), maybe grab baseUrl from config.json ?
var uploadBaseUrl: String,
) {
Expand Down

0 comments on commit 16ee97a

Please sign in to comment.