From 52a81e5f558b3e7b329f828adbd8255960dd750b Mon Sep 17 00:00:00 2001 From: Sun <95302870@qq.com> Date: Thu, 25 Jan 2024 13:13:08 +0800 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- add-frontend-version.js | 28 ++++++++++++++++++++++++++++ package.json | 3 ++- src/components/apps/About/index.vue | 11 ++++++++--- src/locales/en-US.json | 1 + src/locales/zh-CN.json | 1 + 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 add-frontend-version.js diff --git a/add-frontend-version.js b/add-frontend-version.js new file mode 100644 index 0000000..d55b9a5 --- /dev/null +++ b/add-frontend-version.js @@ -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) diff --git a/package.json b/package.json index 02bf24c..47f5658 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ ], "scripts": { "dev": "vite", - "build": "run-p type-check build-only", + "build": "run-p add-version type-check build-only", + "add-version": "node ./add-frontend-version.js", "preview": "vite preview", "build-only": "vite build", "type-check": "vue-tsc --noEmit", diff --git a/src/components/apps/About/index.vue b/src/components/apps/About/index.vue index 8196d3c..ff9b800 100644 --- a/src/components/apps/About/index.vue +++ b/src/components/apps/About/index.vue @@ -1,5 +1,5 @@