feat(project): 添加版本同步机制并更新相关文件

- 新增版本同步脚本 sync-versions.js,实现自动同步 package.json 版本号到指定文件
- 更新 package.json,添加 version:sync 和 version 脚本
- 修改 App.vue 文件,添加 GitHub按钮
- 更新国际化文件,明确模板占位符格式
- 新增 version-sync.md 文档,说明版本同步机制的使用和管理
This commit is contained in:
linshen committed 2025-06-08 22:57:08 +08:00
1 parent f89fbb76eb
commit 7cfbea000c
7 files changed
+180 -7

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
# 版本同步机制
## 概述
为了确保项目中所有组件的版本号保持一致,我们建立了自动版本同步机制。该机制会自动将根目录 `package.json` 中的版本号同步到其他需要版本号的文件中。
## 自动同步的文件
目前自动同步版本号的文件包括:
- `packages/extension/public/manifest.json` - 浏览器扩展清单文件
## 使用方法
### 方法1: 使用 pnpm version 命令(推荐)
使用标准的 pnpm 版本管理命令,版本号会自动同步:
```bash
# 升级补丁版本 (1.0.7 -> 1.0.8)
pnpm version patch
# 升级次版本 (1.0.7 -> 1.1.0)
pnpm version minor
# 升级主版本 (1.0.7 -> 2.0.0)
pnpm version major
```
### 方法2: 手动同步
如果直接修改了 `package.json` 中的版本号,可以手动运行同步命令:
```bash
pnpm run version:sync
```
## 工作原理
1. **pnpm version 命令**: 更新 `package.json` 中的版本号
2. **version 钩子**: 在创建 commit 前运行同步脚本并暂存变更
- 执行 `pnpm run version:sync` 同步其他文件的版本号
- 执行 `git add -A` 将所有变更添加到暂存区
3. **同步脚本**: `scripts/sync-versions.js` 读取新的版本号并更新其他文件
4. **git commit**: pnpm 创建包含所有版本号变更的提交和标签
## 添加新的同步文件
如需添加更多文件的版本同步,编辑 `scripts/sync-versions.js` 文件中的 `versionFiles` 数组:
```javascript
const versionFiles = [
{
path: 'packages/extension/public/manifest.json',
field: 'version',
description: '浏览器扩展清单文件'
},
{
path: 'path/to/your/file.json',
field: 'version',
description: '你的文件描述'
}
];
```
## 注意事项
- 确保目标文件是有效的 JSON 格式
- 版本字段必须存在于目标文件中
- 脚本会在出现错误时退出并显示错误信息
- 所有版本号变更都会被记录到控制台
## 故障排除
如果同步失败,请检查:
1. 目标文件是否存在且格式正确
2. 版本字段是否存在于目标文件中
3. 是否有文件权限问题
4. Node.js 版本是否兼容
如有问题,可以直接运行同步脚本进行调试:
```bash
node scripts/sync-versions.js
```
+3 -1
View File
@@ -38,7 +38,9 @@
"clean:dist": "npm-run-all clean:core clean:ui clean:web clean:ext",
"clean": "npm-run-all clean:dist clean:vite",
"setup:install": "pnpm install",
"dev:fresh": "npm-run-all clean setup:install dev"
"dev:fresh": "npm-run-all clean setup:install dev",
"version:sync": "node scripts/sync-versions.js",
"version": "pnpm run version:sync && git add -A"
},
"devDependencies": {
"concurrently": "^8.2.2",
+15
View File
@@ -28,6 +28,16 @@
:text="$t('nav.dataManager')"
@click="showDataManager = true"
/>
<!-- GitHub 按钮 -->
<button
@click="openGithubRepo"
class="theme-icon-button"
title="GitHub"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 0C5.374 0 0 5.373 0 12 0 17.302 3.438 21.8 8.207 23.387c.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z"/>
</svg>
</button>
<LanguageSwitchUI />
</template>
@@ -309,4 +319,9 @@ const handleDataImported = () => {
window.location.reload()
}, 1000)
}
// GitHub 链接处理
const openGithubRepo = () => {
window.open('https://github.com/linshenkx/prompt-optimizer', '_blank')
}
</script>
+3 -3
View File
@@ -187,8 +187,8 @@ export default {
templateFormat: 'Template Format',
simpleTemplate: 'Simple Template',
advancedTemplate: 'Advanced Template',
simpleTemplateHint: 'Use double brace syntax for variable substitution, e.g. originalPrompt',
advancedTemplateHint: 'Supports multi-message structure and advanced template syntax',
simpleTemplateHint: 'No template technology used, template content directly serves as system prompt, user input as user message',
advancedTemplateHint: 'Supports multi-message structure and advanced template syntax, available variables: {{originalPrompt}}, {{lastOptimizedPrompt}}, {{iterateInput}}',
// Message Templates
messageTemplates: 'Message Templates',
@@ -196,7 +196,7 @@ export default {
removeMessage: 'Remove Message',
moveUp: 'Move Up',
moveDown: 'Move Down',
messageContentPlaceholder: 'Enter message content, supports variables like {originalPrompt}',
messageContentPlaceholder: 'Enter message content, supports variables like {{originalPrompt}}',
// Roles
roleSystem: 'System',
+3 -3
View File
@@ -187,8 +187,8 @@ export default {
templateFormat: '模板格式',
simpleTemplate: '简单模板',
advancedTemplate: '高级模板',
simpleTemplateHint: '使用双花括号语法进行变量替换,如 originalPrompt',
advancedTemplateHint: '支持多消息结构和高级模板语法',
simpleTemplateHint: '不使用模板技术,直接将模板内容作为系统提示词,用户输入作为用户消息',
advancedTemplateHint: '支持多消息结构和高级模板语法,可使用变量:{{originalPrompt}}、{{lastOptimizedPrompt}}、{{iterateInput}}',
// 消息模板
messageTemplates: '消息模板',
@@ -196,7 +196,7 @@ export default {
removeMessage: '删除消息',
moveUp: '上移',
moveDown: '下移',
messageContentPlaceholder: '输入消息内容,支持变量如 {originalPrompt}',
messageContentPlaceholder: '输入消息内容,支持变量如 {{originalPrompt}}',
// 角色
roleSystem: '系统',
+15
View File
@@ -28,6 +28,16 @@
:text="$t('nav.dataManager')"
@click="showDataManager = true"
/>
<!-- GitHub 按钮 -->
<button
@click="openGithubRepo"
class="theme-icon-button"
title="GitHub"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 0C5.374 0 0 5.373 0 12 0 17.302 3.438 21.8 8.207 23.387c.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z"/>
</svg>
</button>
<LanguageSwitchUI />
</template>
@@ -309,4 +319,9 @@ const handleDataImported = () => {
window.location.reload()
}, 1000)
}
// GitHub 链接处理
const openGithubRepo = () => {
window.open('https://github.com/linshenkx/prompt-optimizer', '_blank')
}
</script>
+55
View File
@@ -0,0 +1,55 @@
const fs = require('fs');
const path = require('path');
const rootPackage = require('../package.json');
const targetVersion = rootPackage.version;
console.log(`🔄 开始同步版本号至 ${targetVersion}`);
// 需要同步版本的文件列表
const versionFiles = [
{
path: 'packages/extension/public/manifest.json',
field: 'version',
description: '浏览器扩展清单文件'
}
// 未来可以添加更多需要同步的文件
];
let syncCount = 0;
let errorCount = 0;
versionFiles.forEach(file => {
try {
const filePath = path.resolve(__dirname, '..', file.path);
// 检查文件是否存在
if (!fs.existsSync(filePath)) {
console.log(`⚠️ 文件不存在: ${file.path}`);
errorCount++;
return;
}
// 读取并更新文件
const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
const oldVersion = content[file.field];
if (oldVersion === targetVersion) {
console.log(`✅ ${file.description}: ${file.path} 版本已是最新 (${targetVersion})`);
} else {
content[file.field] = targetVersion;
fs.writeFileSync(filePath, JSON.stringify(content, null, 2) + '\n');
console.log(`✅ ${file.description}: ${file.path} 版本已更新 ${oldVersion} → ${targetVersion}`);
syncCount++;
}
} catch (error) {
console.error(`❌ 更新 ${file.path} 时出错:`, error.message);
errorCount++;
}
});
console.log(`\n📊 同步完成: ${syncCount} 个文件已更新, ${errorCount} 个错误`);
if (errorCount > 0) {
process.exit(1);
}