@modern-js/plugin-changeset 2.21.1 → 2.21.2-alpha.1

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.
@@ -10,6 +10,12 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
+ CommitType: () => CommitType,
14
+ ChangesTitle: () => ChangesTitle,
15
+ ChangesZhTitle: () => ChangesZhTitle,
16
+ CommitTypeTitle: () => CommitTypeTitle,
17
+ CommitTypeZhTitle: () => CommitTypeZhTitle,
18
+ getCommitType: () => getCommitType,
13
19
  getReleaseInfo: () => getReleaseInfo,
14
20
  getReleaseNoteLine: () => getReleaseNoteLine,
15
21
  genReleaseNote: () => genReleaseNote
@@ -19,6 +25,45 @@ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
19
25
  const _resolvefrom = /* @__PURE__ */ _interop_require_default._(require("resolve-from"));
20
26
  const _utils = require("@modern-js/utils");
21
27
  const _read = /* @__PURE__ */ _interop_require_default._(require("@changesets/read"));
28
+ var CommitType;
29
+ (function(CommitType2) {
30
+ CommitType2["Performance"] = "performance";
31
+ CommitType2["Features"] = "features";
32
+ CommitType2["BugFix"] = "bugFix";
33
+ CommitType2["Doc"] = "doc";
34
+ CommitType2["Other"] = "other";
35
+ })(CommitType || (CommitType = {}));
36
+ const ChangesTitle = `What's Changed`;
37
+ const ChangesZhTitle = "更新内容";
38
+ const CommitTypeTitle = {
39
+ performance: "Performance Improvements ⚡",
40
+ features: "New Features 🎉",
41
+ bugFix: "Bug Fixes 🐞",
42
+ doc: "Docs update 📄",
43
+ other: "Other Changes"
44
+ };
45
+ const CommitTypeZhTitle = {
46
+ performance: "性能优化 ⚡",
47
+ features: "新特性 🎉",
48
+ bugFix: "Bug 修复 🐞",
49
+ doc: "文档更新 📄",
50
+ other: "其他变更"
51
+ };
52
+ function getCommitType(message) {
53
+ if (message.startsWith("perf")) {
54
+ return CommitType.Performance;
55
+ }
56
+ if (message.startsWith("feat")) {
57
+ return CommitType.Features;
58
+ }
59
+ if (message.startsWith("fix") || message.startsWith("hotfix")) {
60
+ return CommitType.BugFix;
61
+ }
62
+ if (message.startsWith("docs")) {
63
+ return CommitType.Doc;
64
+ }
65
+ return CommitType.Other;
66
+ }
22
67
  function getReleaseInfo(commit, commitObj) {
23
68
  const commitRegex = /(.*)\(#(\d*)\)/;
24
69
  const [, message, author] = commit.split("--");
@@ -30,38 +75,17 @@ function getReleaseInfo(commit, commitObj) {
30
75
  }
31
76
  return commitObj;
32
77
  }
33
- function formatSummary(summary, pullRequestId) {
34
- const [firstLine, ...futureLines] = summary.split("\n").map((l) => l.trimRight());
35
- let returnVal = firstLine;
36
- if (futureLines.length > 0) {
37
- if (pullRequestId) {
38
- returnVal = `
39
-
40
- ${returnVal}`;
41
- } else {
42
- returnVal = `
43
- ${returnVal}`;
44
- }
45
- returnVal += `
46
-
47
- ${futureLines.filter((l) => Boolean(l)).map((l) => l).join("\n\n")}`;
48
- }
49
- return returnVal;
50
- }
51
- function getReleaseNoteLine(commit, customReleaseNoteFunction) {
78
+ function getReleaseNoteLine(commit, customReleaseNoteFunction, lang = "en") {
52
79
  if (customReleaseNoteFunction === null || customReleaseNoteFunction === void 0 ? void 0 : customReleaseNoteFunction.getReleaseNoteLine) {
53
80
  return customReleaseNoteFunction.getReleaseNoteLine(commit);
54
81
  }
55
- const { repository, pullRequestId, summary } = commit;
56
- if (pullRequestId && repository) {
57
- return `- [#${pullRequestId}](https://github.com/${repository}/pull/${pullRequestId}) ${formatSummary(summary, pullRequestId)}
58
- `;
59
- }
60
- if (pullRequestId) {
61
- return `#${pullRequestId} ${formatSummary(summary, pullRequestId)}
82
+ const { repository, pullRequestId, summary, summary_zh, author } = commit;
83
+ const pullRequest = pullRequestId ? `https://github.com/${repository}/pull/${pullRequestId}` : "";
84
+ if (lang === "en") {
85
+ return `- ${summary} by @${author}${pullRequest ? ` in ${pullRequest}` : ""}
62
86
  `;
63
87
  }
64
- return `${formatSummary(summary, pullRequestId)}
88
+ return `- ${summary_zh} 由 @${author} 实现${pullRequest ? `, 详情可查看 ${pullRequest}` : ""}
65
89
  `;
66
90
  }
67
91
  async function genReleaseNote(options) {
@@ -91,8 +115,28 @@ async function genReleaseNote(options) {
91
115
  console.warn("No unreleased changesets found.");
92
116
  return "";
93
117
  }
94
- const features = [];
95
- const bugFix = [];
118
+ const releaseNote = {
119
+ [CommitType.Performance]: {
120
+ en: [],
121
+ zh: []
122
+ },
123
+ [CommitType.Features]: {
124
+ en: [],
125
+ zh: []
126
+ },
127
+ [CommitType.BugFix]: {
128
+ en: [],
129
+ zh: []
130
+ },
131
+ [CommitType.Doc]: {
132
+ en: [],
133
+ zh: []
134
+ },
135
+ [CommitType.Other]: {
136
+ en: [],
137
+ zh: []
138
+ }
139
+ };
96
140
  for (const changeset of changesets) {
97
141
  const { stdout } = await (0, _utils.execa)("git", [
98
142
  "log",
@@ -100,42 +144,58 @@ async function genReleaseNote(options) {
100
144
  `.changeset/${changeset.id}.md`
101
145
  ]);
102
146
  const [id, message] = stdout.split("--");
147
+ const [firstLine, ...futureLines] = changeset.summary.split("\n").map((l) => l.trimRight());
103
148
  let commitObj = {
104
149
  id,
105
- type: (message || changeset.summary).startsWith("fix") ? "fix" : "feature",
150
+ type: getCommitType(changeset.summary || message),
106
151
  repository,
107
152
  message: (message || changeset.summary).trim(),
108
- summary: changeset.summary
153
+ summary: firstLine,
154
+ summary_zh: futureLines.filter((l) => Boolean(l)).join("\n")
109
155
  };
110
156
  if (customReleaseNoteFunction === null || customReleaseNoteFunction === void 0 ? void 0 : customReleaseNoteFunction.getReleaseInfo) {
111
157
  commitObj = await customReleaseNoteFunction.getReleaseInfo(stdout, commitObj);
112
158
  } else {
113
159
  commitObj = getReleaseInfo(stdout, commitObj);
114
160
  }
115
- if (commitObj.type === "fix") {
116
- bugFix.push(commitObj);
117
- } else {
118
- features.push(commitObj);
161
+ releaseNote[commitObj.type].en.push(commitObj);
162
+ if (commitObj.summary_zh) {
163
+ releaseNote[commitObj.type].zh.push(commitObj);
119
164
  }
120
165
  }
121
- if (!features.length && !bugFix.length) {
122
- console.warn("no release note found, you can run `pnpm run add` to add changeset");
123
- }
124
- let result = "";
125
- if (features.length) {
126
- result += "## Features:\n";
127
- for (const commit of features) {
128
- const releaseNote = await getReleaseNoteLine(commit, customReleaseNoteFunction);
129
- result += releaseNote;
166
+ const result = {
167
+ en: `## ${ChangesTitle}
168
+
169
+ `,
170
+ zh: `## ${ChangesZhTitle}
171
+
172
+ `
173
+ };
174
+ let flag = 0;
175
+ for (const [type, { en, zh }] of Object.entries(releaseNote)) {
176
+ if (en.length > 0) {
177
+ result.en += `### ${CommitTypeTitle[type]}
178
+
179
+ `;
180
+ for (const commit of en) {
181
+ const releaseNote2 = await getReleaseNoteLine(commit, customReleaseNoteFunction, "en");
182
+ result.en += releaseNote2;
183
+ }
130
184
  }
131
- }
132
- if (bugFix.length) {
133
- result += "## Bug Fix:\n";
134
- for (const commit of bugFix) {
135
- const releaseNote = await getReleaseNoteLine(commit, customReleaseNoteFunction);
136
- result += releaseNote;
185
+ if (zh.length > 0) {
186
+ flag = 1;
187
+ result.zh += `### ${CommitTypeZhTitle[type]}
188
+
189
+ `;
190
+ for (const commit of zh) {
191
+ const releaseNote2 = await getReleaseNoteLine(commit, customReleaseNoteFunction, "zh");
192
+ result.zh += releaseNote2;
193
+ }
137
194
  }
138
195
  }
139
- console.info(result);
140
- return result;
196
+ const resultStr = flag ? `${result.en}
197
+
198
+ ${result.zh}` : result.en;
199
+ console.info(resultStr);
200
+ return resultStr;
141
201
  }
@@ -2,6 +2,45 @@ import path from "path";
2
2
  import resolveFrom from "resolve-from";
3
3
  import { fs, execa } from "@modern-js/utils";
4
4
  import readChangesets from "@changesets/read";
5
+ export var CommitType;
6
+ (function(CommitType2) {
7
+ CommitType2["Performance"] = "performance";
8
+ CommitType2["Features"] = "features";
9
+ CommitType2["BugFix"] = "bugFix";
10
+ CommitType2["Doc"] = "doc";
11
+ CommitType2["Other"] = "other";
12
+ })(CommitType || (CommitType = {}));
13
+ export const ChangesTitle = `What's Changed`;
14
+ export const ChangesZhTitle = "更新内容";
15
+ export const CommitTypeTitle = {
16
+ performance: "Performance Improvements ⚡",
17
+ features: "New Features 🎉",
18
+ bugFix: "Bug Fixes 🐞",
19
+ doc: "Docs update 📄",
20
+ other: "Other Changes"
21
+ };
22
+ export const CommitTypeZhTitle = {
23
+ performance: "性能优化 ⚡",
24
+ features: "新特性 🎉",
25
+ bugFix: "Bug 修复 🐞",
26
+ doc: "文档更新 📄",
27
+ other: "其他变更"
28
+ };
29
+ export function getCommitType(message) {
30
+ if (message.startsWith("perf")) {
31
+ return CommitType.Performance;
32
+ }
33
+ if (message.startsWith("feat")) {
34
+ return CommitType.Features;
35
+ }
36
+ if (message.startsWith("fix") || message.startsWith("hotfix")) {
37
+ return CommitType.BugFix;
38
+ }
39
+ if (message.startsWith("docs")) {
40
+ return CommitType.Doc;
41
+ }
42
+ return CommitType.Other;
43
+ }
5
44
  export function getReleaseInfo(commit, commitObj) {
6
45
  const commitRegex = /(.*)\(#(\d*)\)/;
7
46
  const [, message, author] = commit.split("--");
@@ -13,38 +52,17 @@ export function getReleaseInfo(commit, commitObj) {
13
52
  }
14
53
  return commitObj;
15
54
  }
16
- function formatSummary(summary, pullRequestId) {
17
- const [firstLine, ...futureLines] = summary.split("\n").map((l) => l.trimRight());
18
- let returnVal = firstLine;
19
- if (futureLines.length > 0) {
20
- if (pullRequestId) {
21
- returnVal = `
22
-
23
- ${returnVal}`;
24
- } else {
25
- returnVal = `
26
- ${returnVal}`;
27
- }
28
- returnVal += `
29
-
30
- ${futureLines.filter((l) => Boolean(l)).map((l) => l).join("\n\n")}`;
31
- }
32
- return returnVal;
33
- }
34
- export function getReleaseNoteLine(commit, customReleaseNoteFunction) {
55
+ export function getReleaseNoteLine(commit, customReleaseNoteFunction, lang = "en") {
35
56
  if (customReleaseNoteFunction === null || customReleaseNoteFunction === void 0 ? void 0 : customReleaseNoteFunction.getReleaseNoteLine) {
36
57
  return customReleaseNoteFunction.getReleaseNoteLine(commit);
37
58
  }
38
- const { repository, pullRequestId, summary } = commit;
39
- if (pullRequestId && repository) {
40
- return `- [#${pullRequestId}](https://github.com/${repository}/pull/${pullRequestId}) ${formatSummary(summary, pullRequestId)}
41
- `;
42
- }
43
- if (pullRequestId) {
44
- return `#${pullRequestId} ${formatSummary(summary, pullRequestId)}
59
+ const { repository, pullRequestId, summary, summary_zh, author } = commit;
60
+ const pullRequest = pullRequestId ? `https://github.com/${repository}/pull/${pullRequestId}` : "";
61
+ if (lang === "en") {
62
+ return `- ${summary} by @${author}${pullRequest ? ` in ${pullRequest}` : ""}
45
63
  `;
46
64
  }
47
- return `${formatSummary(summary, pullRequestId)}
65
+ return `- ${summary_zh} 由 @${author} 实现${pullRequest ? `, 详情可查看 ${pullRequest}` : ""}
48
66
  `;
49
67
  }
50
68
  export async function genReleaseNote(options) {
@@ -74,8 +92,28 @@ export async function genReleaseNote(options) {
74
92
  console.warn("No unreleased changesets found.");
75
93
  return "";
76
94
  }
77
- const features = [];
78
- const bugFix = [];
95
+ const releaseNote = {
96
+ [CommitType.Performance]: {
97
+ en: [],
98
+ zh: []
99
+ },
100
+ [CommitType.Features]: {
101
+ en: [],
102
+ zh: []
103
+ },
104
+ [CommitType.BugFix]: {
105
+ en: [],
106
+ zh: []
107
+ },
108
+ [CommitType.Doc]: {
109
+ en: [],
110
+ zh: []
111
+ },
112
+ [CommitType.Other]: {
113
+ en: [],
114
+ zh: []
115
+ }
116
+ };
79
117
  for (const changeset of changesets) {
80
118
  const { stdout } = await execa("git", [
81
119
  "log",
@@ -83,42 +121,58 @@ export async function genReleaseNote(options) {
83
121
  `.changeset/${changeset.id}.md`
84
122
  ]);
85
123
  const [id, message] = stdout.split("--");
124
+ const [firstLine, ...futureLines] = changeset.summary.split("\n").map((l) => l.trimRight());
86
125
  let commitObj = {
87
126
  id,
88
- type: (message || changeset.summary).startsWith("fix") ? "fix" : "feature",
127
+ type: getCommitType(changeset.summary || message),
89
128
  repository,
90
129
  message: (message || changeset.summary).trim(),
91
- summary: changeset.summary
130
+ summary: firstLine,
131
+ summary_zh: futureLines.filter((l) => Boolean(l)).join("\n")
92
132
  };
93
133
  if (customReleaseNoteFunction === null || customReleaseNoteFunction === void 0 ? void 0 : customReleaseNoteFunction.getReleaseInfo) {
94
134
  commitObj = await customReleaseNoteFunction.getReleaseInfo(stdout, commitObj);
95
135
  } else {
96
136
  commitObj = getReleaseInfo(stdout, commitObj);
97
137
  }
98
- if (commitObj.type === "fix") {
99
- bugFix.push(commitObj);
100
- } else {
101
- features.push(commitObj);
138
+ releaseNote[commitObj.type].en.push(commitObj);
139
+ if (commitObj.summary_zh) {
140
+ releaseNote[commitObj.type].zh.push(commitObj);
102
141
  }
103
142
  }
104
- if (!features.length && !bugFix.length) {
105
- console.warn("no release note found, you can run `pnpm run add` to add changeset");
106
- }
107
- let result = "";
108
- if (features.length) {
109
- result += "## Features:\n";
110
- for (const commit of features) {
111
- const releaseNote = await getReleaseNoteLine(commit, customReleaseNoteFunction);
112
- result += releaseNote;
143
+ const result = {
144
+ en: `## ${ChangesTitle}
145
+
146
+ `,
147
+ zh: `## ${ChangesZhTitle}
148
+
149
+ `
150
+ };
151
+ let flag = 0;
152
+ for (const [type, { en, zh }] of Object.entries(releaseNote)) {
153
+ if (en.length > 0) {
154
+ result.en += `### ${CommitTypeTitle[type]}
155
+
156
+ `;
157
+ for (const commit of en) {
158
+ const releaseNote2 = await getReleaseNoteLine(commit, customReleaseNoteFunction, "en");
159
+ result.en += releaseNote2;
160
+ }
113
161
  }
114
- }
115
- if (bugFix.length) {
116
- result += "## Bug Fix:\n";
117
- for (const commit of bugFix) {
118
- const releaseNote = await getReleaseNoteLine(commit, customReleaseNoteFunction);
119
- result += releaseNote;
162
+ if (zh.length > 0) {
163
+ flag = 1;
164
+ result.zh += `### ${CommitTypeZhTitle[type]}
165
+
166
+ `;
167
+ for (const commit of zh) {
168
+ const releaseNote2 = await getReleaseNoteLine(commit, customReleaseNoteFunction, "zh");
169
+ result.zh += releaseNote2;
170
+ }
120
171
  }
121
172
  }
122
- console.info(result);
123
- return result;
173
+ const resultStr = flag ? `${result.en}
174
+
175
+ ${result.zh}` : result.en;
176
+ console.info(resultStr);
177
+ return resultStr;
124
178
  }
@@ -0,0 +1,66 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
22
+ function bump(options) {
23
+ return __async(this, null, function* () {
24
+ const { snapshot, canary, preid, ignore } = options;
25
+ const params = [CHANGESET_PATH, "version"];
26
+ if (snapshot) {
27
+ params.push("--snapshot");
28
+ if (typeof snapshot === "string") {
29
+ params.push(snapshot);
30
+ }
31
+ }
32
+ if (ignore) {
33
+ ignore.forEach((pkg) => {
34
+ params.push("--ignore");
35
+ params.push(pkg);
36
+ });
37
+ }
38
+ if (canary) {
39
+ yield execaWithStreamLog(process.execPath, [
40
+ CHANGESET_PATH,
41
+ "pre",
42
+ "enter",
43
+ preid || "next"
44
+ ]);
45
+ try {
46
+ yield execaWithStreamLog(process.execPath, params);
47
+ yield execaWithStreamLog(process.execPath, [
48
+ CHANGESET_PATH,
49
+ "pre",
50
+ "exit"
51
+ ]);
52
+ } catch (e) {
53
+ yield execaWithStreamLog(process.execPath, [
54
+ CHANGESET_PATH,
55
+ "pre",
56
+ "exit"
57
+ ]);
58
+ }
59
+ } else {
60
+ yield execaWithStreamLog(process.execPath, params);
61
+ }
62
+ });
63
+ }
64
+ export {
65
+ bump
66
+ };
@@ -0,0 +1,57 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import {
22
+ isMonorepo,
23
+ getMonorepoPackages,
24
+ getPackageManager,
25
+ logger
26
+ } from "@modern-js/utils";
27
+ import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
28
+ import { i18n, localeKeys } from "../locale";
29
+ function change(options) {
30
+ return __async(this, null, function* () {
31
+ const appDir = process.cwd();
32
+ if (isMonorepo(appDir)) {
33
+ const packages = getMonorepoPackages(appDir);
34
+ if (packages.length === 0) {
35
+ const packageManager = yield getPackageManager(appDir);
36
+ logger.warn(
37
+ i18n.t(localeKeys.command.change.no_packages, {
38
+ packageManager: packageManager === "yarn" ? "yarn" : `${packageManager} run`
39
+ })
40
+ );
41
+ return;
42
+ }
43
+ }
44
+ const { empty, open } = options;
45
+ const params = [CHANGESET_PATH, "add"];
46
+ if (empty) {
47
+ params.push("--empty");
48
+ }
49
+ if (open) {
50
+ params.push("--open");
51
+ }
52
+ yield execaWithStreamLog(process.execPath, params);
53
+ });
54
+ }
55
+ export {
56
+ change
57
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./change";
2
+ export * from "./bump";
3
+ export * from "./pre";
4
+ export * from "./release";
5
+ export * from "./status";
6
+ export * from "./release-note";
@@ -0,0 +1,33 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { CHANGESET_PATH, execaWithStreamLog } from "../utils";
22
+ function pre(type, tag = "next") {
23
+ return __async(this, null, function* () {
24
+ const params = [CHANGESET_PATH, "pre", type];
25
+ if (type === "enter") {
26
+ params.push(tag);
27
+ }
28
+ yield execaWithStreamLog(process.execPath, params);
29
+ });
30
+ }
31
+ export {
32
+ pre
33
+ };