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 @@