@soybeanjs/cli 0.4.2 → 0.5.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.
- package/README.md +12 -10
- package/dist/index.cjs +96 -30
- package/dist/index.mjs +95 -30
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -20,16 +20,18 @@ pnpm soy -h
|
|
|
20
20
|
|
|
21
21
|
## 命令介绍
|
|
22
22
|
|
|
23
|
-
| 命令 | 作用
|
|
24
|
-
| ----------------- |
|
|
25
|
-
| help | 查看全部命令用法
|
|
26
|
-
| git-commit | 生成符合 Angular 规范的 git 提交信息
|
|
27
|
-
| git-commit-verify | 校验 git 的提交信息是否符合 Angular 规范
|
|
28
|
-
| cleanup | 清空依赖和构建产物
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
23
|
+
| 命令 | 作用 |
|
|
24
|
+
| ----------------- | ------------------------------------------------------------------ |
|
|
25
|
+
| help | 查看全部命令用法 |
|
|
26
|
+
| git-commit | 生成符合 Angular 规范的 git 提交信息 |
|
|
27
|
+
| git-commit-verify | 校验 git 的提交信息是否符合 Angular 规范 |
|
|
28
|
+
| cleanup | 清空依赖和构建产物 |
|
|
29
|
+
| init-git-hooks | 初始化 simple-git-hooks 钩子 |
|
|
30
|
+
| update-pkg | 升级依赖 |
|
|
31
|
+
| prettier-format | prettier 格式化 |
|
|
32
|
+
| lint-staged | 执行 lint-staged |
|
|
33
|
+
| changelog | 根据两次 tag 生成 changelog (--total: 根据所有 tag 生成 changelog) |
|
|
34
|
+
| release | 发布:更新版本号、生成 changelog、提交代码 |
|
|
33
35
|
|
|
34
36
|
### prettier-format
|
|
35
37
|
|
package/dist/index.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const promises = require('fs/promises');
|
|
|
12
12
|
const EE = require('events');
|
|
13
13
|
const Stream = require('stream');
|
|
14
14
|
const stringdecoder = require('string_decoder');
|
|
15
|
+
const cliProgress = require('cli-progress');
|
|
15
16
|
const ofetch = require('ofetch');
|
|
16
17
|
const dayjs = require('dayjs');
|
|
17
18
|
const convertGitmoji = require('convert-gitmoji');
|
|
@@ -37,10 +38,11 @@ const actualFS__namespace = /*#__PURE__*/_interopNamespaceCompat(actualFS);
|
|
|
37
38
|
const EE__default = /*#__PURE__*/_interopDefaultCompat(EE);
|
|
38
39
|
const Stream__default = /*#__PURE__*/_interopDefaultCompat(Stream);
|
|
39
40
|
const stringdecoder__default = /*#__PURE__*/_interopDefaultCompat(stringdecoder);
|
|
41
|
+
const cliProgress__default = /*#__PURE__*/_interopDefaultCompat(cliProgress);
|
|
40
42
|
const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
|
|
41
43
|
const versionBumpp__default = /*#__PURE__*/_interopDefaultCompat(versionBumpp);
|
|
42
44
|
|
|
43
|
-
const version = "0.
|
|
45
|
+
const version = "0.5.1";
|
|
44
46
|
|
|
45
47
|
async function execCommand(cmd, args, options) {
|
|
46
48
|
const { execa } = await import('execa');
|
|
@@ -7523,11 +7525,35 @@ function lintStaged() {
|
|
|
7523
7525
|
execCommand("npx", ["lint-staged", "--config", "@soybeanjs/cli/lint-staged"], { stdio: "inherit" });
|
|
7524
7526
|
}
|
|
7525
7527
|
|
|
7528
|
+
const VERSION_REG = /v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;
|
|
7529
|
+
const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?]/g;
|
|
7530
|
+
|
|
7526
7531
|
async function getTotalGitTags() {
|
|
7527
7532
|
const tagStr = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]);
|
|
7528
7533
|
const tags = tagStr.split("\n");
|
|
7529
7534
|
return tags;
|
|
7530
7535
|
}
|
|
7536
|
+
async function getTagDateMap() {
|
|
7537
|
+
const tagDateStr = await execCommand("git", [
|
|
7538
|
+
"--no-pager",
|
|
7539
|
+
"log",
|
|
7540
|
+
"--tags",
|
|
7541
|
+
"--simplify-by-decoration",
|
|
7542
|
+
"--pretty=format:%ci %d"
|
|
7543
|
+
]);
|
|
7544
|
+
const TAG_MARK = "tag: ";
|
|
7545
|
+
const map = /* @__PURE__ */ new Map();
|
|
7546
|
+
const dates = tagDateStr.split("\n").filter((item) => item.includes(TAG_MARK));
|
|
7547
|
+
dates.forEach((item) => {
|
|
7548
|
+
const [dateStr, tagStr] = item.split(TAG_MARK);
|
|
7549
|
+
const date = dayjs__default(dateStr).format("YYYY-MM-DD");
|
|
7550
|
+
const tag = tagStr.match(VERSION_REG)?.[0];
|
|
7551
|
+
if (tag && date) {
|
|
7552
|
+
map.set(tag.trim(), date);
|
|
7553
|
+
}
|
|
7554
|
+
});
|
|
7555
|
+
return map;
|
|
7556
|
+
}
|
|
7531
7557
|
function getFromToTags(tags) {
|
|
7532
7558
|
const result = [];
|
|
7533
7559
|
tags.forEach((tag, index) => {
|
|
@@ -7647,17 +7673,17 @@ function getHeaders(githubToken) {
|
|
|
7647
7673
|
async function getResolvedAuthorLogin(params) {
|
|
7648
7674
|
const { github, githubToken, commitHashes, email } = params;
|
|
7649
7675
|
let login = "";
|
|
7650
|
-
if (!githubToken) {
|
|
7651
|
-
return login;
|
|
7652
|
-
}
|
|
7653
7676
|
try {
|
|
7654
|
-
const data = await ofetch.ofetch(`https://
|
|
7655
|
-
login = data
|
|
7677
|
+
const data = await ofetch.ofetch(`https://ungh.cc/users/find/${email}`);
|
|
7678
|
+
login = data?.user?.username || "";
|
|
7656
7679
|
} catch {
|
|
7657
7680
|
}
|
|
7658
7681
|
if (login) {
|
|
7659
7682
|
return login;
|
|
7660
7683
|
}
|
|
7684
|
+
if (!githubToken) {
|
|
7685
|
+
return login;
|
|
7686
|
+
}
|
|
7661
7687
|
if (commitHashes.length) {
|
|
7662
7688
|
try {
|
|
7663
7689
|
const data = await ofetch.ofetch(`https://api.github.com/repos/${github}/commits/${commitHashes[0]}`, {
|
|
@@ -7667,9 +7693,19 @@ async function getResolvedAuthorLogin(params) {
|
|
|
7667
7693
|
} catch (e) {
|
|
7668
7694
|
}
|
|
7669
7695
|
}
|
|
7696
|
+
if (login) {
|
|
7697
|
+
return login;
|
|
7698
|
+
}
|
|
7699
|
+
try {
|
|
7700
|
+
const data = await ofetch.ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(email)}`, {
|
|
7701
|
+
headers: getHeaders(githubToken)
|
|
7702
|
+
});
|
|
7703
|
+
login = data.items[0].login;
|
|
7704
|
+
} catch (e) {
|
|
7705
|
+
}
|
|
7670
7706
|
return login;
|
|
7671
7707
|
}
|
|
7672
|
-
async function getGitCommitsAndResolvedAuthors(commits, github, githubToken) {
|
|
7708
|
+
async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, resolvedLogins) {
|
|
7673
7709
|
const resultCommits = [];
|
|
7674
7710
|
const map = /* @__PURE__ */ new Map();
|
|
7675
7711
|
for (const commit of commits) {
|
|
@@ -7687,14 +7723,18 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken) {
|
|
|
7687
7723
|
commits: commitHashes,
|
|
7688
7724
|
login: ""
|
|
7689
7725
|
};
|
|
7690
|
-
if (!
|
|
7691
|
-
|
|
7692
|
-
|
|
7726
|
+
if (!resolvedLogins?.has(email)) {
|
|
7727
|
+
const login = await getResolvedAuthorLogin({ github, githubToken, commitHashes, email });
|
|
7728
|
+
resolvedAuthor.login = login;
|
|
7729
|
+
resolvedLogins?.set(email, login);
|
|
7693
7730
|
} else {
|
|
7694
|
-
const
|
|
7695
|
-
|
|
7731
|
+
const login = resolvedLogins?.get(email) || "";
|
|
7732
|
+
resolvedAuthor.login = login;
|
|
7696
7733
|
}
|
|
7697
7734
|
resolvedAuthors.push(resolvedAuthor);
|
|
7735
|
+
if (!map.has(email)) {
|
|
7736
|
+
map.set(email, resolvedAuthor);
|
|
7737
|
+
}
|
|
7698
7738
|
}
|
|
7699
7739
|
}
|
|
7700
7740
|
const resultCommit = { ...commit, resolvedAuthors };
|
|
@@ -7705,9 +7745,7 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken) {
|
|
|
7705
7745
|
contributors: Array.from(map.values())
|
|
7706
7746
|
};
|
|
7707
7747
|
}
|
|
7708
|
-
getTotalGitTags();
|
|
7709
7748
|
|
|
7710
|
-
const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+\]/g;
|
|
7711
7749
|
function formatReferences(references, github, type) {
|
|
7712
7750
|
const refs = references.filter((i) => {
|
|
7713
7751
|
if (type === "issues")
|
|
@@ -7769,26 +7807,47 @@ function formatSection(commits, sectionName, options) {
|
|
|
7769
7807
|
});
|
|
7770
7808
|
return lines;
|
|
7771
7809
|
}
|
|
7810
|
+
function getUserGithub(userName) {
|
|
7811
|
+
const githubUrl = `https://github.com/${userName}`;
|
|
7812
|
+
return githubUrl;
|
|
7813
|
+
}
|
|
7772
7814
|
function getGitUserAvatar(userName) {
|
|
7773
|
-
const
|
|
7815
|
+
const githubUrl = getUserGithub(userName);
|
|
7816
|
+
const avatarUrl = `${githubUrl}.png?size=48`;
|
|
7774
7817
|
return avatarUrl;
|
|
7775
7818
|
}
|
|
7776
|
-
function
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
|
|
7781
|
-
|
|
7782
|
-
|
|
7819
|
+
function createContributorLine(contributors) {
|
|
7820
|
+
let loginLine = "";
|
|
7821
|
+
let unloginLine = "";
|
|
7822
|
+
contributors.forEach((contributor, index) => {
|
|
7823
|
+
const { name, email, login } = contributor;
|
|
7824
|
+
if (!login) {
|
|
7825
|
+
let line = `[${name}](mailto:${email})`;
|
|
7826
|
+
if (index < contributors.length - 1) {
|
|
7827
|
+
line += ", ";
|
|
7828
|
+
}
|
|
7829
|
+
unloginLine += line;
|
|
7830
|
+
} else {
|
|
7831
|
+
const githubUrl = getUserGithub(login);
|
|
7832
|
+
const avatar = getGitUserAvatar(login);
|
|
7833
|
+
loginLine += `[](${githubUrl}) `;
|
|
7834
|
+
}
|
|
7835
|
+
});
|
|
7836
|
+
return `${loginLine}
|
|
7837
|
+
${unloginLine}`;
|
|
7783
7838
|
}
|
|
7784
7839
|
function generateMarkdown(params) {
|
|
7785
7840
|
const { commits, options, showTitle, contributors } = params;
|
|
7786
7841
|
const lines = [];
|
|
7787
7842
|
const url = `https://github.com/${options.github}/compare/${options.from}...${options.to}`;
|
|
7788
7843
|
if (showTitle) {
|
|
7789
|
-
const
|
|
7790
|
-
const version =
|
|
7791
|
-
const
|
|
7844
|
+
const isNewVersion = !VERSION_REG.test(options.to);
|
|
7845
|
+
const version = isNewVersion ? options.newVersion : options.to;
|
|
7846
|
+
const date = isNewVersion ? dayjs__default().format("YY-MM-DD") : options.tagDateMap.get(options.to);
|
|
7847
|
+
let title = `## [${version}](${url})`;
|
|
7848
|
+
if (date) {
|
|
7849
|
+
title += ` (${date})`;
|
|
7850
|
+
}
|
|
7792
7851
|
lines.push(title);
|
|
7793
7852
|
}
|
|
7794
7853
|
const [breaking, changes] = partition(commits, (c) => c.isBreaking);
|
|
@@ -7805,13 +7864,12 @@ function generateMarkdown(params) {
|
|
|
7805
7864
|
lines.push("", `##### [View changes on GitHub](${url})`);
|
|
7806
7865
|
}
|
|
7807
7866
|
if (showTitle) {
|
|
7808
|
-
lines.push("", "###
|
|
7809
|
-
const contributorLine = contributors
|
|
7867
|
+
lines.push("", "### \u2764\uFE0F Contributors", "");
|
|
7868
|
+
const contributorLine = createContributorLine(contributors);
|
|
7810
7869
|
lines.push(contributorLine);
|
|
7811
7870
|
}
|
|
7812
7871
|
const md = convertGitmoji.convert(lines.join("\n").trim(), true);
|
|
7813
|
-
|
|
7814
|
-
return markdown;
|
|
7872
|
+
return md;
|
|
7815
7873
|
}
|
|
7816
7874
|
async function isVersionInMarkdown(version, mdPath) {
|
|
7817
7875
|
let isIn = false;
|
|
@@ -7878,6 +7936,7 @@ function createDefaultOptions() {
|
|
|
7878
7936
|
from: "",
|
|
7879
7937
|
to: "",
|
|
7880
7938
|
tags: [],
|
|
7939
|
+
tagDateMap: /* @__PURE__ */ new Map(),
|
|
7881
7940
|
prerelease: false,
|
|
7882
7941
|
capitalize: true,
|
|
7883
7942
|
emoji: true,
|
|
@@ -7926,6 +7985,7 @@ async function initOptions() {
|
|
|
7926
7985
|
options.from = lastTag || firstCommit;
|
|
7927
7986
|
}
|
|
7928
7987
|
options.tags = await getTotalGitTags();
|
|
7988
|
+
options.tagDateMap = await getTagDateMap();
|
|
7929
7989
|
options.github = await getGitHubRepo();
|
|
7930
7990
|
options.prerelease = isPrerelease(options.to);
|
|
7931
7991
|
return options;
|
|
@@ -7942,21 +8002,27 @@ async function generateChangelogByTag(options) {
|
|
|
7942
8002
|
}
|
|
7943
8003
|
async function generateChangelogByTags(options) {
|
|
7944
8004
|
const tags = getFromToTags(options.tags);
|
|
8005
|
+
const bar = new cliProgress__default.SingleBar({}, cliProgress__default.Presets.shades_classic);
|
|
8006
|
+
bar.start(tags.length, 0);
|
|
7945
8007
|
let md = "";
|
|
8008
|
+
const resolvedLogins = /* @__PURE__ */ new Map();
|
|
7946
8009
|
for (let i = 0; i < tags.length; i += 1) {
|
|
7947
8010
|
const { from, to } = tags[i];
|
|
7948
8011
|
const gitCommits = await getGitCommits(from, to, options.scopeMap);
|
|
7949
8012
|
const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
|
|
7950
8013
|
gitCommits,
|
|
7951
8014
|
options.github,
|
|
7952
|
-
options.githubToken
|
|
8015
|
+
options.githubToken,
|
|
8016
|
+
resolvedLogins
|
|
7953
8017
|
);
|
|
7954
8018
|
const opts = { ...options, from, to };
|
|
7955
8019
|
const nextMd = generateMarkdown({ commits, options: opts, showTitle: true, contributors });
|
|
7956
8020
|
md = `${nextMd}
|
|
7957
8021
|
|
|
7958
8022
|
${md}`;
|
|
8023
|
+
bar.update(i + 1);
|
|
7959
8024
|
}
|
|
8025
|
+
bar.stop();
|
|
7960
8026
|
return md;
|
|
7961
8027
|
}
|
|
7962
8028
|
async function generateChangelog(total = false) {
|
package/dist/index.mjs
CHANGED
|
@@ -11,12 +11,13 @@ import { lstat, readdir as readdir$1, readlink, realpath, readFile, writeFile }
|
|
|
11
11
|
import EE from 'events';
|
|
12
12
|
import Stream from 'stream';
|
|
13
13
|
import stringdecoder from 'string_decoder';
|
|
14
|
+
import cliProgress from 'cli-progress';
|
|
14
15
|
import { ofetch } from 'ofetch';
|
|
15
16
|
import dayjs from 'dayjs';
|
|
16
17
|
import { convert } from 'convert-gitmoji';
|
|
17
18
|
import versionBumpp from 'bumpp';
|
|
18
19
|
|
|
19
|
-
const version = "0.
|
|
20
|
+
const version = "0.5.1";
|
|
20
21
|
|
|
21
22
|
async function execCommand(cmd, args, options) {
|
|
22
23
|
const { execa } = await import('execa');
|
|
@@ -7499,11 +7500,35 @@ function lintStaged() {
|
|
|
7499
7500
|
execCommand("npx", ["lint-staged", "--config", "@soybeanjs/cli/lint-staged"], { stdio: "inherit" });
|
|
7500
7501
|
}
|
|
7501
7502
|
|
|
7503
|
+
const VERSION_REG = /v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;
|
|
7504
|
+
const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?]/g;
|
|
7505
|
+
|
|
7502
7506
|
async function getTotalGitTags() {
|
|
7503
7507
|
const tagStr = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]);
|
|
7504
7508
|
const tags = tagStr.split("\n");
|
|
7505
7509
|
return tags;
|
|
7506
7510
|
}
|
|
7511
|
+
async function getTagDateMap() {
|
|
7512
|
+
const tagDateStr = await execCommand("git", [
|
|
7513
|
+
"--no-pager",
|
|
7514
|
+
"log",
|
|
7515
|
+
"--tags",
|
|
7516
|
+
"--simplify-by-decoration",
|
|
7517
|
+
"--pretty=format:%ci %d"
|
|
7518
|
+
]);
|
|
7519
|
+
const TAG_MARK = "tag: ";
|
|
7520
|
+
const map = /* @__PURE__ */ new Map();
|
|
7521
|
+
const dates = tagDateStr.split("\n").filter((item) => item.includes(TAG_MARK));
|
|
7522
|
+
dates.forEach((item) => {
|
|
7523
|
+
const [dateStr, tagStr] = item.split(TAG_MARK);
|
|
7524
|
+
const date = dayjs(dateStr).format("YYYY-MM-DD");
|
|
7525
|
+
const tag = tagStr.match(VERSION_REG)?.[0];
|
|
7526
|
+
if (tag && date) {
|
|
7527
|
+
map.set(tag.trim(), date);
|
|
7528
|
+
}
|
|
7529
|
+
});
|
|
7530
|
+
return map;
|
|
7531
|
+
}
|
|
7507
7532
|
function getFromToTags(tags) {
|
|
7508
7533
|
const result = [];
|
|
7509
7534
|
tags.forEach((tag, index) => {
|
|
@@ -7623,17 +7648,17 @@ function getHeaders(githubToken) {
|
|
|
7623
7648
|
async function getResolvedAuthorLogin(params) {
|
|
7624
7649
|
const { github, githubToken, commitHashes, email } = params;
|
|
7625
7650
|
let login = "";
|
|
7626
|
-
if (!githubToken) {
|
|
7627
|
-
return login;
|
|
7628
|
-
}
|
|
7629
7651
|
try {
|
|
7630
|
-
const data = await ofetch(`https://
|
|
7631
|
-
login = data
|
|
7652
|
+
const data = await ofetch(`https://ungh.cc/users/find/${email}`);
|
|
7653
|
+
login = data?.user?.username || "";
|
|
7632
7654
|
} catch {
|
|
7633
7655
|
}
|
|
7634
7656
|
if (login) {
|
|
7635
7657
|
return login;
|
|
7636
7658
|
}
|
|
7659
|
+
if (!githubToken) {
|
|
7660
|
+
return login;
|
|
7661
|
+
}
|
|
7637
7662
|
if (commitHashes.length) {
|
|
7638
7663
|
try {
|
|
7639
7664
|
const data = await ofetch(`https://api.github.com/repos/${github}/commits/${commitHashes[0]}`, {
|
|
@@ -7643,9 +7668,19 @@ async function getResolvedAuthorLogin(params) {
|
|
|
7643
7668
|
} catch (e) {
|
|
7644
7669
|
}
|
|
7645
7670
|
}
|
|
7671
|
+
if (login) {
|
|
7672
|
+
return login;
|
|
7673
|
+
}
|
|
7674
|
+
try {
|
|
7675
|
+
const data = await ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(email)}`, {
|
|
7676
|
+
headers: getHeaders(githubToken)
|
|
7677
|
+
});
|
|
7678
|
+
login = data.items[0].login;
|
|
7679
|
+
} catch (e) {
|
|
7680
|
+
}
|
|
7646
7681
|
return login;
|
|
7647
7682
|
}
|
|
7648
|
-
async function getGitCommitsAndResolvedAuthors(commits, github, githubToken) {
|
|
7683
|
+
async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, resolvedLogins) {
|
|
7649
7684
|
const resultCommits = [];
|
|
7650
7685
|
const map = /* @__PURE__ */ new Map();
|
|
7651
7686
|
for (const commit of commits) {
|
|
@@ -7663,14 +7698,18 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken) {
|
|
|
7663
7698
|
commits: commitHashes,
|
|
7664
7699
|
login: ""
|
|
7665
7700
|
};
|
|
7666
|
-
if (!
|
|
7667
|
-
|
|
7668
|
-
|
|
7701
|
+
if (!resolvedLogins?.has(email)) {
|
|
7702
|
+
const login = await getResolvedAuthorLogin({ github, githubToken, commitHashes, email });
|
|
7703
|
+
resolvedAuthor.login = login;
|
|
7704
|
+
resolvedLogins?.set(email, login);
|
|
7669
7705
|
} else {
|
|
7670
|
-
const
|
|
7671
|
-
|
|
7706
|
+
const login = resolvedLogins?.get(email) || "";
|
|
7707
|
+
resolvedAuthor.login = login;
|
|
7672
7708
|
}
|
|
7673
7709
|
resolvedAuthors.push(resolvedAuthor);
|
|
7710
|
+
if (!map.has(email)) {
|
|
7711
|
+
map.set(email, resolvedAuthor);
|
|
7712
|
+
}
|
|
7674
7713
|
}
|
|
7675
7714
|
}
|
|
7676
7715
|
const resultCommit = { ...commit, resolvedAuthors };
|
|
@@ -7681,9 +7720,7 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken) {
|
|
|
7681
7720
|
contributors: Array.from(map.values())
|
|
7682
7721
|
};
|
|
7683
7722
|
}
|
|
7684
|
-
getTotalGitTags();
|
|
7685
7723
|
|
|
7686
|
-
const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+\]/g;
|
|
7687
7724
|
function formatReferences(references, github, type) {
|
|
7688
7725
|
const refs = references.filter((i) => {
|
|
7689
7726
|
if (type === "issues")
|
|
@@ -7745,26 +7782,47 @@ function formatSection(commits, sectionName, options) {
|
|
|
7745
7782
|
});
|
|
7746
7783
|
return lines;
|
|
7747
7784
|
}
|
|
7785
|
+
function getUserGithub(userName) {
|
|
7786
|
+
const githubUrl = `https://github.com/${userName}`;
|
|
7787
|
+
return githubUrl;
|
|
7788
|
+
}
|
|
7748
7789
|
function getGitUserAvatar(userName) {
|
|
7749
|
-
const
|
|
7790
|
+
const githubUrl = getUserGithub(userName);
|
|
7791
|
+
const avatarUrl = `${githubUrl}.png?size=48`;
|
|
7750
7792
|
return avatarUrl;
|
|
7751
7793
|
}
|
|
7752
|
-
function
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7794
|
+
function createContributorLine(contributors) {
|
|
7795
|
+
let loginLine = "";
|
|
7796
|
+
let unloginLine = "";
|
|
7797
|
+
contributors.forEach((contributor, index) => {
|
|
7798
|
+
const { name, email, login } = contributor;
|
|
7799
|
+
if (!login) {
|
|
7800
|
+
let line = `[${name}](mailto:${email})`;
|
|
7801
|
+
if (index < contributors.length - 1) {
|
|
7802
|
+
line += ", ";
|
|
7803
|
+
}
|
|
7804
|
+
unloginLine += line;
|
|
7805
|
+
} else {
|
|
7806
|
+
const githubUrl = getUserGithub(login);
|
|
7807
|
+
const avatar = getGitUserAvatar(login);
|
|
7808
|
+
loginLine += `[](${githubUrl}) `;
|
|
7809
|
+
}
|
|
7810
|
+
});
|
|
7811
|
+
return `${loginLine}
|
|
7812
|
+
${unloginLine}`;
|
|
7759
7813
|
}
|
|
7760
7814
|
function generateMarkdown(params) {
|
|
7761
7815
|
const { commits, options, showTitle, contributors } = params;
|
|
7762
7816
|
const lines = [];
|
|
7763
7817
|
const url = `https://github.com/${options.github}/compare/${options.from}...${options.to}`;
|
|
7764
7818
|
if (showTitle) {
|
|
7765
|
-
const
|
|
7766
|
-
const version =
|
|
7767
|
-
const
|
|
7819
|
+
const isNewVersion = !VERSION_REG.test(options.to);
|
|
7820
|
+
const version = isNewVersion ? options.newVersion : options.to;
|
|
7821
|
+
const date = isNewVersion ? dayjs().format("YY-MM-DD") : options.tagDateMap.get(options.to);
|
|
7822
|
+
let title = `## [${version}](${url})`;
|
|
7823
|
+
if (date) {
|
|
7824
|
+
title += ` (${date})`;
|
|
7825
|
+
}
|
|
7768
7826
|
lines.push(title);
|
|
7769
7827
|
}
|
|
7770
7828
|
const [breaking, changes] = partition(commits, (c) => c.isBreaking);
|
|
@@ -7781,13 +7839,12 @@ function generateMarkdown(params) {
|
|
|
7781
7839
|
lines.push("", `##### [View changes on GitHub](${url})`);
|
|
7782
7840
|
}
|
|
7783
7841
|
if (showTitle) {
|
|
7784
|
-
lines.push("", "###
|
|
7785
|
-
const contributorLine = contributors
|
|
7842
|
+
lines.push("", "### \u2764\uFE0F Contributors", "");
|
|
7843
|
+
const contributorLine = createContributorLine(contributors);
|
|
7786
7844
|
lines.push(contributorLine);
|
|
7787
7845
|
}
|
|
7788
7846
|
const md = convert(lines.join("\n").trim(), true);
|
|
7789
|
-
|
|
7790
|
-
return markdown;
|
|
7847
|
+
return md;
|
|
7791
7848
|
}
|
|
7792
7849
|
async function isVersionInMarkdown(version, mdPath) {
|
|
7793
7850
|
let isIn = false;
|
|
@@ -7854,6 +7911,7 @@ function createDefaultOptions() {
|
|
|
7854
7911
|
from: "",
|
|
7855
7912
|
to: "",
|
|
7856
7913
|
tags: [],
|
|
7914
|
+
tagDateMap: /* @__PURE__ */ new Map(),
|
|
7857
7915
|
prerelease: false,
|
|
7858
7916
|
capitalize: true,
|
|
7859
7917
|
emoji: true,
|
|
@@ -7902,6 +7960,7 @@ async function initOptions() {
|
|
|
7902
7960
|
options.from = lastTag || firstCommit;
|
|
7903
7961
|
}
|
|
7904
7962
|
options.tags = await getTotalGitTags();
|
|
7963
|
+
options.tagDateMap = await getTagDateMap();
|
|
7905
7964
|
options.github = await getGitHubRepo();
|
|
7906
7965
|
options.prerelease = isPrerelease(options.to);
|
|
7907
7966
|
return options;
|
|
@@ -7918,21 +7977,27 @@ async function generateChangelogByTag(options) {
|
|
|
7918
7977
|
}
|
|
7919
7978
|
async function generateChangelogByTags(options) {
|
|
7920
7979
|
const tags = getFromToTags(options.tags);
|
|
7980
|
+
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
7981
|
+
bar.start(tags.length, 0);
|
|
7921
7982
|
let md = "";
|
|
7983
|
+
const resolvedLogins = /* @__PURE__ */ new Map();
|
|
7922
7984
|
for (let i = 0; i < tags.length; i += 1) {
|
|
7923
7985
|
const { from, to } = tags[i];
|
|
7924
7986
|
const gitCommits = await getGitCommits(from, to, options.scopeMap);
|
|
7925
7987
|
const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
|
|
7926
7988
|
gitCommits,
|
|
7927
7989
|
options.github,
|
|
7928
|
-
options.githubToken
|
|
7990
|
+
options.githubToken,
|
|
7991
|
+
resolvedLogins
|
|
7929
7992
|
);
|
|
7930
7993
|
const opts = { ...options, from, to };
|
|
7931
7994
|
const nextMd = generateMarkdown({ commits, options: opts, showTitle: true, contributors });
|
|
7932
7995
|
md = `${nextMd}
|
|
7933
7996
|
|
|
7934
7997
|
${md}`;
|
|
7998
|
+
bar.update(i + 1);
|
|
7935
7999
|
}
|
|
8000
|
+
bar.stop();
|
|
7936
8001
|
return md;
|
|
7937
8002
|
}
|
|
7938
8003
|
async function generateChangelog(total = false) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "SoybeanJS's command line tools",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Soybean",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"bumpp": "9.1.0",
|
|
36
36
|
"cac": "6.7.14",
|
|
37
|
+
"cli-progress": "^3.12.0",
|
|
37
38
|
"convert-gitmoji": "0.1.3",
|
|
38
39
|
"dayjs": "1.11.8",
|
|
39
40
|
"enquirer": "2.3.6",
|
|
@@ -47,10 +48,10 @@
|
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@soybeanjs/cli": "link:",
|
|
51
|
+
"@types/cli-progress": "^3.11.0",
|
|
50
52
|
"@types/node": "20.2.5",
|
|
51
53
|
"eslint": "8.41.0",
|
|
52
54
|
"eslint-config-soybeanjs": "0.4.7",
|
|
53
|
-
"githublogen": "link:../githublogen",
|
|
54
55
|
"simple-git-hooks": "2.8.1",
|
|
55
56
|
"tsx": "3.12.7",
|
|
56
57
|
"typescript": "5.0.4",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"commit-msg": "pnpm soy git-commit-verify",
|
|
61
62
|
"pre-commit": "pnpm typecheck && pnpm soy lint-staged"
|
|
62
63
|
},
|
|
63
|
-
"github-token": "
|
|
64
|
+
"github-token": "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",
|
|
64
65
|
"scripts": {
|
|
65
66
|
"build": "pnpm typecheck && unbuild",
|
|
66
67
|
"lint": "eslint . --fix",
|