Browse Source

fix:版本号自动递增

master
guoapeng 3 months ago
parent
commit
f5214ed783
  1. 23
      increment-version.js
  2. 8
      package.json
  3. 8
      src/pages/Login/index.vue
  4. 1
      src/vite-env.d.ts
  5. 4
      vite.config.ts

23
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}`)

8
package.json

@ -1,11 +1,14 @@
{ {
"name": "a8000-plus", "name": "a8000-plus",
"private": true, "private": true,
"version": "0.0.0",
"version": "0.0.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vue-tsc -b && vite build", "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" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
@ -25,6 +28,7 @@
"ramda": "^0.30.1", "ramda": "^0.30.1",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"sass": "^1.79.5", "sass": "^1.79.5",
"semver": "^7.7.1",
"simple-keyboard": "^3.8.17", "simple-keyboard": "^3.8.17",
"simple-keyboard-layouts": "^3.4.41", "simple-keyboard-layouts": "^3.4.41",
"vue": "^3.5.10", "vue": "^3.5.10",
@ -56,4 +60,4 @@
"vite": "^5.4.11", "vite": "^5.4.11",
"vue-tsc": "^2.1.6" "vue-tsc": "^2.1.6"
} }
}
}

8
src/pages/Login/index.vue

@ -95,6 +95,8 @@ const next = () => {
const back = () => { const back = () => {
showPassword.value = false showPassword.value = false
} }
const version = __APP_VERSION__
</script> </script>
<template> <template>
<div class="login-box"> <div class="login-box">
@ -139,6 +141,7 @@ const back = () => {
</div> </div>
</div> </div>
</transition> </transition>
<div class="version">版本号v {{version}}</div>
</div> </div>
</template> </template>
@ -358,4 +361,9 @@ const back = () => {
.flip-card-leave-to .password-box { .flip-card-leave-to .password-box {
transform: rotateY(-90deg); transform: rotateY(-90deg);
} }
.version {
position: absolute;
bottom: 10px;
color: rgba(0,0,0,0.25);
}
</style> </style>

1
src/vite-env.d.ts

@ -1 +1,2 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
declare const __APP_VERSION__: string;

4
vite.config.ts

@ -4,9 +4,13 @@ import { fileURLToPath, URL } from 'url'
import AutoImport from 'unplugin-auto-import/vite' import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite' import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import packageJson from './package.json'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(packageJson.version),
},
base: './', base: './',
plugins: [ plugins: [
vue(), vue(),

Loading…
Cancel
Save