From 95808dab2cb3be98a62b927608a7d6b1338d061d Mon Sep 17 00:00:00 2001 From: guoapeng Date: Tue, 22 Apr 2025 20:03:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=9B=B4=E6=94=B9=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E4=B8=8E=E6=97=B6=E9=97=B41;git=E8=87=AA=E5=8A=A8=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- increment-version.js | 46 ++++++++++++++++++++++++++----------- src/pages/Index/Settings/Device.vue | 1 + 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/increment-version.js b/increment-version.js index 3239813..6c720e4 100644 --- a/increment-version.js +++ b/increment-version.js @@ -1,23 +1,41 @@ -import fs from 'node:fs' -import path, { dirname } from 'node:path' -import { fileURLToPath } from 'node:url' -import semver from 'semver' +import fs from 'node:fs'; +import path, { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import semver from 'semver'; +import { execSync } from 'child_process'; // 引入 child_process 模块用于执行 Git 命令 -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) +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')) +const packagePath = path.resolve(__dirname, 'package.json'); +const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')); // 读取命令行参数(默认使用 'patch') -const versionType = process.argv[2] || 'patch' +const versionType = process.argv[2] || 'patch'; // 递增版本 -const newVersion = semver.inc(packageJson.version, versionType) +const newVersion = semver.inc(packageJson.version, versionType); if (!newVersion) { - throw new Error(`Invalid version type: ${versionType}`) + throw new Error(`Invalid version type: ${versionType}`); } -packageJson.version = newVersion -fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)) -console.log(`Version updated to: ${newVersion}`) +packageJson.version = newVersion; +fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)); +console.log(`Version updated to: ${newVersion}`); + +// 新增:自动提交 package.json 到远程仓库 +try { + // 将 package.json 添加到暂存区 + execSync('git add package.json'); + console.log('Added package.json to staging area.'); + + // 提交更改 + execSync(`git commit -m "Update version to ${newVersion}"`); + console.log(`Committed changes with message: Update version to ${newVersion}`); + + // 推送到远程仓库 + execSync('git push'); + console.log('Pushed changes to remote repository.'); +} catch (error) { + console.error('Failed to commit and push changes:', error.message); +} \ No newline at end of file diff --git a/src/pages/Index/Settings/Device.vue b/src/pages/Index/Settings/Device.vue index b1c54b7..dec32b0 100644 --- a/src/pages/Index/Settings/Device.vue +++ b/src/pages/Index/Settings/Device.vue @@ -580,6 +580,7 @@ const resumeTimer = () => { } :deep(.date-input) { width: 250px; + margin-right: 30px; .el-input__wrapper { height: 40px; }