mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 00:20:19 +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 upload.Bintray
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
@ -74,6 +76,33 @@ tasks {
|
|||||||
"test"(Test::class) {
|
"test"(Test::class) {
|
||||||
useJUnitPlatform()
|
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
|
// region PUBLISHING
|
||||||
|
@ -13,6 +13,8 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.io.charsets.Charset
|
import kotlinx.io.charsets.Charset
|
||||||
import net.mamoe.mirai.Bot
|
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.PluginLoader
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JarPluginLoader
|
import net.mamoe.mirai.console.plugin.jvm.JarPluginLoader
|
||||||
import net.mamoe.mirai.utils.DefaultLogger
|
import net.mamoe.mirai.utils.DefaultLogger
|
||||||
@ -21,6 +23,7 @@ import net.mamoe.mirai.utils.MiraiLogger
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
|
import java.util.*
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
internal object MiraiConsoleInitializer {
|
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 控制台实例.
|
* mirai 控制台实例.
|
||||||
*/
|
*/
|
||||||
object MiraiConsole : CoroutineScope, IMiraiConsole {
|
object MiraiConsole : CoroutineScope, IMiraiConsole {
|
||||||
|
val pluginCenter: PluginCenter get() = CuiPluginCenter
|
||||||
|
|
||||||
private val instance: IMiraiConsole
|
private val instance: IMiraiConsole
|
||||||
get() = MiraiConsoleInitializer.instance
|
get() = MiraiConsoleInitializer.instance
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `mirai-console` build 号
|
* `mirai-console` build 号
|
||||||
|
*
|
||||||
|
* UTC+8 时间
|
||||||
*/
|
*/
|
||||||
@MiraiExperimentalAPI
|
@JvmStatic
|
||||||
override val build: String
|
val buildDate: Date
|
||||||
get() = instance.build
|
get() = MiraiConsoleBuildConstants.buildDate
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `mirai-console` 版本
|
* `mirai-console` 版本
|
||||||
*/
|
*/
|
||||||
@MiraiExperimentalAPI
|
const val version: String = MiraiConsoleBuildConstants.version
|
||||||
override val version: String
|
|
||||||
get() = instance.version
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Console 运行路径
|
* Console 运行路径
|
||||||
@ -89,9 +100,6 @@ object MiraiConsole : CoroutineScope, IMiraiConsole {
|
|||||||
|
|
||||||
// 前端使用
|
// 前端使用
|
||||||
internal interface IMiraiConsole : CoroutineScope {
|
internal interface IMiraiConsole : CoroutineScope {
|
||||||
val build: String
|
|
||||||
val version: String
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Console 运行路径
|
* Console 运行路径
|
||||||
*/
|
*/
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
package net.mamoe.mirai.console
|
package net.mamoe.mirai.console
|
||||||
|
|
||||||
import net.mamoe.mirai.Bot
|
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.LoginSolver
|
||||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
import net.mamoe.mirai.utils.MiraiLogger
|
||||||
@ -22,11 +20,6 @@ import net.mamoe.mirai.utils.MiraiLogger
|
|||||||
*/
|
*/
|
||||||
@MiraiInternalAPI
|
@MiraiInternalAPI
|
||||||
interface MiraiConsoleFrontEnd {
|
interface MiraiConsoleFrontEnd {
|
||||||
/**
|
|
||||||
* 提供 [PluginCenter]
|
|
||||||
*/
|
|
||||||
val pluginCenter: PluginCenter get() = CuiPluginCenter
|
|
||||||
|
|
||||||
fun loggerFor(identity: String?): MiraiLogger
|
fun loggerFor(identity: String?): MiraiLogger
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,12 +36,6 @@ interface MiraiConsoleFrontEnd {
|
|||||||
bot: Bot
|
bot: Bot
|
||||||
)
|
)
|
||||||
|
|
||||||
fun pushVersion(
|
|
||||||
consoleVersion: String,
|
|
||||||
consoleBuild: String,
|
|
||||||
coreVersion: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 让 UI 层提供一个输入, 相当于 [readLine]
|
* 让 UI 层提供一个输入, 相当于 [readLine]
|
||||||
*/
|
*/
|
||||||
|
@ -60,9 +60,6 @@ object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd {
|
|||||||
override fun pushBot(bot: Bot) {
|
override fun pushBot(bot: Bot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pushVersion(consoleVersion: String, consoleBuild: String, coreVersion: String) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun requestInput(hint: String): String {
|
override suspend fun requestInput(hint: String): String {
|
||||||
if (hint.isNotEmpty()) {
|
if (hint.isNotEmpty()) {
|
||||||
ConsoleUtils.lineReader.printAbove(
|
ConsoleUtils.lineReader.printAbove(
|
||||||
|
@ -35,15 +35,12 @@ import kotlin.coroutines.EmptyCoroutineContext
|
|||||||
private val delegateScope = CoroutineScope(EmptyCoroutineContext)
|
private val delegateScope = CoroutineScope(EmptyCoroutineContext)
|
||||||
|
|
||||||
object MiraiConsolePure : IMiraiConsole {
|
object MiraiConsolePure : IMiraiConsole {
|
||||||
override val build: String = "UNKNOWN"
|
|
||||||
override val builtInPluginLoaders: List<PluginLoader<*, *>> = LinkedList()
|
override val builtInPluginLoaders: List<PluginLoader<*, *>> = LinkedList()
|
||||||
override val frontEnd: MiraiConsoleFrontEnd = MiraiConsoleFrontEndPure
|
override val frontEnd: MiraiConsoleFrontEnd = MiraiConsoleFrontEndPure
|
||||||
override val mainLogger: MiraiLogger = DefaultLogger("Console")
|
override val mainLogger: MiraiLogger = DefaultLogger("Console")
|
||||||
override val rootDir: File = File("./test/console").also {
|
override val rootDir: File = File("./test/console").also {
|
||||||
it.mkdirs()
|
it.mkdirs()
|
||||||
}
|
}
|
||||||
override val version: String
|
|
||||||
get() = "UNKNOWN"
|
|
||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
get() = delegateScope.coroutineContext
|
get() = delegateScope.coroutineContext
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user