基本ok
This commit is contained in:
@@ -25,7 +25,7 @@ ext {
|
||||
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
|
||||
}
|
||||
|
||||
genUpdateJson = { downloadUrl, releaseDir, apkFileName, defaultConfig, variant ->
|
||||
genUpdateJson = { downloadUrl, releaseDir, apkFileName, logfile, defaultConfig, variant ->
|
||||
// 生成 update.json 文件,用于自动更新
|
||||
def releaseTime = releaseTime()
|
||||
def txtFile = new File(releaseDir, "update.json")
|
||||
@@ -33,14 +33,15 @@ ext {
|
||||
def fileMd5 = ""
|
||||
|
||||
// 读取 changelog,并提取最新版本的日志
|
||||
def changeLogFile = new File(project.getProjectDir().path, "changelog.md")
|
||||
def changeLogFile = new File(project.getProjectDir().path, logfile)
|
||||
def text = changeLogFile.text
|
||||
def marker = "### 更新记录"
|
||||
def marker = "#### 更新记录"
|
||||
def startIndex = text.indexOf(marker)
|
||||
|
||||
if (startIndex != -1) {
|
||||
// 找到标记后,找到下一个空行
|
||||
def endIndex = text.indexOf('\r\n\r\n', startIndex)
|
||||
def endIndex = text.indexOf('### [', startIndex)
|
||||
|
||||
if(endIndex == -1)
|
||||
endIndex = text.length() - 1
|
||||
|
||||
@@ -48,7 +49,10 @@ ext {
|
||||
// 截取内容并存储到变量B
|
||||
def content = text.substring(startIndex + marker.length(), endIndex)
|
||||
changeLog = content.trim()
|
||||
changeLog = changeLog.replaceAll("\r\n", "\\\\n")
|
||||
changeLog = changeLog
|
||||
.replaceAll("\r\n", "\\\\n") // 处理 Windows 换行
|
||||
.replaceAll("\n", "\\\\n") // 处理 Linux/macOS 换行
|
||||
.replaceAll("\r", "\\\\n") // 处理旧版 macOS 换行
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +78,13 @@ ext {
|
||||
" \"downloadUrl\": \"${downloadUrl}\"\n" +
|
||||
"}"
|
||||
}
|
||||
|
||||
replaceText = {File file, String key, String value ->
|
||||
def fileText = file.text
|
||||
def regex = '\\$\\{' + key + '\\}'
|
||||
fileText = (fileText =~ /${regex}/).replaceAll(value)
|
||||
file.write(fileText)
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义任务
|
||||
|
||||
Reference in New Issue
Block a user