@soybeanjs/cli 0.5.1 → 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/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.1";
45
+ const version = "0.5.2";
46
46
 
47
47
  async function execCommand(cmd, args, options) {
48
48
  const { execa } = await import('execa');
@@ -7670,8 +7670,7 @@ function getHeaders(githubToken) {
7670
7670
  authorization: `token ${githubToken}`
7671
7671
  };
7672
7672
  }
7673
- async function getResolvedAuthorLogin(params) {
7674
- const { github, githubToken, commitHashes, email } = params;
7673
+ async function getResolvedAuthorLogin(github, commitHashes, email) {
7675
7674
  let login = "";
7676
7675
  try {
7677
7676
  const data = await ofetch.ofetch(`https://ungh.cc/users/find/${email}`);
@@ -7681,13 +7680,14 @@ async function getResolvedAuthorLogin(params) {
7681
7680
  if (login) {
7682
7681
  return login;
7683
7682
  }
7684
- if (!githubToken) {
7683
+ const { repo, token } = github;
7684
+ if (!token) {
7685
7685
  return login;
7686
7686
  }
7687
7687
  if (commitHashes.length) {
7688
7688
  try {
7689
- const data = await ofetch.ofetch(`https://api.github.com/repos/${github}/commits/${commitHashes[0]}`, {
7690
- headers: getHeaders(githubToken)
7689
+ const data = await ofetch.ofetch(`https://api.github.com/repos/${repo}/commits/${commitHashes[0]}`, {
7690
+ headers: getHeaders(token)
7691
7691
  });
7692
7692
  login = data?.author?.login || "";
7693
7693
  } catch (e) {
@@ -7698,19 +7698,19 @@ async function getResolvedAuthorLogin(params) {
7698
7698
  }
7699
7699
  try {
7700
7700
  const data = await ofetch.ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(email)}`, {
7701
- headers: getHeaders(githubToken)
7701
+ headers: getHeaders(token)
7702
7702
  });
7703
7703
  login = data.items[0].login;
7704
7704
  } catch (e) {
7705
7705
  }
7706
7706
  return login;
7707
7707
  }
7708
- async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, resolvedLogins) {
7708
+ async function getGitCommitsAndResolvedAuthors(commits, github, resolvedLogins) {
7709
7709
  const resultCommits = [];
7710
7710
  const map = /* @__PURE__ */ new Map();
7711
- for (const commit of commits) {
7711
+ for await (const commit of commits) {
7712
7712
  const resolvedAuthors = [];
7713
- for (const [index, author] of Object.entries(commit.authors)) {
7713
+ for await (const [index, author] of Object.entries(commit.authors)) {
7714
7714
  const { email, name } = author;
7715
7715
  if (email && name) {
7716
7716
  const commitHashes = [];
@@ -7724,7 +7724,7 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, res
7724
7724
  login: ""
7725
7725
  };
7726
7726
  if (!resolvedLogins?.has(email)) {
7727
- const login = await getResolvedAuthorLogin({ github, githubToken, commitHashes, email });
7727
+ const login = await getResolvedAuthorLogin(github, commitHashes, email);
7728
7728
  resolvedAuthor.login = login;
7729
7729
  resolvedLogins?.set(email, login);
7730
7730
  } else {
@@ -7764,8 +7764,8 @@ function formatReferences(references, github, type) {
7764
7764
  return referencesString;
7765
7765
  }
7766
7766
  function formatLine(commit, options) {
7767
- const prRefs = formatReferences(commit.references, options.github, "issues");
7768
- 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");
7769
7769
  let authors = join([...new Set(commit.resolvedAuthors.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))]).trim();
7770
7770
  if (authors) {
7771
7771
  authors = `by ${authors}`;
@@ -7839,7 +7839,7 @@ ${unloginLine}`;
7839
7839
  function generateMarkdown(params) {
7840
7840
  const { commits, options, showTitle, contributors } = params;
7841
7841
  const lines = [];
7842
- 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}`;
7843
7843
  if (showTitle) {
7844
7844
  const isNewVersion = !VERSION_REG.test(options.to);
7845
7845
  const version = isNewVersion ? options.newVersion : options.to;
@@ -7931,8 +7931,10 @@ function createDefaultOptions() {
7931
7931
  ci: { title: "\u{1F916} CI" }
7932
7932
  },
7933
7933
  scopeMap: {},
7934
- github: "",
7935
- githubToken: process.env.GITHUB_TOKEN || "",
7934
+ github: {
7935
+ repo: "",
7936
+ token: process.env.GITHUB_TOKEN || ""
7937
+ },
7936
7938
  from: "",
7937
7939
  to: "",
7938
7940
  tags: [],
@@ -7965,20 +7967,14 @@ async function getOptionsFromPkg(cwd) {
7965
7967
  };
7966
7968
  }
7967
7969
  async function initOptions() {
7970
+ var _a;
7968
7971
  const options = createDefaultOptions();
7969
7972
  const { githubToken, newVersion } = await getOptionsFromPkg(options.cwd);
7970
- if (!options.githubToken) {
7971
- options.githubToken = githubToken;
7972
- }
7973
- if (newVersion) {
7974
- options.newVersion = `v${newVersion}`;
7975
- }
7976
- if (!options.from) {
7977
- options.from = await getLastGitTag();
7978
- }
7979
- if (!options.to) {
7980
- options.to = await getCurrentGitBranch();
7981
- }
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());
7982
7978
  if (options.to === options.from) {
7983
7979
  const lastTag = await getLastGitTag(-1);
7984
7980
  const firstCommit = await getFirstGitCommit();
@@ -7986,17 +7982,12 @@ async function initOptions() {
7986
7982
  }
7987
7983
  options.tags = await getTotalGitTags();
7988
7984
  options.tagDateMap = await getTagDateMap();
7989
- options.github = await getGitHubRepo();
7990
7985
  options.prerelease = isPrerelease(options.to);
7991
7986
  return options;
7992
7987
  }
7993
7988
  async function generateChangelogByTag(options) {
7994
7989
  const gitCommits = await getGitCommits(options.from, options.to, options.scopeMap);
7995
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7996
- gitCommits,
7997
- options.github,
7998
- options.githubToken
7999
- );
7990
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github);
8000
7991
  const md = generateMarkdown({ commits, options, showTitle: true, contributors });
8001
7992
  return md;
8002
7993
  }
@@ -8006,21 +7997,16 @@ async function generateChangelogByTags(options) {
8006
7997
  bar.start(tags.length, 0);
8007
7998
  let md = "";
8008
7999
  const resolvedLogins = /* @__PURE__ */ new Map();
8009
- for (let i = 0; i < tags.length; i += 1) {
8010
- const { from, to } = tags[i];
8000
+ for await (const [index, tag] of tags.entries()) {
8001
+ const { from, to } = tag;
8011
8002
  const gitCommits = await getGitCommits(from, to, options.scopeMap);
8012
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
8013
- gitCommits,
8014
- options.github,
8015
- options.githubToken,
8016
- resolvedLogins
8017
- );
8003
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github, resolvedLogins);
8018
8004
  const opts = { ...options, from, to };
8019
8005
  const nextMd = generateMarkdown({ commits, options: opts, showTitle: true, contributors });
8020
8006
  md = `${nextMd}
8021
8007
 
8022
8008
  ${md}`;
8023
- bar.update(i + 1);
8009
+ bar.update(index + 1);
8024
8010
  }
8025
8011
  bar.stop();
8026
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.1";
20
+ const version = "0.5.2";
21
21
 
22
22
  async function execCommand(cmd, args, options) {
23
23
  const { execa } = await import('execa');
@@ -7645,8 +7645,7 @@ function getHeaders(githubToken) {
7645
7645
  authorization: `token ${githubToken}`
7646
7646
  };
7647
7647
  }
7648
- async function getResolvedAuthorLogin(params) {
7649
- const { github, githubToken, commitHashes, email } = params;
7648
+ async function getResolvedAuthorLogin(github, commitHashes, email) {
7650
7649
  let login = "";
7651
7650
  try {
7652
7651
  const data = await ofetch(`https://ungh.cc/users/find/${email}`);
@@ -7656,13 +7655,14 @@ async function getResolvedAuthorLogin(params) {
7656
7655
  if (login) {
7657
7656
  return login;
7658
7657
  }
7659
- if (!githubToken) {
7658
+ const { repo, token } = github;
7659
+ if (!token) {
7660
7660
  return login;
7661
7661
  }
7662
7662
  if (commitHashes.length) {
7663
7663
  try {
7664
- const data = await ofetch(`https://api.github.com/repos/${github}/commits/${commitHashes[0]}`, {
7665
- headers: getHeaders(githubToken)
7664
+ const data = await ofetch(`https://api.github.com/repos/${repo}/commits/${commitHashes[0]}`, {
7665
+ headers: getHeaders(token)
7666
7666
  });
7667
7667
  login = data?.author?.login || "";
7668
7668
  } catch (e) {
@@ -7673,19 +7673,19 @@ async function getResolvedAuthorLogin(params) {
7673
7673
  }
7674
7674
  try {
7675
7675
  const data = await ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(email)}`, {
7676
- headers: getHeaders(githubToken)
7676
+ headers: getHeaders(token)
7677
7677
  });
7678
7678
  login = data.items[0].login;
7679
7679
  } catch (e) {
7680
7680
  }
7681
7681
  return login;
7682
7682
  }
7683
- async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, resolvedLogins) {
7683
+ async function getGitCommitsAndResolvedAuthors(commits, github, resolvedLogins) {
7684
7684
  const resultCommits = [];
7685
7685
  const map = /* @__PURE__ */ new Map();
7686
- for (const commit of commits) {
7686
+ for await (const commit of commits) {
7687
7687
  const resolvedAuthors = [];
7688
- for (const [index, author] of Object.entries(commit.authors)) {
7688
+ for await (const [index, author] of Object.entries(commit.authors)) {
7689
7689
  const { email, name } = author;
7690
7690
  if (email && name) {
7691
7691
  const commitHashes = [];
@@ -7699,7 +7699,7 @@ async function getGitCommitsAndResolvedAuthors(commits, github, githubToken, res
7699
7699
  login: ""
7700
7700
  };
7701
7701
  if (!resolvedLogins?.has(email)) {
7702
- const login = await getResolvedAuthorLogin({ github, githubToken, commitHashes, email });
7702
+ const login = await getResolvedAuthorLogin(github, commitHashes, email);
7703
7703
  resolvedAuthor.login = login;
7704
7704
  resolvedLogins?.set(email, login);
7705
7705
  } else {
@@ -7739,8 +7739,8 @@ function formatReferences(references, github, type) {
7739
7739
  return referencesString;
7740
7740
  }
7741
7741
  function formatLine(commit, options) {
7742
- const prRefs = formatReferences(commit.references, options.github, "issues");
7743
- 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");
7744
7744
  let authors = join([...new Set(commit.resolvedAuthors.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))]).trim();
7745
7745
  if (authors) {
7746
7746
  authors = `by ${authors}`;
@@ -7814,7 +7814,7 @@ ${unloginLine}`;
7814
7814
  function generateMarkdown(params) {
7815
7815
  const { commits, options, showTitle, contributors } = params;
7816
7816
  const lines = [];
7817
- 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}`;
7818
7818
  if (showTitle) {
7819
7819
  const isNewVersion = !VERSION_REG.test(options.to);
7820
7820
  const version = isNewVersion ? options.newVersion : options.to;
@@ -7906,8 +7906,10 @@ function createDefaultOptions() {
7906
7906
  ci: { title: "\u{1F916} CI" }
7907
7907
  },
7908
7908
  scopeMap: {},
7909
- github: "",
7910
- githubToken: process.env.GITHUB_TOKEN || "",
7909
+ github: {
7910
+ repo: "",
7911
+ token: process.env.GITHUB_TOKEN || ""
7912
+ },
7911
7913
  from: "",
7912
7914
  to: "",
7913
7915
  tags: [],
@@ -7940,20 +7942,14 @@ async function getOptionsFromPkg(cwd) {
7940
7942
  };
7941
7943
  }
7942
7944
  async function initOptions() {
7945
+ var _a;
7943
7946
  const options = createDefaultOptions();
7944
7947
  const { githubToken, newVersion } = await getOptionsFromPkg(options.cwd);
7945
- if (!options.githubToken) {
7946
- options.githubToken = githubToken;
7947
- }
7948
- if (newVersion) {
7949
- options.newVersion = `v${newVersion}`;
7950
- }
7951
- if (!options.from) {
7952
- options.from = await getLastGitTag();
7953
- }
7954
- if (!options.to) {
7955
- options.to = await getCurrentGitBranch();
7956
- }
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());
7957
7953
  if (options.to === options.from) {
7958
7954
  const lastTag = await getLastGitTag(-1);
7959
7955
  const firstCommit = await getFirstGitCommit();
@@ -7961,17 +7957,12 @@ async function initOptions() {
7961
7957
  }
7962
7958
  options.tags = await getTotalGitTags();
7963
7959
  options.tagDateMap = await getTagDateMap();
7964
- options.github = await getGitHubRepo();
7965
7960
  options.prerelease = isPrerelease(options.to);
7966
7961
  return options;
7967
7962
  }
7968
7963
  async function generateChangelogByTag(options) {
7969
7964
  const gitCommits = await getGitCommits(options.from, options.to, options.scopeMap);
7970
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7971
- gitCommits,
7972
- options.github,
7973
- options.githubToken
7974
- );
7965
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github);
7975
7966
  const md = generateMarkdown({ commits, options, showTitle: true, contributors });
7976
7967
  return md;
7977
7968
  }
@@ -7981,21 +7972,16 @@ async function generateChangelogByTags(options) {
7981
7972
  bar.start(tags.length, 0);
7982
7973
  let md = "";
7983
7974
  const resolvedLogins = /* @__PURE__ */ new Map();
7984
- for (let i = 0; i < tags.length; i += 1) {
7985
- const { from, to } = tags[i];
7975
+ for await (const [index, tag] of tags.entries()) {
7976
+ const { from, to } = tag;
7986
7977
  const gitCommits = await getGitCommits(from, to, options.scopeMap);
7987
- const { commits, contributors } = await getGitCommitsAndResolvedAuthors(
7988
- gitCommits,
7989
- options.github,
7990
- options.githubToken,
7991
- resolvedLogins
7992
- );
7978
+ const { commits, contributors } = await getGitCommitsAndResolvedAuthors(gitCommits, options.github, resolvedLogins);
7993
7979
  const opts = { ...options, from, to };
7994
7980
  const nextMd = generateMarkdown({ commits, options: opts, showTitle: true, contributors });
7995
7981
  md = `${nextMd}
7996
7982
 
7997
7983
  ${md}`;
7998
- bar.update(i + 1);
7984
+ bar.update(index + 1);
7999
7985
  }
8000
7986
  bar.stop();
8001
7987
  return md;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soybeanjs/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "SoybeanJS's command line tools",
5
5
  "author": {
6
6
  "name": "Soybean",