zixulu 1.79.1 → 1.79.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.js CHANGED
@@ -1727,8 +1727,90 @@ main()
1727
1727
  });
1728
1728
  return getCommitMessage("feature", "添加同步包脚本");
1729
1729
  }
1730
+ const regexPlaceholders = [
1731
+ {
1732
+ token: "__SPACE__",
1733
+ value: " "
1734
+ },
1735
+ {
1736
+ token: "__CARET__",
1737
+ value: "^"
1738
+ },
1739
+ {
1740
+ token: "__DOLLAR__",
1741
+ value: "$"
1742
+ },
1743
+ {
1744
+ token: "__PIPE__",
1745
+ value: "|"
1746
+ },
1747
+ {
1748
+ token: "__AMPERSAND__",
1749
+ value: "&"
1750
+ },
1751
+ {
1752
+ token: "__SEMICOLON__",
1753
+ value: ";"
1754
+ },
1755
+ {
1756
+ token: "__LPAREN__",
1757
+ value: "("
1758
+ },
1759
+ {
1760
+ token: "__RPAREN__",
1761
+ value: ")"
1762
+ },
1763
+ {
1764
+ token: "__LBRACE__",
1765
+ value: "{"
1766
+ },
1767
+ {
1768
+ token: "__RBRACE__",
1769
+ value: "}"
1770
+ },
1771
+ {
1772
+ token: "__LBRACKET__",
1773
+ value: "["
1774
+ },
1775
+ {
1776
+ token: "__RBRACKET__",
1777
+ value: "]"
1778
+ },
1779
+ {
1780
+ token: "__SQUOTE__",
1781
+ value: "'"
1782
+ },
1783
+ {
1784
+ token: "__DQUOTE__",
1785
+ value: '"'
1786
+ },
1787
+ {
1788
+ token: "__BACKTICK__",
1789
+ value: "`"
1790
+ },
1791
+ {
1792
+ token: "__AT__",
1793
+ value: "@"
1794
+ },
1795
+ {
1796
+ token: "__LT__",
1797
+ value: "<"
1798
+ },
1799
+ {
1800
+ token: "__GT__",
1801
+ value: ">"
1802
+ },
1803
+ {
1804
+ token: "__BACKSLASH__",
1805
+ value: "\\"
1806
+ }
1807
+ ];
1808
+ const regexPlaceholderHint = "特殊字符请使用 __XXX__ 占位符,例如 __CARET__、__DOLLAR__、__PIPE__、__LPAREN__、__RPAREN__、__AMPERSAND__、__SPACE__";
1809
+ function preprocessPlaceholderText(text) {
1810
+ return regexPlaceholders.reduce((result, placeholder)=>result.split(placeholder.token).join(placeholder.value), text);
1811
+ }
1730
1812
  function preprocessRegex(reg) {
1731
- return reg.replace(/\{\{CARET\}\}/g, "^");
1813
+ return preprocessPlaceholderText(reg);
1732
1814
  }
1733
1815
  async function addTag({ reg, flags, replacement, push, remote = "origin", force }) {
1734
1816
  const git = simpleGit();
@@ -1737,8 +1819,9 @@ async function addTag({ reg, flags, replacement, push, remote = "origin", force
1737
1819
  const status = await git.status();
1738
1820
  if (status.files.length > 0) return void external_consola_consola.error("当前 Git 仓库存在未提交的文件,请先提交或暂存这些文件");
1739
1821
  const processedReg = preprocessRegex(reg);
1822
+ const processedReplacement = preprocessPlaceholderText(replacement);
1740
1823
  external_consola_consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
1741
- external_consola_consola.info(`替换字符串: ${replacement}`);
1824
+ external_consola_consola.info(`替换字符串: ${processedReplacement}`);
1742
1825
  const cont = await shouldContinue("是否继续?");
1743
1826
  if (!cont) return void external_consola_consola.info("操作已取消");
1744
1827
  const log = await git.log();
@@ -1751,7 +1834,7 @@ async function addTag({ reg, flags, replacement, push, remote = "origin", force
1751
1834
  for (const commit of commits){
1752
1835
  const regexp = new RegExp(processedReg, flags);
1753
1836
  if (regexp.test(commit.message)) {
1754
- const tagName = commit.message.replace(new RegExp(processedReg, flags), replacement);
1837
+ const tagName = commit.message.replace(new RegExp(processedReg, flags), processedReplacement);
1755
1838
  if (tagName && tagName.trim()) tagsToAdd.push({
1756
1839
  hash: commit.hash,
1757
1840
  message: commit.message,
@@ -3623,10 +3706,11 @@ async function replaceCommitMessage({ reg, replace, flags, push, remote = "origi
3623
3706
  "HEAD"
3624
3707
  ]);
3625
3708
  const processedReg = preprocessRegex(reg);
3709
+ const processedReplace = preprocessPlaceholderText(replace);
3626
3710
  external_consola_consola.warn("⚠️ 警告:此操作将重写 Git 历史,建议先备份");
3627
3711
  external_consola_consola.info(`目标分支: ${currentBranch}`);
3628
3712
  external_consola_consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
3629
- external_consola_consola.info(`替换字符串: ${replace}`);
3713
+ external_consola_consola.info(`替换字符串: ${processedReplace}`);
3630
3714
  const cont = await shouldContinue("⚠️ 是否继续?此操作将重写 Git 历史");
3631
3715
  if (!cont) return void external_consola_consola.info("操作已取消");
3632
3716
  const logResult = await git.log([
@@ -3637,7 +3721,7 @@ async function replaceCommitMessage({ reg, replace, flags, push, remote = "origi
3637
3721
  const tempScriptPath = join(tmpdir(), `git-msg-filter-${Date.now()}.js`);
3638
3722
  const scriptContent = `
3639
3723
  const reg = ${JSON.stringify(processedReg)}
3640
- const replace = ${JSON.stringify(replace)}
3724
+ const replace = ${JSON.stringify(processedReplace)}
3641
3725
  const flags = ${JSON.stringify(flags ?? "")}
3642
3726
 
3643
3727
  let input = ""
@@ -3698,8 +3782,9 @@ async function replaceTag({ reg, replace, flags, push, remote = "origin" }) {
3698
3782
  const status = await git.status();
3699
3783
  if (status.files.length > 0) return void external_consola_consola.error("当前 Git 仓库存在未提交的文件,请先提交或暂存这些文件");
3700
3784
  const processedReg = preprocessRegex(reg);
3785
+ const processedReplace = preprocessPlaceholderText(replace);
3701
3786
  external_consola_consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
3702
- external_consola_consola.info(`替换字符串: ${replace}`);
3787
+ external_consola_consola.info(`替换字符串: ${processedReplace}`);
3703
3788
  const cont = await shouldContinue("是否继续?");
3704
3789
  if (!cont) return void external_consola_consola.info("操作已取消");
3705
3790
  const tags = await git.tags();
@@ -3709,7 +3794,7 @@ async function replaceTag({ reg, replace, flags, push, remote = "origin" }) {
3709
3794
  const operations = [];
3710
3795
  for (const tag of allTags){
3711
3796
  const regexp = new RegExp(processedReg, flags);
3712
- const newTag = tag.replace(regexp, replace);
3797
+ const newTag = tag.replace(regexp, processedReplace);
3713
3798
  if (newTag !== tag) operations.push({
3714
3799
  oldTag: tag,
3715
3800
  newTag
@@ -6088,7 +6173,7 @@ program.command("sync-cursor-ext-to-code").alias("sce2c").description("同步 cu
6088
6173
  program.command("create-prisma-debugger").alias("cpd").description("创建 prisma 调试器").action(createPrismaDebugger);
6089
6174
  program.command("verdaccio").description("同步 verdaccio 配置").action(verdaccio);
6090
6175
  program.command("sync-agent-rules").alias("sar").description("同步 Agent 规则").action(actionWithBackup(asyncAgentRules));
6091
- program.command("replace-tag").alias("rt").description("替换所有 git tag (正则中可用 {{CARET}} 代替 ^)").argument("regexp", "正则表达式字符串").argument("[replace]", "替换字符串,默认为空字符串").option("-f, --flags <flags>", "正则表达式标志,如 i、g、m 等").option("-p, --push", "是否推送到远程仓库").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").action(async (regexp, replace, options)=>{
6176
+ program.command("replace-tag").alias("rt").description(`替换所有 git tag (${regexPlaceholderHint})`).argument("regexp", "正则表达式字符串").argument("[replace]", "替换字符串,默认为空字符串").option("-f, --flags <flags>", "正则表达式标志,如 i、g、m 等").option("-p, --push", "是否推送到远程仓库").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").action(async (regexp, replace, options)=>{
6092
6177
  await replaceTag({
6093
6178
  reg: regexp,
6094
6179
  replace: replace ?? "",
@@ -6097,7 +6182,7 @@ program.command("replace-tag").alias("rt").description("替换所有 git tag (
6097
6182
  remote: options.remote
6098
6183
  });
6099
6184
  });
6100
- program.command("remove-tag").alias("rmt").description("删除匹配的 git tag (正则中可用 {{CARET}} 代替 ^)").argument("regexp", "正则表达式字符串").option("-f, --flags <flags>", "正则表达式标志,如 i、g、m 等").option("-p, --push", "是否同时删除远程仓库的 tag").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").action(async (regexp, options)=>{
6185
+ program.command("remove-tag").alias("rmt").description(`删除匹配的 git tag (${regexPlaceholderHint})`).argument("regexp", "正则表达式字符串").option("-f, --flags <flags>", "正则表达式标志,如 i、g、m 等").option("-p, --push", "是否同时删除远程仓库的 tag").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").action(async (regexp, options)=>{
6101
6186
  await removeTag({
6102
6187
  reg: regexp,
6103
6188
  flags: options.flags,
@@ -6105,7 +6190,7 @@ program.command("remove-tag").alias("rmt").description("删除匹配的 git tag
6105
6190
  remote: options.remote
6106
6191
  });
6107
6192
  });
6108
- program.command("add-tag").alias("adt").description("为匹配的 commit 添加 git tag (正则中可用 {{CARET}} 代替 ^)").argument("regexp", "用于匹配 commit message 的正则表达式字符串").argument("replacement", "用于生成 tag 名称的替换字符串").option("-f, --flags <flags>", "正则表达式标志,如 i、g、m 等").option("-p, --push", "是否推送到远程仓库").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").option("--force", "是否覆盖已存在的 tag").action(async (regexp, replacement, options)=>{
6193
+ program.command("add-tag").alias("adt").description(`为匹配的 commit 添加 git tag (${regexPlaceholderHint})`).argument("regexp", "用于匹配 commit message 的正则表达式字符串").argument("replacement", "用于生成 tag 名称的替换字符串").option("-f, --flags <flags>", "正则表达式标志,如 i、g、m 等").option("-p, --push", "是否推送到远程仓库").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").option("--force", "是否覆盖已存在的 tag").action(async (regexp, replacement, options)=>{
6109
6194
  await addTag({
6110
6195
  reg: regexp,
6111
6196
  replacement,
@@ -6115,7 +6200,7 @@ program.command("add-tag").alias("adt").description("为匹配的 commit 添加
6115
6200
  force: options.force
6116
6201
  });
6117
6202
  });
6118
- program.command("replace-commit-message").alias("rcm").description("替换所有提交消息(⚠️ 会重写 Git 历史,正则中可用 {{CARET}} 代替 ^)").argument("regexp", "正则表达式字符串").argument("[replace]", "替换字符串,默认为空字符串").option("-f, --flags <flags>", "正则表达式标志,如 g、i 等(注意:sed 语法)").option("-p, --push", "是否强制推送到远程仓库").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").option("-b, --branch <branch>", "分支名称,默认为当前分支").action(async (regexp, replace, options)=>{
6203
+ program.command("replace-commit-message").alias("rcm").description(`替换所有提交消息(⚠️ 会重写 Git 历史,${regexPlaceholderHint})`).argument("regexp", "正则表达式字符串").argument("[replace]", "替换字符串,默认为空字符串").option("-f, --flags <flags>", "正则表达式标志,如 g、i 等(注意:sed 语法)").option("-p, --push", "是否强制推送到远程仓库").option("-r, --remote <remote>", "远程仓库名称,默认为 origin").option("-b, --branch <branch>", "分支名称,默认为当前分支").action(async (regexp, replace, options)=>{
6119
6204
  await replaceCommitMessage({
6120
6205
  reg: regexp,
6121
6206
  replace: replace ?? "",