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 ae3f7ff..026215f 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,14 @@ { "name": "a8000-plus", "private": true, - "version": "0.0.0", + "version": "0.0.1", "type": "module", "scripts": { "dev": "vite", "build": "vue-tsc -b && vite build", + "build:patch": "node increment-version.js patch && vite build", + "build:minor": "node increment-version.js minor && vite build", + "build:major": "node increment-version.js major && vite build", "preview": "vite preview" }, "dependencies": { @@ -25,6 +28,7 @@ "ramda": "^0.30.1", "rxjs": "^7.8.1", "sass": "^1.79.5", + "semver": "^7.7.1", "simple-keyboard": "^3.8.17", "simple-keyboard-layouts": "^3.4.41", "vue": "^3.5.10", @@ -56,4 +60,4 @@ "vite": "^5.4.11", "vue-tsc": "^2.1.6" } -} +} \ No newline at end of file diff --git a/src/pages/Login/index.vue b/src/pages/Login/index.vue index 53589cb..27af65f 100644 --- a/src/pages/Login/index.vue +++ b/src/pages/Login/index.vue @@ -95,6 +95,8 @@ const next = () => { const back = () => { showPassword.value = false } + +const version = __APP_VERSION__ @@ -358,4 +361,9 @@ const back = () => { .flip-card-leave-to .password-box { transform: rotateY(-90deg); } +.version { + position: absolute; + bottom: 10px; + color: rgba(0,0,0,0.25); +} \ No newline at end of file diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 11f02fe..85b9599 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1 +1,2 @@ /// +declare const __APP_VERSION__: string; \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index e47006a..96ecea7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,9 +4,13 @@ import { fileURLToPath, URL } from 'url' import AutoImport from 'unplugin-auto-import/vite' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' +import packageJson from './package.json' // https://vitejs.dev/config/ export default defineConfig({ + define: { + __APP_VERSION__: JSON.stringify(packageJson.version), + }, base: './', plugins: [ vue(),