@modern-js/main-doc 0.0.0-next-1685988387703 → 0.0.0-next-1686037191101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,11 +9,15 @@ Modern.js 提供了 `modern gen-release-note` 命令,支持通过当前存在
9
9
  默认生成的 Release Note 格式为:
10
10
 
11
11
  ```markdown
12
- [[#1220](https://github.com/web-infra-dev/modern.js/pull/1220)] feat: support bff operators -- Ming
12
+ - fix: add missing type definitions by @zllkjc in https://github.com/web-infra-dev/modern.js/pull/3835
13
13
  ```
14
14
 
15
15
  根据 commit 信息获取 changeset 的 Pull Request ID,并生成 Github 的链接,内容为 changeset 的 changelog 信息和作者信息。
16
16
 
17
+ :::info
18
+ 获取作者信息,需要提供 Github Token 环境变量,通过 GITHUB_AUTH_TOKEN 传入。
19
+ :::
20
+
17
21
  当默认生成 Release Note 逻辑不能满足需求时,支持自定义 Release Note 格式。
18
22
 
19
23
  ## 信息
@@ -34,7 +38,7 @@ Modern.js 提供了 `modern gen-release-note` 命令,支持通过当前存在
34
38
 
35
39
  当前 changeset 对应的 commit message 信息。
36
40
 
37
- 执行 `git log --pretty=format:%h--%s--%an .changeset/${changeset.id}.md` 的结果。
41
+ 执行 `git log --pretty=format:%h--%s--%ae .changeset/${changeset.id}.md` 的结果。
38
42
 
39
43
  - commitObj
40
44
 
@@ -49,6 +53,7 @@ interface Commit {
49
53
  author?: string;
50
54
  message: string; // commit message
51
55
  summary: string; // changeset summary
56
+ summary_zh: string; // changeset zh summary
52
57
  [key: string]: string | undefined;
53
58
  }
54
59
  ```
@@ -59,15 +64,37 @@ commitObj, 补充后完整的 commit 对象。
59
64
 
60
65
  ##### 默认实现
61
66
 
62
- Modern.js 的默认实现为:根据 commit 信息拆分出 Pull Request ID 和作者,加入到 commitObj 中。
67
+ Modern.js 的默认实现为:根据 commit 信息拆分出 Pull Request ID,并根据 commit id 获取到用户信息,加入到 commitObj 中。
63
68
 
64
69
  ```ts
65
70
  function getReleaseInfo(commit: string, commitObj: Commit) {
66
- const commitRegex = /(.*)\(#(\d*)\)/;
67
-
68
- const [, message, author] = commit.split('--');
69
-
70
- commitObj.author = author;
71
+ const commitRegex = /(.*)\(#(\d*)\)/;
72
+
73
+ const [commitId, message, email] = commit.split('--');
74
+
75
+ const author = AuthorMap.get(email);
76
+ const token = authToken || process.env.GITHUB_AUTH_TOKEN;
77
+ if (author) {
78
+ commitObj.author = author;
79
+ } else if (repo && token) {
80
+ try {
81
+ const res = await axios.get(
82
+ `https://api.github.com/repos/${repo}/commits/${commitId}`,
83
+ {
84
+ method: 'GET',
85
+ headers: {
86
+ 'Content-Type': 'application/json',
87
+ Authorization: token,
88
+ },
89
+ },
90
+ );
91
+ const author = res.data.author.login;
92
+ commitObj.author = author;
93
+ AuthorMap.set(email, author);
94
+ } catch (e) {
95
+ console.warn(e);
96
+ }
97
+ }
71
98
 
72
99
  if ((message || commitObj.summary).match(commitRegex)) {
73
100
  const [, messageShort, pullRequestId] = (
@@ -95,6 +122,12 @@ function getReleaseInfo(commit: string, commitObj: Commit) {
95
122
 
96
123
  类型和上述 commitObj 类型一致。
97
124
 
125
+ - lang
126
+
127
+ 类型: string;
128
+
129
+ 获取对应语言的 Release Note 信息,支持 `en` 和 `zh`,默认为 `en`。
130
+
98
131
  ##### 返回值
99
132
 
100
133
  生成的 Release Note。
@@ -104,52 +137,29 @@ function getReleaseInfo(commit: string, commitObj: Commit) {
104
137
  Modern.js 的默认实现为:
105
138
 
106
139
  ```ts
107
- function formatSummary(summary: string, pullRequestId?: string) {
108
- const [firstLine, ...futureLines] = summary
109
- .split('\n')
110
- .map(l => l.trimRight());
111
-
112
- let returnVal = firstLine;
113
-
114
- if (futureLines.length > 0) {
115
- if (pullRequestId) {
116
- returnVal = `\n\n ${returnVal}`;
117
- } else {
118
- returnVal = `\n ${returnVal}`;
119
- }
120
- returnVal += `\n\n ${futureLines
121
- .filter(l => Boolean(l))
122
- .map(l => l)
123
- .join('\n\n')}`;
124
- }
125
- return returnVal;
126
- }
127
-
128
- export async function getReleaseNoteLine(
140
+ export function getReleaseNoteLine(
129
141
  commit: Commit,
130
- customReleaseNoteFunction?: CustomReleaseNoteFunction,
142
+ lang: 'en' | 'zh' = 'en',
131
143
  ) {
132
- if (customReleaseNoteFunction?.getReleaseNoteLine) {
133
- return customReleaseNoteFunction.getReleaseNoteLine(commit);
134
- }
135
-
136
- const { repository, pullRequestId, summary } = commit;
137
- if (pullRequestId && repository) {
138
- return `- [#${pullRequestId}](https://github.com/${repository}/pull/${pullRequestId}) ${formatSummary(
139
- summary,
140
- pullRequestId,
141
- )}\n`;
142
- }
143
- if (pullRequestId) {
144
- return `#${pullRequestId} ${formatSummary(summary, pullRequestId)}\n`;
144
+ const { repository, pullRequestId, summary, summary_zh, author } = commit;
145
+ const pullRequest =
146
+ pullRequestId && repository
147
+ ? `https://github.com/${repository}/pull/${pullRequestId}`
148
+ : '';
149
+ if (lang === 'en') {
150
+ return `- ${summary}${author ? ` by @${author}` : ''}${
151
+ pullRequest ? ` in ${pullRequest}` : ''
152
+ }\n`;
145
153
  }
146
- return `${formatSummary(summary, pullRequestId)}\n`;
154
+ return `- ${summary_zh}${author ? ` 由 @${author} 实现` : ''}${
155
+ pullRequest ? `, 详情可查看 ${pullRequest}` : ''
156
+ }\n`;
147
157
  }
148
158
  ```
149
159
 
150
160
  ## 使用自定义模块
151
161
 
152
- `gen-release-note` 命令支持 `--custom` 参数,该参数可传入自定义 release note 模块的模块名称或者路径。
162
+ `gen-release-note` 命令支持 `--custom` 参数,该参数可传入自定义 Release Note 模块的模块名称或者路径。
153
163
 
154
164
  ### 配置相对路径
155
165
 
@@ -173,7 +183,7 @@ module.exports = {
173
183
  执行下面命令:
174
184
 
175
185
  ```bash
176
- pnpm run gen-release-note -- --custom ./scripts/my-release-note-config.js
186
+ pnpm run gen-release-note --custom ./scripts/my-release-note-config.js
177
187
  ```
178
188
 
179
189
  也可以把命令参数直接定义到 package.json 中:
@@ -216,7 +226,7 @@ export function getReleaseNoteLine() {}
216
226
  5. 执行 gen-release-note 命令添加 custom 参数
217
227
 
218
228
  ```bash
219
- pnpm run gen-release-note -- --custom custom-release-note
229
+ pnpm run gen-release-note --custom custom-release-note
220
230
  ```
221
231
 
222
232
  ### 使用 Monorepo 工程方案
@@ -253,7 +263,7 @@ export function getReleaseNoteLine() {}
253
263
  4. 执行 `gen-release-note` 命令添加 `--custom` 参数
254
264
 
255
265
  ```bash
256
- pnpm run gen-release-note -- --custom custom-release-note
266
+ pnpm run gen-release-note --custom custom-release-note
257
267
  ```
258
268
 
259
269
  该模块发布到 NPM 后,依然可以和模块类型一样供其他仓库使用。
@@ -4,7 +4,7 @@ sidebar_position: 4
4
4
 
5
5
  # 发布预发布版本
6
6
 
7
- 在发布正式版本之前,我们也需要发布预发布版本供内部测试和用户使用,Changesets 也支持发布预发布版本。
7
+ 在发布正式版本之前,我们也需要发布预发布版本供内部测试和用户使用,changesets 也支持发布预发布版本。
8
8
 
9
9
  ## 步骤
10
10
 
@@ -16,7 +16,7 @@ sidebar_position: 4
16
16
  #### 执行以下命令升级预发布版本版本号:
17
17
 
18
18
  ```bash
19
- pnpm run bump -- --canary --preid <preid>
19
+ pnpm run bump --canary --preid <preid>
20
20
  ```
21
21
 
22
22
  `preid` 为预发布版本标记,例如 `alpha`、`beta` 等,默认值为 `next`。
@@ -38,7 +38,7 @@ pnpm run bump -- --canary --preid <preid>
38
38
  #### 执行以下命令发布预发布版本:
39
39
 
40
40
  ```bash
41
- pnpm run release -- --tag <tag>
41
+ pnpm run release --tag <tag>
42
42
  ```
43
43
 
44
44
  发布预发布版本一定要使用 `--tag` 参数,参数值最好和 `preid` 值相同,方便用户使用。
@@ -47,4 +47,4 @@ pnpm run release -- --tag <tag>
47
47
 
48
48
  ### 退出预发布模式
49
49
 
50
- 在进入预发布模式后,Changesets 会自动在 `.changeset` 目录创建 `pre.json` 文件用于记录当时进入预发布模式的一些状态信息,当出现状态信息和当前仓库状态不一致时,可直接删除该文件退出预发布模式。
50
+ 在进入预发布模式后,changesets 会自动在 `.changeset` 目录创建 `pre.json` 文件用于记录当时进入预发布模式的一些状态信息,当出现状态信息和当前仓库状态不一致时,可直接删除该文件退出预发布模式。
@@ -108,7 +108,7 @@ git push --follow-tags
108
108
  - `--snapshot` 生成基于时间戳的版本号。
109
109
 
110
110
  ```bash
111
- pnpm run bump -- --snapshot canary
111
+ pnpm run bump --snapshot canary
112
112
  ```
113
113
 
114
114
  执行完成后,对应的升级版本号将会变成 `0.0.0-canary-20220622092823` 的形式,其中 canary 为 snapshot 配置的标记,如果不配置,将直接生成 `0.0.0-20220622092823` 的形式。
@@ -120,7 +120,7 @@ pnpm run bump -- --snapshot canary
120
120
  例如本次发布你需要忽略 `module-2` 包:
121
121
 
122
122
  ```bash
123
- pnpm run bump -- --ignore module-2
123
+ pnpm run bump --ignore module-2
124
124
  ```
125
125
 
126
126
  命令执行完成后,将会忽略 `module-2` 包的更新。注意如果存在包依赖 `module-2`,需要将对应包也加入到 `ignore` 参数中,否则 `bump` 命令将执行失败。
@@ -128,7 +128,7 @@ pnpm run bump -- --ignore module-2
128
128
  加入多个包的使用姿势为:
129
129
 
130
130
  ```bash
131
- pnpm run bump -- --ignore module-2 --ignore module-3
131
+ pnpm run bump --ignore module-2 --ignore module-3
132
132
  ```
133
133
 
134
134
  ### release 命令参数
@@ -136,13 +136,13 @@ pnpm run bump -- --ignore module-2 --ignore module-3
136
136
  - `--otp` 使用 `npm token` 执行 release 命令发布对应包
137
137
 
138
138
  ```bash
139
- pnpm run relese -- --otp <token>
139
+ pnpm run relese --otp <token>
140
140
  ```
141
141
 
142
142
  - `--tag` 本地发布使用特定的 tag,默认使用 `latest`
143
143
 
144
144
  ```bash
145
- pnpm run release -- --tag <tag>
145
+ pnpm run release --tag <tag>
146
146
  ```
147
147
 
148
148
  - `--ignore-scripts` 发布时忽略 npm scripts。
@@ -150,7 +150,7 @@ pnpm run release -- --tag <tag>
150
150
  执行 `publish` 命令时,npm 会自动触发很多命令,比如 `prepare`、`prepublish`,使用该参数可以忽略这些命令执行。该参数仅支持在使用 pnpm 的 Monorepo 中使用。
151
151
 
152
152
  ```bash
153
- pnpm run release -- --ignore-scripts
153
+ pnpm run release --ignore-scripts
154
154
  ```
155
155
 
156
156
  - `--no-git-checks` 发布时忽略检查当前分支。
@@ -158,7 +158,7 @@ pnpm run release -- --ignore-scripts
158
158
  执行发布命令时,默认会自动检查当前分支是否为发布分支,是否存在未提交变更等等,使用该参数可以忽略 git 相关检查。
159
159
 
160
160
  ```bash
161
- pnpm run release -- --no-git-checks
161
+ pnpm run release --no-git-checks
162
162
  ```
163
163
 
164
164
  ## 升级版本策略
package/package.json CHANGED
@@ -15,13 +15,13 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-next-1685988387703",
18
+ "version": "0.0.0-next-1686037191101",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public"
22
22
  },
23
23
  "peerDependencies": {
24
- "@modern-js/builder-doc": "0.0.0-next-1685988387703"
24
+ "@modern-js/builder-doc": "0.0.0-next-1686037191101"
25
25
  },
26
26
  "devDependencies": {
27
27
  "classnames": "^2",
@@ -33,9 +33,9 @@
33
33
  "fs-extra": "^10",
34
34
  "@types/node": "^16",
35
35
  "@types/fs-extra": "^9",
36
- "@modern-js/builder-doc": "0.0.0-next-1685988387703",
37
- "@modern-js/doc-tools": "0.0.0-next-1685988387703",
38
- "@modern-js/doc-plugin-auto-sidebar": "0.0.0-next-1685988387703"
36
+ "@modern-js/builder-doc": "0.0.0-next-1686037191101",
37
+ "@modern-js/doc-plugin-auto-sidebar": "0.0.0-next-1686037191101",
38
+ "@modern-js/doc-tools": "0.0.0-next-1686037191101"
39
39
  },
40
40
  "scripts": {
41
41
  "dev": "modern dev",