mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-09-30 04:59:05 +02:00
CreateModlist will now accept an "all" option to not only add mods to the list
CreateModlist will now use not only client relations if no link is specified, there will be no href in the mod list
This commit is contained in:
parent
93cef01984
commit
dbc0892753
2 changed files with 27 additions and 17 deletions
|
@ -21,7 +21,7 @@ import java.nio.charset.StandardCharsets
|
||||||
@LoadCommand
|
@LoadCommand
|
||||||
object CreateModlist : ICommand {
|
object CreateModlist : ICommand {
|
||||||
override val name: String = "createmodlist"
|
override val name: String = "createmodlist"
|
||||||
override val helpMessage: String = "This creates a modlist either as html or csv file. Syntax: <html/csv> outFile"
|
override val helpMessage: String = "This creates a modlist either as html or csv file. if the \'all\' option is supplied, not only mods will be included Syntax: <html/csv> <outFile> [all]"
|
||||||
|
|
||||||
override fun execute(args: Array<out String>): CommandReturn {
|
override fun execute(args: Array<out String>): CommandReturn {
|
||||||
if(!args.checkArgs())
|
if(!args.checkArgs())
|
||||||
|
@ -32,20 +32,21 @@ object CreateModlist : ICommand {
|
||||||
if(outFile.exists())
|
if(outFile.exists())
|
||||||
return fail("File already exists!")
|
return fail("File already exists!")
|
||||||
|
|
||||||
|
val all = args.getOrNull(3) == "all"
|
||||||
return if(args[1] == "html")
|
return if(args[1] == "html")
|
||||||
doHtml(outFile)
|
doHtml(outFile, all)
|
||||||
else
|
else
|
||||||
doCsv(outFile)
|
doCsv(outFile, all)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doCsv(outFile: File): CommandReturn {
|
private fun doCsv(outFile: File, all: Boolean): CommandReturn {
|
||||||
println("Making CSV file $outFile")
|
println("Making CSV file $outFile")
|
||||||
val printer = CSVPrinter(FileWriter(outFile), CSVFormat.EXCEL.withDelimiter(';'))
|
val printer = CSVPrinter(FileWriter(outFile), CSVFormat.EXCEL.withDelimiter(';'))
|
||||||
|
|
||||||
printer.printRecord("Name", "Contributors", "Link")
|
printer.printRecord("Name", "Contributors", "Link")
|
||||||
printer.println()
|
printer.println()
|
||||||
|
|
||||||
for(mod in getMods()) {
|
for(mod in getMods(all)) {
|
||||||
printer.printRecord(
|
printer.printRecord(
|
||||||
mod.name,
|
mod.name,
|
||||||
mod.contributors.keys.joinToString(),
|
mod.contributors.keys.joinToString(),
|
||||||
|
@ -57,7 +58,7 @@ object CreateModlist : ICommand {
|
||||||
return success("Wrote CSV file")
|
return success("Wrote CSV file")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doHtml(outFile: File): CommandReturn {
|
private fun doHtml(outFile: File, all: Boolean): CommandReturn {
|
||||||
println("Making HTML file $outFile")
|
println("Making HTML file $outFile")
|
||||||
val writer = FileWriter(outFile)
|
val writer = FileWriter(outFile)
|
||||||
val html = html(
|
val html = html(
|
||||||
|
@ -75,18 +76,22 @@ object CreateModlist : ICommand {
|
||||||
td(b("Contributors")),
|
td(b("Contributors")),
|
||||||
td(b("Description"))
|
td(b("Description"))
|
||||||
),
|
),
|
||||||
each(getMods()) {
|
each(getMods(all)) {
|
||||||
tr(
|
tr(
|
||||||
td(if(it.icon != null) a(
|
td(if(it.icon != null) a(
|
||||||
img().withSrc(it.icon)
|
img().withSrc(it.icon)
|
||||||
.withClass("img")
|
.withClass("img")
|
||||||
).withHref(it.website) else null
|
).withHref(it.website) else null
|
||||||
),
|
),
|
||||||
td(a(it.name)
|
td(run {
|
||||||
.withHref(it.website)
|
val a = a(it.name)
|
||||||
//Open in new tab
|
//Open in new tab
|
||||||
.withRel("noopener noreferrer")
|
.withRel("noopener noreferrer")
|
||||||
.withTarget("_blank")),
|
.withTarget("_blank")
|
||||||
|
if(it.website != null)
|
||||||
|
a.withHref(it.website)
|
||||||
|
a
|
||||||
|
}),
|
||||||
td(ul(
|
td(ul(
|
||||||
each(it.contributors) {contr ->
|
each(it.contributors) {contr ->
|
||||||
li(contr.key)
|
li(contr.key)
|
||||||
|
@ -106,13 +111,13 @@ object CreateModlist : ICommand {
|
||||||
return success("Wrote HTML file")
|
return success("Wrote HTML file")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMods(): List<MetaData> {
|
private fun getMods(all: Boolean): List<MetaData> {
|
||||||
println("Getting mods...")
|
println("Getting mods...")
|
||||||
val asJson = MPJH.asWrapper
|
val asJson = MPJH.asWrapper
|
||||||
val mods = mutableListOf<MetaData>()
|
val mods = mutableListOf<MetaData>()
|
||||||
val toGet = mutableListOf<ArtifactDestination>()
|
val toGet = mutableListOf<ArtifactDestination>()
|
||||||
|
|
||||||
for(rel in asJson!!.defaultVersion.getRelations(arrayOf("client"), arrayOf("mod", "modloader"))) {
|
for(rel in asJson!!.defaultVersion.getRelations(arrayOf("included"), /*null means all*/ if(all) null else arrayOf("mod"))) {
|
||||||
if(rel.hasLocalMeta())
|
if(rel.hasLocalMeta())
|
||||||
mods.add(rel.localMeta)
|
mods.add(rel.localMeta)
|
||||||
else if(rel.hasFile() && rel.file.isArtifact)
|
else if(rel.hasFile() && rel.file.isArtifact)
|
||||||
|
@ -122,6 +127,11 @@ object CreateModlist : ICommand {
|
||||||
return mods.sortedBy {m -> m.name?.toLowerCase()}
|
return mods.sortedBy {m -> m.name?.toLowerCase()}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Array<out String>.checkArgs(): Boolean = this.size >= 3 && this[1] in arrayOf("html", "csv")
|
private fun Array<out String>.checkArgs(): Boolean =
|
||||||
|
//must be right length
|
||||||
|
this.size >= 3 &&
|
||||||
|
//second option must be html or csv
|
||||||
|
this[1] in arrayOf("html", "csv") &&
|
||||||
|
//3rd option must either be "all" or nothing
|
||||||
|
this.getOrElse(3) {"all"} == "all"
|
||||||
}
|
}
|
|
@ -87,7 +87,7 @@ open class FileDownloader(
|
||||||
val responseCode: Int?,
|
val responseCode: Int?,
|
||||||
val responseMessage: String?,
|
val responseMessage: String?,
|
||||||
val exception: Exception?
|
val exception: Exception?
|
||||||
) {}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ExistingFileBehaviour {
|
enum class ExistingFileBehaviour {
|
||||||
|
|
Loading…
Reference in a new issue