Squashed commit of the following:
commit 908d87357c4e22868eff85f377bb8cd22f3785d7 Author: Sun <95302870@qq.com> Date: Thu Jan 25 13:12:14 2024 +0800 增加前端版本号 commit 8ed2b636476c7a14ae4e1761f7712949b7ce60fc Author: Sun <95302870@qq.com> Date: Thu Jan 25 12:29:49 2024 +0800 增加自动获取前端版本号的git tag
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
const fs = require('fs')
|
||||
// const { execSync } = require('child_process')
|
||||
const moment = require('moment')
|
||||
|
||||
// git 最新标签
|
||||
// const latestTag = execSync('git describe --tags --abbrev=0').toString().trim()
|
||||
const packDate = moment().format('YYYYMMDD-HH')
|
||||
|
||||
// 要追加的内容
|
||||
const contentToAppend = `\nVITE_APP_VERSION=${packDate}`
|
||||
// 读取文件原始内容
|
||||
const envFilePath = '.env'
|
||||
let envContent = fs.readFileSync(envFilePath, 'utf-8')
|
||||
|
||||
const versionRegex = /^VITE_APP_VERSION=.*$/m
|
||||
if (versionRegex.test(envContent)) {
|
||||
// 使用正则表达式查找并替换 VITE_APP_VERSION=* 这一行
|
||||
envContent = envContent.replace(versionRegex, contentToAppend)
|
||||
}
|
||||
else {
|
||||
// 追加内容
|
||||
envContent = envContent + contentToAppend
|
||||
}
|
||||
|
||||
// 将新内容写回 .env 文件
|
||||
fs.writeFileSync(envFilePath, envContent)
|
||||
|
||||
console.log('update to .env file.', contentToAppend)
|
||||
Reference in New Issue
Block a user