Commit a980dc24 by chunhong.mu

chore(root): update commitlint scope rules

parent e63a9de2
...@@ -596,14 +596,50 @@ pnpm git:deploy-release ...@@ -596,14 +596,50 @@ pnpm git:deploy-release
#### 6.7.3 版本回滚 #### 6.7.3 版本回滚
**场景**:某个子包发布后发现问题,需要回滚到之前的版本,且不影响其他包。
**方式一:创建回滚分支(推荐,适用于需要重新开发)**
```bash ```bash
# 只回滚官网到 v1.0.0,不影响其他包 # 1. 从指定 tag 创建回滚分支
git checkout official-site-web@1.0.0 -- packages/official-site-web/ git checkout -b rollback/official-site-web-1.0.0 official-site-web@1.0.0
# 2. 恢复其他包到最新版本
git checkout dev -- common/ packages/other-web/
# 回滚后重新构建部署 # 3. 提交回滚
pnpm --filter=official-site-web build git commit -m "rollback: official-site-web to v1.0.0"
# 4. 合并回 dev 分支
pnpm git:dev-done official-site-web
``` ```
**方式二:Revert 指定提交(适用于快速修复)**
```bash
# 1. 查看官网项目的提交历史
git log --oneline -- packages/official-site-web/
# 2. Revert 需要回滚的提交(可指定多个 commit)
git revert <commit-hash>
# 3. 推送到远程
git push origin dev
```
**方式三:CI/CD 部署时指定版本(适用于紧急回滚部署)**
```bash
# 部署系统直接拉取指定 tag 的代码
git clone --branch official-site-web@1.0.0 --depth=1 <repo-url>
# 只部署 packages/official-site-web/ 目录
```
**注意事项**
- 回滚只影响目标包,其他包保持最新版本
- 回滚后建议重新执行 `pnpm changeset` 记录回滚变更
- 如果回滚涉及依赖变更,需要同步更新 `package.json`
#### 6.7.4 Tag 命名规范 #### 6.7.4 Tag 命名规范
| 包名 | Tag 格式 | 示例 | | 包名 | Tag 格式 | 示例 |
...@@ -637,13 +673,17 @@ jobs: ...@@ -637,13 +673,17 @@ jobs:
Commit 信息格式:`type(scope): description` Commit 信息格式:`type(scope): description`
**scope 为子包全名** **scope 规则**
| 场景 | scope 写法 | 示例 |
|------|-----------|------|
| 单个 common 子包改动 | `@common/包名` | `feat(@common/utils): 添加日期格式化` |
| 单个业务项目改动 | `项目名` | `feat(official-site-web): 添加首页 banner` |
| 根目录配置改动 | `root` | `chore(root): 更新 ESLint 配置` |
| 多个子包改动 | `*` | `feat(*): 同步工具函数调用` |
| 子包 | scope | **scope 白名单**
|------|-------| scope 白名单由 `scripts/generate-commitlint-config.ts` 动态生成,每次 `pnpm install` 时自动更新。新增项目后无需手动修改 commitlint 配置。
| `official-site-web` | `official-site-web` |
| `admin-web` | `admin-web` |
| 根目录配置 | `root` |
| type | 说明 | | type | 说明 |
| ---------- | --------- | | ---------- | --------- |
...@@ -657,3 +697,4 @@ Commit 信息格式:`type(scope): description` ...@@ -657,3 +697,4 @@ Commit 信息格式:`type(scope): description`
示例:`feat(official-site-web): 添加首页 banner 功能` 示例:`feat(official-site-web): 添加首页 banner 功能`
示例:`chore(root): 更新 ESLint 配置` 示例:`chore(root): 更新 ESLint 配置`
示例:`feat(*): 同步 utils 跨包调用`
export default { export default {
extends: ['@commitlint/config-conventional'], extends: ['@commitlint/config-conventional'],
rules: {
'scope-enum': [2, 'always', ["root", "*", "@common/utils", "@common/vue-kit", "official-site-web"]],
'scope-empty': [2, 'never'],
},
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"prepare": "husky", "prepare": "husky",
"postinstall": "tsx scripts/generate-commitlint-config.ts",
"git:dev-start": "tsx scripts/git-workflow.ts dev-start", "git:dev-start": "tsx scripts/git-workflow.ts dev-start",
"git:dev-done": "tsx scripts/git-workflow.ts dev-done", "git:dev-done": "tsx scripts/git-workflow.ts dev-done",
"git:deploy-staging": "tsx scripts/git-workflow.ts deploy-staging", "git:deploy-staging": "tsx scripts/git-workflow.ts deploy-staging",
......
import { readdirSync, readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
/**
* 动态生成 commitlint.config.mjs
* 原理:读取 pnpm-workspace.yaml 中定义的包路径,自动收集所有子包 name 作为 scope 白名单
* 触发时机:pnpm install 时自动执行(postinstall 钩子)
*/
const root = process.cwd()
const scopes: string[] = ['root', '*']
/**
* 读取指定目录下的所有子包 package.json name
*/
function collectPackageNames(dirPath: string) {
try {
const dirs = readdirSync(dirPath, { withFileTypes: true })
for (const dir of dirs) {
if (dir.isDirectory()) {
const pkgPath = resolve(dirPath, dir.name, 'package.json')
try {
const pkgContent = readFileSync(pkgPath, 'utf-8')
const pkg = JSON.parse(pkgContent)
if (pkg.name) {
scopes.push(pkg.name)
}
}
catch {
// 没有 package.json,跳过
}
}
}
}
catch (error: any) {
console.warn(`Warning: Could not read directory ${dirPath}:`, error.message)
}
}
// 收集 common/* 下的包
const commonDir = resolve(root, 'common')
collectPackageNames(commonDir)
// 收集 packages/* 下的包
const packagesDir = resolve(root, 'packages')
collectPackageNames(packagesDir)
// 去重
const uniqueScopes = [...new Set(scopes)]
// 生成 commitlint 配置
const config = `export default {
extends: ['@commitlint/config-conventional'],
rules: {
'scope-enum': [2, 'always', ${JSON.stringify(uniqueScopes)}],
'scope-empty': [2, 'never']
}
}
`
const outputPath = resolve(root, 'commitlint.config.mjs')
writeFileSync(outputPath, config, 'utf-8')
console.log('✅ Generated commitlint.config.mjs')
console.log(` Scopes: ${uniqueScopes.join(', ')}`)
...@@ -222,10 +222,11 @@ writeFileSync( ...@@ -222,10 +222,11 @@ writeFileSync(
) )
/** /**
* 步骤 8:安装依赖 * 步骤 8:安装依赖(自动触发 postinstall 更新 commitlint scope 白名单)
*/ */
console.log('Installing dependencies...') console.log('Installing dependencies...')
execSync('pnpm install', { stdio: 'inherit' }) execSync('pnpm install', { stdio: 'inherit' })
console.log('Commitlint scope whitelist updated automatically')
/** /**
* 步骤 9:创建并切换到项目开发分支 * 步骤 9:创建并切换到项目开发分支
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment