factorio mod deploy tweaks (better confirmation and link to the page)

This commit is contained in:
Adam 2022-06-19 11:29:07 +02:00
parent 0398e2026d
commit d2768c3c9e
3 changed files with 37 additions and 14 deletions

View file

@ -36,6 +36,7 @@ class FactorioModPortalPublishClient(
private val modVersion: String, private val modVersion: String,
private val portalApiKey: String, private val portalApiKey: String,
private val portalUploadEndpoint: String, private val portalUploadEndpoint: String,
private val modPortalBaseURl: String,
) { ) {
private fun client() = HttpClient(CIO) { private fun client() = HttpClient(CIO) {
@ -61,11 +62,18 @@ class FactorioModPortalPublishClient(
client().useToRun { client().useToRun {
val initUploadResponse = initUpload() val initUploadResponse = initUpload()
val confirmation = userInputHandler val enteredVersion = userInputHandler
.askQuestion("Are you sure you want to publish $modName:$modVersion?", "no") .askQuestion(
.toBooleanLenient() ?: false """
|Are you sure you want to publish $modName:$modVersion?
|Enter the version number to confirm:
""".trimMargin(),
"",
)
if (confirmation) { val confirmed = enteredVersion.trim() == modVersion.trim()
if (confirmed) {
upload(initUploadResponse) upload(initUploadResponse)
} else { } else {
println("aborting upload") println("aborting upload")
@ -120,6 +128,7 @@ class FactorioModPortalPublishClient(
require(response.status.isSuccess() && submitUploadResponse is SubmitUploadResponse.Success) { require(response.status.isSuccess() && submitUploadResponse is SubmitUploadResponse.Success) {
"upload request failed" "upload request failed"
} }
println("Mod uploaded successfully! ${modPortalBaseURl.removeSuffix("/")}/$modName")
} }
companion object { companion object {

View file

@ -44,6 +44,15 @@ abstract class FactorioModPublishTask @Inject constructor(
val portalApiUrl: Property<String> = objects.property<String>() val portalApiUrl: Property<String> = objects.property<String>()
.convention("https://mods.factorio.com/api/v2/") .convention("https://mods.factorio.com/api/v2/")
/**
* Base URL for linking to a mod page in the portal
*
* Example `https://mods.factorio.com/mod/my-mod-name`
*/
@get:Input
val modPortalBaseURl: Property<String> = objects.property<String>()
.convention("https://mods.factorio.com/mod/")
@get:Input @get:Input
val portalUploadEndpoint: Property<String> = objects.property<String>() val portalUploadEndpoint: Property<String> = objects.property<String>()
.convention("mods/releases/init_upload") .convention("mods/releases/init_upload")
@ -65,12 +74,13 @@ abstract class FactorioModPublishTask @Inject constructor(
.buildString() .buildString()
val client = FactorioModPortalPublishClient( val client = FactorioModPortalPublishClient(
userInputHandler, userInputHandler = userInputHandler,
distributionZip.get().asFile, distributionZip = distributionZip.get().asFile,
modName.get(), modName = modName.get(),
modVersion.get(), modVersion = modVersion.get(),
portalApiKey.get(), portalApiKey = portalApiKey.get(),
portalUploadEndpoint, portalUploadEndpoint = portalUploadEndpoint,
modPortalBaseURl = modPortalBaseURl.get(),
) )
client.uploadMod() client.uploadMod()

View file

@ -9,7 +9,8 @@
"engines": { "engines": {
"node": "~14.19.1" "node": "~14.19.1"
}, },
"devDependencies": {}, "devDependencies": {
},
"dependencies": { "dependencies": {
"lua-types": "^2.11.0", "lua-types": "^2.11.0",
"typescript-to-lua": "1.6.0", "typescript-to-lua": "1.6.0",
@ -17,7 +18,10 @@
"typescript": "4.7.4" "typescript": "4.7.4"
}, },
"license": "UNLICENSED", "license": "UNLICENSED",
"peerDependencies": {}, "peerDependencies": {
"optionalDependencies": {}, },
"bundledDependencies": [] "optionalDependencies": {
},
"bundledDependencies": [
]
} }