From da1105334367c8c9f6b26efee29fdc6a4c54c82c Mon Sep 17 00:00:00 2001 From: guoapeng Date: Wed, 26 Mar 2025 17:29:38 +0800 Subject: [PATCH] =?UTF-8?q?clone:build=E5=90=8E=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- increment-version.js | 23 +++++++++++++++++++++++ package.json | 9 ++++++--- pnpm-lock.yaml | 3 +++ src/views/login/index.vue | 4 ++-- vite.config.ts | 8 ++++++-- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 increment-version.js diff --git a/increment-version.js b/increment-version.js new file mode 100644 index 0000000..3239813 --- /dev/null +++ b/increment-version.js @@ -0,0 +1,23 @@ +import fs from 'node:fs' +import path, { dirname } from 'node:path' +import { fileURLToPath } from 'node:url' +import semver from 'semver' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) + +const packagePath = path.resolve(__dirname, 'package.json') +const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')) + +// 读取命令行参数(默认使用 'patch') +const versionType = process.argv[2] || 'patch' + +// 递增版本 +const newVersion = semver.inc(packageJson.version, versionType) +if (!newVersion) { + throw new Error(`Invalid version type: ${versionType}`) +} + +packageJson.version = newVersion +fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)) +console.log(`Version updated to: ${newVersion}`) diff --git a/package.json b/package.json index 71b3af4..970db3a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "matrix-spray-web", "type": "module", - "version": "1.0.0", + "version": "1.0.1", "description": "", "author": "", "license": "ISC", @@ -13,7 +13,9 @@ "dev:prod": "vite --mode prod", "build": "vite build --mode dev", "build:test": "vite build --mode test", - "build:prod": "vite build --mode prod", + "build:prod:patch": "node increment-version.js patch && vite build --mode prod", + "build:prod:minor": "node increment-version.js minor && vite build --mode prod", + "build:prod:major": "node increment-version.js major && vite build --mode prod", "build:pre": "vite build --mode pre", "build:dev": "vite build --mode dev", "prepare": "husky", @@ -60,6 +62,7 @@ "lint-staged": "^15.4.3", "prettier": "^3.5.2", "sass": "^1.85.1", + "semver": "^7.7.1", "typescript": "^5.7.3", "unplugin-auto-import": "^19.1.1", "unplugin-vue-components": "^28.4.1", @@ -80,4 +83,4 @@ "lint-staged" ] } -} +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8830192..d5922a5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -114,6 +114,9 @@ importers: sass: specifier: ^1.85.1 version: 1.85.1 + semver: + specifier: ^7.7.1 + version: 7.7.1 typescript: specifier: ^5.7.3 version: 5.7.3 diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 5d1882b..77c386f 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -7,7 +7,7 @@ const router = useRouter() const progress = ref(0) // 进度条数值 let timer: any = null // 定时器标识 - +const version = __APP_VERSION__ // 登录成功后开始随机进度条动画 const startProgress = () => { timer = setInterval(() => { @@ -46,7 +46,7 @@ onBeforeUnmount(() => {
- v1.0.1系统初始化中 {{ progress }}% + v{{ version }}系统初始化中 {{ progress }}%
diff --git a/vite.config.ts b/vite.config.ts index de4e7cf..2c69921 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,9 +5,13 @@ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' import { defineConfig } from 'vite' import viteCompression from 'vite-plugin-compression' import eslintPlugin from 'vite-plugin-eslint' +import packageJson from './package.json' const Timestamp = new Date().getTime() export default defineConfig({ + define: { + __APP_VERSION__: JSON.stringify(packageJson.version), + }, base: './', envPrefix: 'FT_', esbuild: { @@ -80,8 +84,8 @@ export default defineConfig({ host: '0.0.0.0', proxy: { '/api': { - // target: 'http://192.168.1.199:8080', - target: 'http://192.168.1.200:8080', + target: 'http://192.168.1.199:8080', + // target: 'http://192.168.1.200:8080', // secure: false, changeOrigin: true, // 是否跨域 rewrite: path => path.replace(/^\/api/, 'api'),