mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Add build constant auto-fill
This commit is contained in:
parent
16cba3a87d
commit
7ac1d94db9
@ -1,4 +1,6 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import upload.Bintray
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
@ -74,6 +76,33 @@ tasks {
|
||||
"test"(Test::class) {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
val compileKotlin by getting {}
|
||||
|
||||
val fillBuildConstants by registering {
|
||||
doLast {
|
||||
(compileKotlin as KotlinCompile).source.filter { it.name == "MiraiConsole.kt" }.single().let { file ->
|
||||
file.writeText(file.readText()
|
||||
.replace(Regex("""val buildDate: Date = Date\((.*)\) //(.*)""")) {
|
||||
"""
|
||||
val buildDate: Date = Date(${System.currentTimeMillis()}) // ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").apply {
|
||||
timeZone = TimeZone.getTimeZone("GMT+8")
|
||||
}.format(Date())}
|
||||
""".trimIndent()
|
||||
}
|
||||
.replace(Regex("""const val version: String = "(.*)"""")) {
|
||||
"""
|
||||
const val version: String = "${Versions.console}"
|
||||
""".trimIndent()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"compileKotlin" {
|
||||
dependsOn(fillBuildConstants)
|
||||
}
|
||||
}
|
||||
|
||||
// region PUBLISHING
|
||||
|
@ -13,6 +13,8 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.io.charsets.Charset
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.center.CuiPluginCenter
|
||||
import net.mamoe.mirai.console.center.PluginCenter
|
||||
import net.mamoe.mirai.console.plugin.PluginLoader
|
||||
import net.mamoe.mirai.console.plugin.jvm.JarPluginLoader
|
||||
import net.mamoe.mirai.utils.DefaultLogger
|
||||
@ -21,6 +23,7 @@ import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.util.*
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
internal object MiraiConsoleInitializer {
|
||||
@ -33,26 +36,34 @@ internal object MiraiConsoleInitializer {
|
||||
|
||||
}
|
||||
|
||||
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
|
||||
@JvmStatic
|
||||
val buildDate: Date = Date(1592720608995) // 2020-06-21 14:23:28
|
||||
const val version: String = "0.5.1"
|
||||
}
|
||||
|
||||
/**
|
||||
* mirai 控制台实例.
|
||||
*/
|
||||
object MiraiConsole : CoroutineScope, IMiraiConsole {
|
||||
val pluginCenter: PluginCenter get() = CuiPluginCenter
|
||||
|
||||
private val instance: IMiraiConsole
|
||||
get() = MiraiConsoleInitializer.instance
|
||||
|
||||
/**
|
||||
* `mirai-console` build 号
|
||||
*
|
||||
* UTC+8 时间
|
||||
*/
|
||||
@MiraiExperimentalAPI
|
||||
override val build: String
|
||||
get() = instance.build
|
||||
@JvmStatic
|
||||
val buildDate: Date
|
||||
get() = MiraiConsoleBuildConstants.buildDate
|
||||
|
||||
/**
|
||||
* `mirai-console` 版本
|
||||
*/
|
||||
@MiraiExperimentalAPI
|
||||
override val version: String
|
||||
get() = instance.version
|
||||
const val version: String = MiraiConsoleBuildConstants.version
|
||||
|
||||
/**
|
||||
* Console 运行路径
|
||||
@ -89,9 +100,6 @@ object MiraiConsole : CoroutineScope, IMiraiConsole {
|
||||
|
||||
// 前端使用
|
||||
internal interface IMiraiConsole : CoroutineScope {
|
||||
val build: String
|
||||
val version: String
|
||||
|
||||
/**
|
||||
* Console 运行路径
|
||||
*/
|
||||
|
@ -10,8 +10,6 @@
|
||||
package net.mamoe.mirai.console
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.center.CuiPluginCenter
|
||||
import net.mamoe.mirai.console.center.PluginCenter
|
||||
import net.mamoe.mirai.utils.LoginSolver
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
@ -22,11 +20,6 @@ import net.mamoe.mirai.utils.MiraiLogger
|
||||
*/
|
||||
@MiraiInternalAPI
|
||||
interface MiraiConsoleFrontEnd {
|
||||
/**
|
||||
* 提供 [PluginCenter]
|
||||
*/
|
||||
val pluginCenter: PluginCenter get() = CuiPluginCenter
|
||||
|
||||
fun loggerFor(identity: String?): MiraiLogger
|
||||
|
||||
/**
|
||||
@ -43,12 +36,6 @@ interface MiraiConsoleFrontEnd {
|
||||
bot: Bot
|
||||
)
|
||||
|
||||
fun pushVersion(
|
||||
consoleVersion: String,
|
||||
consoleBuild: String,
|
||||
coreVersion: String
|
||||
)
|
||||
|
||||
/**
|
||||
* 让 UI 层提供一个输入, 相当于 [readLine]
|
||||
*/
|
||||
|
@ -60,9 +60,6 @@ object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd {
|
||||
override fun pushBot(bot: Bot) {
|
||||
}
|
||||
|
||||
override fun pushVersion(consoleVersion: String, consoleBuild: String, coreVersion: String) {
|
||||
}
|
||||
|
||||
override suspend fun requestInput(hint: String): String {
|
||||
if (hint.isNotEmpty()) {
|
||||
ConsoleUtils.lineReader.printAbove(
|
||||
|
@ -35,15 +35,12 @@ import kotlin.coroutines.EmptyCoroutineContext
|
||||
private val delegateScope = CoroutineScope(EmptyCoroutineContext)
|
||||
|
||||
object MiraiConsolePure : IMiraiConsole {
|
||||
override val build: String = "UNKNOWN"
|
||||
override val builtInPluginLoaders: List<PluginLoader<*, *>> = LinkedList()
|
||||
override val frontEnd: MiraiConsoleFrontEnd = MiraiConsoleFrontEndPure
|
||||
override val mainLogger: MiraiLogger = DefaultLogger("Console")
|
||||
override val rootDir: File = File("./test/console").also {
|
||||
it.mkdirs()
|
||||
}
|
||||
override val version: String
|
||||
get() = "UNKNOWN"
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = delegateScope.coroutineContext
|
||||
}
|
Loading…
Reference in New Issue
Block a user