@soybeanjs/cli 0.5.0 → 0.5.2

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 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
- | cleanup-deep | 清空依赖和构建产物(包含 深层级) |
30
- | init-git-hooks | 初始化 simple-gi t-hooks 钩子 |
31
- | update-pkg | 升级依赖 |
32
- | prettier-format | prettier 格式化 |
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
@@ -42,7 +42,7 @@ const cliProgress__default = /*#__PURE__*/_interopDefaultCompat(cliProgress);
42
42
  const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
43
43
  const versionBumpp__default = /*#__PURE__*/_interopDefaultCompat(versionBumpp);
44
44
 
45
- const version = "0.5.0";
45
+ const version = "0.5.2";
46
46
 
47
47
  async function execCommand(cmd, args, options) {
48
48
  const { execa } = await import('execa');
@@ -7525,6 +7525,9 @@ function lintStaged() {
7525
7525
  execCommand("npx", ["lint-staged", "--config", "@soybeanjs/cli/lint-staged"], { stdio: "inherit" });
7526
7526
  }
7527
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
+
7528
7531
  async function getTotalGitTags() {
7529
7532
  const tagStr = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]);
7530
7533
  const tags = tagStr.split("\n");
@@ -7538,13 +7541,12 @@ async function getTagDateMap() {
7538
7541
  "--simplify-by-decoration",
7539
7542
  "--pretty=format:%ci %d"
7540
7543
  ]);
7541
- const TAG_MARK = "(tag: ";
7544
+ const TAG_MARK = "tag: ";
7542
7545
  const map = /* @__PURE__ */ new Map();
7543
7546
  const dates = tagDateStr.split("\n").filter((item) => item.includes(TAG_MARK));
7544
7547
  dates.forEach((item) => {
7545
7548
  const [dateStr, tagStr] = item.split(TAG_MARK);
7546
- const date = dayjs__default(dateStr.trim()).format("YYYY-MM-DD");
7547
- const VERSION_REG = /v\d+\.\d+\.\d+/;
7549
+ const date = dayjs__default(dateStr).format("YYYY-MM-DD");
7548
7550
  const tag = tagStr.match(VERSION_REG)?.[0];
7549
7551
  if (tag && date) {
7550
7552
  map.set(tag.trim(), date);
@@ -7668,37 +7670,47 @@ function getHeaders(githubToken) {
7668
7670
  authorization: `token ${githubToken}`
7669
7671
  };
7670
7672
  }
7671
- async function getResolvedAuthorLogin(params) {
7672
- const { github, githubToken, commitHashes, email } = params;
7673
+ async function getResolvedAuthorLogin(github, commitHashes, email) {
7673
7674
  let login = "";
7674
- if (!githubToken) {
7675
- return login;
7676
- }
7677
7675
  try {
7678
- const data = await ofetch.ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(email)}`);
7679
- login = data.items[0].login;
7676
+ const data = await ofetch.ofetch(`https://ungh.cc/users/find/${email}`);
7677
+ login = data?.user?.username || "";
7680
7678
  } catch {
7681
7679
  }
7682
7680
  if (login) {
7683
7681
  return login;
7684
7682
  }
7683
+ const { repo, token } = github;
7684
+ if (!token) {
7685
+ return login;
7686
+ }
7685
7687
  if (commitHashes.length) {
7686
7688
  try {
7687
- const data = await ofetch.ofetch(`https://api.github.com/repos/${github}/commits/${commitHashes[0]}`, {
7688
- headers: getHeaders(githubToken)
7689
+ const data = await ofetch.ofetch(`https://api.github.com/repos/${repo}/commits/${commitHashes[0]}`, {
7690
+ headers: getHeaders(token)
7689
7691
  });
7690
7692
  login = data?.author?.login || "";
7691
7693
  } catch (e) {
7692
7694
  }
7693
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(token)
7702
+ });
7703
+ login = data.items[0].login;
7704
+ } catch (e) {
7705
+ }
7694
7706
  return login;
7695
7707
  }
7696
- async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, resolvedLogins) {
7708
+ async function getGitCommitsAndResolvedAuthors(commits, github, resolvedLogins) {
7697
7709
  const resultCommits = [];
7698
7710
  const map = /* @__PURE__ */ new Map();
7699
- for (const commit of commits) {
7711
+ for await (const commit of commits) {
7700
7712
  const resolvedAuthors = [];
7701
- for (const [index, author] of Object.entries(commit.authors)) {
7713
+ for await (const [index, author] of Object.entries(commit.authors)) {
7702
7714
  const { email, name } = author;
7703
7715
  if (email && name) {
7704
7716
  const commitHashes = [];
@@ -7712,7 +7724,7 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, res
7712
7724
  login: ""
7713
7725
  };
7714
7726
  if (!resolvedLogins?.has(email)) {
7715
- const login = await getResolvedAuthorLogin({ github, githubToken, commitHashes, email });
7727
+ const login = await getResolvedAuthorLogin(github, commitHashes, email);
7716
7728
  resolvedAuthor.login = login;
7717
7729
  resolvedLogins?.set(email, login);
7718
7730
  } else {
@@ -7752,8 +7764,8 @@ function formatReferences(references, github, type) {
7752
7764
  return referencesString;
7753
7765
  }
7754
7766
  function formatLine(commit, options) {
7755
- const prRefs = formatReferences(commit.references, options.github, "issues");
7756
- const hashRefs = formatReferences(commit.references, options.github, "hash");
7767
+ const prRefs = formatReferences(commit.references, options.github.repo, "issues");
7768
+ const hashRefs = formatReferences(commit.references, options.github.repo, "hash");
7757
7769
  let authors = join([...new Set(commit.resolvedAuthors.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))]).trim();
7758
7770
  if (authors) {
7759
7771
  authors = `by ${authors}`;
@@ -7795,8 +7807,13 @@ function formatSection(commits, sectionName, options) {
7795
7807
  });
7796
7808
  return lines;
7797
7809
  }
7810
+ function getUserGithub(userName) {
7811
+ const githubUrl = `https://github.com/${userName}`;
7812
+ return githubUrl;
7813
+ }
7798
7814
  function getGitUserAvatar(userName) {
7799
- const avatarUrl = `https://github.com/${userName}.png?size=48`;
7815
+ const githubUrl = getUserGithub(userName);
7816
+ const avatarUrl = `${githubUrl}.png?size=48`;
7800
7817
  return avatarUrl;
7801
7818
  }
7802
7819
  function createContributorLine(contributors) {
@@ -7807,25 +7824,26 @@ function createContributorLine(contributors) {
7807
7824
  if (!login) {
7808
7825
  let line = `[${name}](mailto:${email})`;
7809
7826
  if (index < contributors.length - 1) {
7810
- line += ", ";
7827
+ line += ",&nbsp;";
7811
7828
  }
7812
7829
  unloginLine += line;
7813
7830
  } else {
7831
+ const githubUrl = getUserGithub(login);
7814
7832
  const avatar = getGitUserAvatar(login);
7815
- loginLine += `![${login}](${avatar}) `;
7833
+ loginLine += `[![${login}](${avatar})](${githubUrl})&nbsp;&nbsp;`;
7816
7834
  }
7817
7835
  });
7818
7836
  return `${loginLine}
7819
7837
  ${unloginLine}`;
7820
7838
  }
7821
7839
  function generateMarkdown(params) {
7822
- const VERSION_REG = /v\d+\.\d+\.\d+/;
7823
7840
  const { commits, options, showTitle, contributors } = params;
7824
7841
  const lines = [];
7825
- const url = `https://github.com/${options.github}/compare/${options.from}...${options.to}`;
7842
+ const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to}`;
7826
7843
  if (showTitle) {
7827
- const version = VERSION_REG.test(options.to) ? options.to : options.newVersion;
7828
- const date = options.tagDateMap.get(options.to);
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);
7829
7847
  let title = `## [${version}](${url})`;
7830
7848
  if (date) {
7831
7849
  title += ` (${date})`;
@@ -7846,16 +7864,14 @@ function generateMarkdown(params) {
7846
7864
  lines.push("", `##### &nbsp;&nbsp;&nbsp;&nbsp;[View changes on GitHub](${url})`);
7847
7865
  }
7848
7866
  if (showTitle) {
7849
- lines.push("", "### \u2764\uFE0F Contributors", "");
7867
+ lines.push("", "### &nbsp;&nbsp;&nbsp;\u2764\uFE0F Contributors", "");
7850
7868
  const contributorLine = createContributorLine(contributors);
7851
7869
  lines.push(contributorLine);
7852
7870
  }
7853
7871
  const md = convertGitmoji.convert(lines.join("\n").trim(), true);
7854
- const markdown = md.replace(/&nbsp;/g, "");
7855
- return markdown;
7872
+ return md;
7856
7873
  }
7857
7874
  async function isVersionInMarkdown(version, mdPath) {
7858
- const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+\]/g;
7859
7875
  let isIn = false;
7860
7876
  const md = await promises.readFile(mdPath, "utf8");
7861
7877
  if (md) {
@@ -7915,8 +7931,10 @@ function createDefaultOptions() {
7915
7931
  ci: { title: "\u{1F916} CI" }
7916
7932
  },
7917
7933
  scopeMap: {},
7918
- github: "",
7919
- githubToken: process.env.GITHUB_TOKEN || "",
7934
+ github: {
7935
+ repo: "",
7936
+ token: process.env.GITHUB_TOKEN || ""
7937
+ },
7920
7938
  from: "",
7921
7939
  to: "",
7922
7940
  tags: [],
@@ -7949,20 +7967,14 @@ async function getOptionsFromPkg(cwd) {
7949
7967
  };
7950
7968
  }
7951
7969
  async function initOptions() {
7970
+ var _a;
7952
7971
  const options = createDefaultOptions();
7953
7972
  const { githubToken, newVersion } = await getOptionsFromPkg(options.cwd);
7954
- if (!options.githubToken) {
7955
- options.githubToken = githubToken;
7956
- }
7957
- if (newVersion) {
7958
- options.newVersion = `v${newVersion}`;
7959
- }
7960
- if (!options.from) {
7961
- options.from = await getLastGitTag();
7962
- }
7963
- if (!options.to) {
7964
- options.to = await getCurrentGitBranch();
7965
- }
7973
+ (_a = options.github).token || (_a.token = githubToken);
7974
+ options.github.repo = await getGitHubRepo();
7975
+ options.newVersion || (options.newVersion = `v${newVersion}`);
7976
+ options.from || (options.from = await getLastGitTag());
7977
+ options.to || (options.to = await getCurrentGitBranch());
7966
7978
  if (options.to === options.from) {
7967
7979
  const lastTag = await getLastGitTag(-1);
7968
7980
  const firstCommit = await getFirstGitCommit();
@@ -7970,17 +7982,12 @@ async function initOptions() {
7970
7982
  }
7971
7983
  options.tags = await getTotalGitTags();
7972
7984
  options.tagDateMap = await getTagDateMap();
7973
- options.github = await getGitHubRepo();
7974
7985
  options.prerelease = isPrerelease(options.to);
7975
7986
  return options;
7976
7987
  }
7977
7988
  async function generateChangelogByTag(options) {
7978
7989
  const gitCommits = await getGitCommits(options.from, options.to, options.scopeMap);
7979
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7980
- gitCommits,
7981
- options.github,
7982
- options.githubToken
7983
- );
7990
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github);
7984
7991
  const md = generateMarkdown({ commits, options, showTitle: true, contributors });
7985
7992
  return md;
7986
7993
  }
@@ -7990,21 +7997,16 @@ async function generateChangelogByTags(options) {
7990
7997
  bar.start(tags.length, 0);
7991
7998
  let md = "";
7992
7999
  const resolvedLogins = /* @__PURE__ */ new Map();
7993
- for (let i = 0; i < tags.length; i += 1) {
7994
- const { from, to } = tags[i];
8000
+ for await (const [index, tag] of tags.entries()) {
8001
+ const { from, to } = tag;
7995
8002
  const gitCommits = await getGitCommits(from, to, options.scopeMap);
7996
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7997
- gitCommits,
7998
- options.github,
7999
- options.githubToken,
8000
- resolvedLogins
8001
- );
8003
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github, resolvedLogins);
8002
8004
  const opts = { ...options, from, to };
8003
8005
  const nextMd = generateMarkdown({ commits, options: opts, showTitle: true, contributors });
8004
8006
  md = `${nextMd}
8005
8007
 
8006
8008
  ${md}`;
8007
- bar.update(i + 1);
8009
+ bar.update(index + 1);
8008
8010
  }
8009
8011
  bar.stop();
8010
8012
  return md;
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ import dayjs from 'dayjs';
17
17
  import { convert } from 'convert-gitmoji';
18
18
  import versionBumpp from 'bumpp';
19
19
 
20
- const version = "0.5.0";
20
+ const version = "0.5.2";
21
21
 
22
22
  async function execCommand(cmd, args, options) {
23
23
  const { execa } = await import('execa');
@@ -7500,6 +7500,9 @@ function lintStaged() {
7500
7500
  execCommand("npx", ["lint-staged", "--config", "@soybeanjs/cli/lint-staged"], { stdio: "inherit" });
7501
7501
  }
7502
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
+
7503
7506
  async function getTotalGitTags() {
7504
7507
  const tagStr = await execCommand("git", ["--no-pager", "tag", "-l", "--sort=creatordate"]);
7505
7508
  const tags = tagStr.split("\n");
@@ -7513,13 +7516,12 @@ async function getTagDateMap() {
7513
7516
  "--simplify-by-decoration",
7514
7517
  "--pretty=format:%ci %d"
7515
7518
  ]);
7516
- const TAG_MARK = "(tag: ";
7519
+ const TAG_MARK = "tag: ";
7517
7520
  const map = /* @__PURE__ */ new Map();
7518
7521
  const dates = tagDateStr.split("\n").filter((item) => item.includes(TAG_MARK));
7519
7522
  dates.forEach((item) => {
7520
7523
  const [dateStr, tagStr] = item.split(TAG_MARK);
7521
- const date = dayjs(dateStr.trim()).format("YYYY-MM-DD");
7522
- const VERSION_REG = /v\d+\.\d+\.\d+/;
7524
+ const date = dayjs(dateStr).format("YYYY-MM-DD");
7523
7525
  const tag = tagStr.match(VERSION_REG)?.[0];
7524
7526
  if (tag && date) {
7525
7527
  map.set(tag.trim(), date);
@@ -7643,37 +7645,47 @@ function getHeaders(githubToken) {
7643
7645
  authorization: `token ${githubToken}`
7644
7646
  };
7645
7647
  }
7646
- async function getResolvedAuthorLogin(params) {
7647
- const { github, githubToken, commitHashes, email } = params;
7648
+ async function getResolvedAuthorLogin(github, commitHashes, email) {
7648
7649
  let login = "";
7649
- if (!githubToken) {
7650
- return login;
7651
- }
7652
7650
  try {
7653
- const data = await ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(email)}`);
7654
- login = data.items[0].login;
7651
+ const data = await ofetch(`https://ungh.cc/users/find/${email}`);
7652
+ login = data?.user?.username || "";
7655
7653
  } catch {
7656
7654
  }
7657
7655
  if (login) {
7658
7656
  return login;
7659
7657
  }
7658
+ const { repo, token } = github;
7659
+ if (!token) {
7660
+ return login;
7661
+ }
7660
7662
  if (commitHashes.length) {
7661
7663
  try {
7662
- const data = await ofetch(`https://api.github.com/repos/${github}/commits/${commitHashes[0]}`, {
7663
- headers: getHeaders(githubToken)
7664
+ const data = await ofetch(`https://api.github.com/repos/${repo}/commits/${commitHashes[0]}`, {
7665
+ headers: getHeaders(token)
7664
7666
  });
7665
7667
  login = data?.author?.login || "";
7666
7668
  } catch (e) {
7667
7669
  }
7668
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(token)
7677
+ });
7678
+ login = data.items[0].login;
7679
+ } catch (e) {
7680
+ }
7669
7681
  return login;
7670
7682
  }
7671
- async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, resolvedLogins) {
7683
+ async function getGitCommitsAndResolvedAuthors(commits, github, resolvedLogins) {
7672
7684
  const resultCommits = [];
7673
7685
  const map = /* @__PURE__ */ new Map();
7674
- for (const commit of commits) {
7686
+ for await (const commit of commits) {
7675
7687
  const resolvedAuthors = [];
7676
- for (const [index, author] of Object.entries(commit.authors)) {
7688
+ for await (const [index, author] of Object.entries(commit.authors)) {
7677
7689
  const { email, name } = author;
7678
7690
  if (email && name) {
7679
7691
  const commitHashes = [];
@@ -7687,7 +7699,7 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, res
7687
7699
  login: ""
7688
7700
  };
7689
7701
  if (!resolvedLogins?.has(email)) {
7690
- const login = await getResolvedAuthorLogin({ github, githubToken, commitHashes, email });
7702
+ const login = await getResolvedAuthorLogin(github, commitHashes, email);
7691
7703
  resolvedAuthor.login = login;
7692
7704
  resolvedLogins?.set(email, login);
7693
7705
  } else {
@@ -7727,8 +7739,8 @@ function formatReferences(references, github, type) {
7727
7739
  return referencesString;
7728
7740
  }
7729
7741
  function formatLine(commit, options) {
7730
- const prRefs = formatReferences(commit.references, options.github, "issues");
7731
- const hashRefs = formatReferences(commit.references, options.github, "hash");
7742
+ const prRefs = formatReferences(commit.references, options.github.repo, "issues");
7743
+ const hashRefs = formatReferences(commit.references, options.github.repo, "hash");
7732
7744
  let authors = join([...new Set(commit.resolvedAuthors.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))]).trim();
7733
7745
  if (authors) {
7734
7746
  authors = `by ${authors}`;
@@ -7770,8 +7782,13 @@ function formatSection(commits, sectionName, options) {
7770
7782
  });
7771
7783
  return lines;
7772
7784
  }
7785
+ function getUserGithub(userName) {
7786
+ const githubUrl = `https://github.com/${userName}`;
7787
+ return githubUrl;
7788
+ }
7773
7789
  function getGitUserAvatar(userName) {
7774
- const avatarUrl = `https://github.com/${userName}.png?size=48`;
7790
+ const githubUrl = getUserGithub(userName);
7791
+ const avatarUrl = `${githubUrl}.png?size=48`;
7775
7792
  return avatarUrl;
7776
7793
  }
7777
7794
  function createContributorLine(contributors) {
@@ -7782,25 +7799,26 @@ function createContributorLine(contributors) {
7782
7799
  if (!login) {
7783
7800
  let line = `[${name}](mailto:${email})`;
7784
7801
  if (index < contributors.length - 1) {
7785
- line += ", ";
7802
+ line += ",&nbsp;";
7786
7803
  }
7787
7804
  unloginLine += line;
7788
7805
  } else {
7806
+ const githubUrl = getUserGithub(login);
7789
7807
  const avatar = getGitUserAvatar(login);
7790
- loginLine += `![${login}](${avatar}) `;
7808
+ loginLine += `[![${login}](${avatar})](${githubUrl})&nbsp;&nbsp;`;
7791
7809
  }
7792
7810
  });
7793
7811
  return `${loginLine}
7794
7812
  ${unloginLine}`;
7795
7813
  }
7796
7814
  function generateMarkdown(params) {
7797
- const VERSION_REG = /v\d+\.\d+\.\d+/;
7798
7815
  const { commits, options, showTitle, contributors } = params;
7799
7816
  const lines = [];
7800
- const url = `https://github.com/${options.github}/compare/${options.from}...${options.to}`;
7817
+ const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.to}`;
7801
7818
  if (showTitle) {
7802
- const version = VERSION_REG.test(options.to) ? options.to : options.newVersion;
7803
- const date = options.tagDateMap.get(options.to);
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);
7804
7822
  let title = `## [${version}](${url})`;
7805
7823
  if (date) {
7806
7824
  title += ` (${date})`;
@@ -7821,16 +7839,14 @@ function generateMarkdown(params) {
7821
7839
  lines.push("", `##### &nbsp;&nbsp;&nbsp;&nbsp;[View changes on GitHub](${url})`);
7822
7840
  }
7823
7841
  if (showTitle) {
7824
- lines.push("", "### \u2764\uFE0F Contributors", "");
7842
+ lines.push("", "### &nbsp;&nbsp;&nbsp;\u2764\uFE0F Contributors", "");
7825
7843
  const contributorLine = createContributorLine(contributors);
7826
7844
  lines.push(contributorLine);
7827
7845
  }
7828
7846
  const md = convert(lines.join("\n").trim(), true);
7829
- const markdown = md.replace(/&nbsp;/g, "");
7830
- return markdown;
7847
+ return md;
7831
7848
  }
7832
7849
  async function isVersionInMarkdown(version, mdPath) {
7833
- const VERSION_REG_OF_MARKDOWN = /## \[v\d+\.\d+\.\d+\]/g;
7834
7850
  let isIn = false;
7835
7851
  const md = await readFile(mdPath, "utf8");
7836
7852
  if (md) {
@@ -7890,8 +7906,10 @@ function createDefaultOptions() {
7890
7906
  ci: { title: "\u{1F916} CI" }
7891
7907
  },
7892
7908
  scopeMap: {},
7893
- github: "",
7894
- githubToken: process.env.GITHUB_TOKEN || "",
7909
+ github: {
7910
+ repo: "",
7911
+ token: process.env.GITHUB_TOKEN || ""
7912
+ },
7895
7913
  from: "",
7896
7914
  to: "",
7897
7915
  tags: [],
@@ -7924,20 +7942,14 @@ async function getOptionsFromPkg(cwd) {
7924
7942
  };
7925
7943
  }
7926
7944
  async function initOptions() {
7945
+ var _a;
7927
7946
  const options = createDefaultOptions();
7928
7947
  const { githubToken, newVersion } = await getOptionsFromPkg(options.cwd);
7929
- if (!options.githubToken) {
7930
- options.githubToken = githubToken;
7931
- }
7932
- if (newVersion) {
7933
- options.newVersion = `v${newVersion}`;
7934
- }
7935
- if (!options.from) {
7936
- options.from = await getLastGitTag();
7937
- }
7938
- if (!options.to) {
7939
- options.to = await getCurrentGitBranch();
7940
- }
7948
+ (_a = options.github).token || (_a.token = githubToken);
7949
+ options.github.repo = await getGitHubRepo();
7950
+ options.newVersion || (options.newVersion = `v${newVersion}`);
7951
+ options.from || (options.from = await getLastGitTag());
7952
+ options.to || (options.to = await getCurrentGitBranch());
7941
7953
  if (options.to === options.from) {
7942
7954
  const lastTag = await getLastGitTag(-1);
7943
7955
  const firstCommit = await getFirstGitCommit();
@@ -7945,17 +7957,12 @@ async function initOptions() {
7945
7957
  }
7946
7958
  options.tags = await getTotalGitTags();
7947
7959
  options.tagDateMap = await getTagDateMap();
7948
- options.github = await getGitHubRepo();
7949
7960
  options.prerelease = isPrerelease(options.to);
7950
7961
  return options;
7951
7962
  }
7952
7963
  async function generateChangelogByTag(options) {
7953
7964
  const gitCommits = await getGitCommits(options.from, options.to, options.scopeMap);
7954
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7955
- gitCommits,
7956
- options.github,
7957
- options.githubToken
7958
- );
7965
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github);
7959
7966
  const md = generateMarkdown({ commits, options, showTitle: true, contributors });
7960
7967
  return md;
7961
7968
  }
@@ -7965,21 +7972,16 @@ async function generateChangelogByTags(options) {
7965
7972
  bar.start(tags.length, 0);
7966
7973
  let md = "";
7967
7974
  const resolvedLogins = /* @__PURE__ */ new Map();
7968
- for (let i = 0; i < tags.length; i += 1) {
7969
- const { from, to } = tags[i];
7975
+ for await (const [index, tag] of tags.entries()) {
7976
+ const { from, to } = tag;
7970
7977
  const gitCommits = await getGitCommits(from, to, options.scopeMap);
7971
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7972
- gitCommits,
7973
- options.github,
7974
- options.githubToken,
7975
- resolvedLogins
7976
- );
7978
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github, resolvedLogins);
7977
7979
  const opts = { ...options, from, to };
7978
7980
  const nextMd = generateMarkdown({ commits, options: opts, showTitle: true, contributors });
7979
7981
  md = `${nextMd}
7980
7982
 
7981
7983
  ${md}`;
7982
- bar.update(i + 1);
7984
+ bar.update(index + 1);
7983
7985
  }
7984
7986
  bar.stop();
7985
7987
  return md;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soybeanjs/cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "SoybeanJS's command line tools",
5
5
  "author": {
6
6
  "name": "Soybean",
@@ -61,7 +61,7 @@
61
61
  "commit-msg": "pnpm soy git-commit-verify",
62
62
  "pre-commit": "pnpm typecheck && pnpm soy lint-staged"
63
63
  },
64
- "github-token": "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",
64
+ "github-token": "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",
65
65
  "scripts": {
66
66
  "build": "pnpm typecheck && unbuild",
67
67
  "lint": "eslint . --fix",