Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
穆春红
/
frontend-hub
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a980dc24
authored
Jun 22, 2026
by
chunhong.mu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
chore(root): update commitlint scope rules
parent
e63a9de2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
11 deletions
ARCHITECTURE.md
commitlint.config.mjs
package.json
scripts/generate-commitlint-config.ts
scripts/new-project.ts
ARCHITECTURE.md
View file @
a980dc24
...
@@ -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 跨包调用`
commitlint.config.mjs
View file @
a980dc24
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'],
},
}
}
package.json
View file @
a980dc24
...
@@ -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"
,
...
...
scripts/generate-commitlint-config.ts
0 → 100644
View file @
a980dc24
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
(
', '
)}
`
)
scripts/new-project.ts
View file @
a980dc24
...
@@ -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:创建并切换到项目开发分支
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment