Skip to content

Commit

Permalink
docs: 文档
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshang918 committed Apr 3, 2021
1 parent 6f0947c commit 0b6f0f1
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 16 deletions.
8 changes: 7 additions & 1 deletion docs/Node.js/常用npm_package/清单.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: 5b48dd8280d9d24945307c72022765a0
id: 9688efbb3877b7be40b25452ccaef48f
title: 清单
---

Expand Down Expand Up @@ -190,3 +190,9 @@ title: 清单
* [resolve-from](https://www.npmjs.com/package/resolve-from)

> Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from a given path
* [import-local](https://www.npmjs.com/package/import-local)

优先使用本地的包,本地 node_modules 不存在再用全局的包

*
3 changes: 0 additions & 3 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ title: todo
> 5. Npm token or npm \_auth username:password
>
#### yarn


### 埋点和异常上报


Expand Down
4 changes: 0 additions & 4 deletions docs/工程化/依赖管理/yarn/TODO.md

This file was deleted.

20 changes: 20 additions & 0 deletions docs/工程化/依赖管理/yarn/yarn_link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
id: 9ae9305418cff5aa629668bf9bc2f1f2
title: yarn_link
---

1. 可在`~/.config/yarn/link`查看所有 link 的 package
2. yarn global bin 查看 yarn 全局 bin 安装位置
3. yarn global dir 查看 yarn 全局安装路径

## QA

1.`xxx` pakcage 中,yarn link 时 warning 提示`There's already a package called "x x x" registered. This command has had no effect. If this command was run in another folder with the same name, the other folder is still linked. Please run yarn unlink in the other folder if you want to register this folder.`

`rm ~/.config/yarn/link/xxx`

## 参考

1. [yarn link](https://classic.yarnpkg.com/en/docs/cli/link)

2. [yarn unlink](https://classic.yarnpkg.com/en/docs/cli/unlink)
102 changes: 97 additions & 5 deletions docs/工程化/协议规范/changelog规范.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: 63e3f15bc79b1f9b0c4d967587030c59
id: 11d34bb17b6b6518fe13a517e8018b61
title: changelog规范
---

Expand All @@ -9,10 +9,102 @@ title: changelog规范
## how to do

配合[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
配合语义化提交规范[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/),加上业界常用的版本和 changelog 生成包[conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)

## 自定义 changelog 生成实践

### 在 monorepo 中如何生成 changelog

一般 monorepo 我们都适用 lerna 管理,lerna 使用 conventional-comit 来生成 changelog。lerna 默认使用 angualr 预设,如果我们需要定制自己的 changelog 生成方式呐。这里我们介绍如何使用 conventionalcommits 预设来根据 commit 提交自动生成 changelog。

1. 参考[conventional-changelog-conventionalcommits](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits)文档,可以自定义 changelog 配置。配置具体规则参考:[conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec)

2.`lerna.json`中配置`changelogPreset`,如下

```json
{
"changelogPreset": {
"name": "conventionalcommits",
"types": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "perf", "section": "Performance Improvements" },
{ "type": "style", "section": "style" },
{ "type": "chore", "section": "chore" },
{ "type": "docs", "hidden": true },
{ "type": "refactor", "hidden": true },
{ "type": "test", "hidden": true }
],
"commitUrlFormat": "{{host}}/{{owner}}/{{repository}}/commit/{{hash}}"
}
}
```

- feat、fix、perf、style、chore 类型会形成 changlog,docs、refactor、test 不会生成 changelog。

- 配置了`section`的 type 会归类并生成标题。例如:feat 类型的 commit 会归类在 Features 标题下

- 指定 commit 的地址。使用模板占位符。host、owener、repository、hash 根据 package.json 读取默认值,优先使用 context 中内容。

context 即可以通过 conventional-changelog-cli 工具指定。

- conventionoal-changelog -c xxx.json

- context 必须是 json 文件

- 参考以下 context 文件配置

上述模板占位符可以在 context 文件中配置

```json
{
"owner": "drip",
"repository": "drip-form"
}
```

3. lerna version --conventional-commits 就会跟据上面的配置生成相应的 changelog

4. 将之前的 changelog 使用新的规则覆盖。

参考[lerna 如何初始化 changelog](https://github.com/lerna/lerna/tree/main/commands/version#generating-initial-changelogs)

lerna exec + conventional-changelog-cli 。同时需要制定预设为 conventionalcommits、context 文件为 xxx.json。因为 conventinal-changelog-cli 不读取 lerna.json 中的 changelog 配置。所以我们也需要制定 changelog 配置文件

参考:[conventional-changlog-conventionalcommits 如何配置](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits#indirect-usage-as-preset)

5. 执行 lerna exec 命令生成初始化 changelog

`npx lerna exec --concurrency 1 --stream -- 'conventional-changelog --preset conventionalcommits -n ../../changelogConfig.json --release-count 0 --commit-path $PWD --pkg $PWD/package.json --outfile $PWD/CHANGELOG.md --verbose --lerna-package $LERNA_PACKAGE_NAME -c ../../context.json'`

上面命令`../../changelogConfig.json`效果同`lerna.json`中`changelogPreset`字段。具体配置方法参考上一步

上面命令`../../context.json`即模板占位符中的 host、owner 等字段。

因为配置文件都在根目录,所以有`../../`,这里路径请自行控制。也可以每个 package 设置单独的生成规则

### single repo 生成 changlog 方式

conventional-changelog-cli + conventional-changelog-conventionalcommits + 上述自定义配置即可完成

## QA

1. lerna 配合 conventionalcommits 时,提示`Unable to load conventional-changelog preset conventionalcommits`

下载 conventional-changelog-conventionalcommits

## 参考

1. https://keepachangelog.com/en/1.0.0/
2. https://www.conventionalcommits.org/en/v1.0.0/
3. https://zhuanlan.zhihu.com/p/51894196
1. [keep a changelog](https://keepachangelog.com/en/1.0.0/)

2. [版本语义化](https://www.conventionalcommits.org/en/v1.0.0/)

3. [Conventional-commits-conventionalcommits](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits)

使用版本语义化的自动 changelog 生成和版本管理的实现

4. [conventional-changelog-cli](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli)

生成 changelog 的 cli 工具,可配合 angular、conventionalcommits 等预设使用。可指定预设(-p)文件、指定 context(-c)文件

5. [git commit 、CHANGELOG 和版本发布的标准自动化](https://zhuanlan.zhihu.com/p/51894196)
9 changes: 9 additions & 0 deletions docs/工程化/版本管理/git/git进阶.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: 312c951b7bed071f4a67dda0bf41816c
title: git进阶
---

## 参考

1. https://docs.github.com/en/rest/overview/libraries
2. https://github.com/Val-Zhang/blogs/issues/9
10 changes: 7 additions & 3 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ module.exports = {
items: [
{
type: 'doc',
id: 'Node.js/常用npm_package/5b48dd8280d9d24945307c72022765a0',
id: 'Node.js/常用npm_package/9688efbb3877b7be40b25452ccaef48f',
},
],
},
Expand Down Expand Up @@ -513,7 +513,7 @@ module.exports = {
items: [
{
type: 'doc',
id: '工程化/依赖管理/yarn/d85b014615bb1a174e857f844b896bd6',
id: '工程化/依赖管理/yarn/9ae9305418cff5aa629668bf9bc2f1f2',
},
],
},
Expand Down Expand Up @@ -556,7 +556,7 @@ module.exports = {
items: [
{
type: 'doc',
id: '工程化/协议规范/63e3f15bc79b1f9b0c4d967587030c59',
id: '工程化/协议规范/11d34bb17b6b6518fe13a517e8018b61',
},
{
type: 'doc',
Expand Down Expand Up @@ -695,6 +695,10 @@ module.exports = {
type: 'doc',
id: '工程化/版本管理/git/a3c10acfacecd20085ffd19a4b785459',
},
{
type: 'doc',
id: '工程化/版本管理/git/312c951b7bed071f4a67dda0bf41816c',
},
{
type: 'doc',
id: '工程化/版本管理/git/d22c453d0f1b235abd0a15ed6699608a',
Expand Down

0 comments on commit 0b6f0f1

Please sign in to comment.