@zjex/git-workflow 0.2.24 → 0.3.0

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.
Files changed (92) hide show
  1. package/.github/workflows/deploy-docs.yml +68 -0
  2. package/.github/workflows/test.yml +24 -4
  3. package/.husky/pre-commit +14 -0
  4. package/README.md +72 -1066
  5. package/dist/index.js +103 -13
  6. package/docs/.vitepress/cache/deps/_metadata.json +52 -0
  7. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js +9719 -0
  8. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js.map +7 -0
  9. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js +12824 -0
  10. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js.map +7 -0
  11. package/docs/.vitepress/cache/deps/package.json +3 -0
  12. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
  13. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  14. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
  15. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  16. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  17. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  18. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1665 -0
  19. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  20. package/docs/.vitepress/cache/deps/vitepress___minisearch.js +1813 -0
  21. package/docs/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
  22. package/docs/.vitepress/cache/deps/vue.js +347 -0
  23. package/docs/.vitepress/cache/deps/vue.js.map +7 -0
  24. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js +9719 -0
  25. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js.map +7 -0
  26. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js +12824 -0
  27. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js.map +7 -0
  28. package/docs/.vitepress/cache/deps_temp_44e2fb0f/package.json +3 -0
  29. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js +4505 -0
  30. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js.map +7 -0
  31. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js +583 -0
  32. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js.map +7 -0
  33. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  34. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  35. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js +1665 -0
  36. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  37. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js +1813 -0
  38. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js.map +7 -0
  39. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js +347 -0
  40. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js.map +7 -0
  41. package/docs/.vitepress/config.ts +167 -0
  42. package/docs/.vitepress/theme/custom.css +39 -0
  43. package/docs/.vitepress/theme/index.ts +4 -0
  44. package/docs/README.md +82 -0
  45. package/docs/commands/branch.md +468 -0
  46. package/docs/commands/commit.md +554 -0
  47. package/docs/commands/config.md +346 -0
  48. package/docs/commands/index.md +312 -0
  49. package/docs/commands/interactive.md +384 -0
  50. package/docs/commands/release.md +300 -0
  51. package/docs/commands/stash.md +309 -0
  52. package/docs/commands/tag.md +278 -0
  53. package/docs/commands/update.md +347 -0
  54. package/docs/config/ai-config.md +160 -0
  55. package/docs/config/branch-config.md +133 -0
  56. package/docs/config/commit-config.md +185 -0
  57. package/docs/config/config-file.md +776 -0
  58. package/docs/config/examples.md +279 -0
  59. package/docs/config/index.md +478 -0
  60. package/docs/guide/ai-commit.md +576 -0
  61. package/docs/guide/basic-usage.md +522 -0
  62. package/docs/guide/best-practices.md +426 -0
  63. package/docs/guide/branch-management.md +712 -0
  64. package/docs/guide/getting-started.md +294 -0
  65. package/docs/guide/index.md +168 -0
  66. package/docs/guide/installation.md +449 -0
  67. package/docs/guide/release-management.md +744 -0
  68. package/docs/guide/stash-management.md +608 -0
  69. package/docs/guide/tag-management.md +614 -0
  70. package/docs/index.md +205 -0
  71. package/docs/public/favicon.svg +21 -0
  72. package/docs/public/hero-logo.svg +43 -0
  73. package/docs/public/logo.svg +20 -0
  74. package/package.json +11 -2
  75. package/scripts/publish.js +55 -8
  76. package/scripts/publish.sh +20 -2
  77. package/scripts/release.sh +20 -2
  78. package/scripts/update-test-count.js +55 -0
  79. package/src/ai-service.ts +101 -15
  80. package/src/commands/init.ts +18 -0
  81. package/src/config.ts +1 -0
  82. package/tests/ai-service.test.ts +237 -2
  83. package/tests/help.test.ts +134 -0
  84. package/tests/init.test.ts +582 -0
  85. package/tests/release.test.ts +333 -0
  86. package/tests/setup.ts +21 -0
  87. package/tests/stash.test.ts +376 -0
  88. package/tests/update.test.ts +402 -0
  89. package/vitest.config.ts +3 -0
  90. package/zjex-logo.svg +22 -0
  91. package/zjex-optimized.svg +34 -0
  92. package/zjex.svg +1 -0
package/dist/index.js CHANGED
@@ -1442,11 +1442,28 @@ async function init() {
1442
1442
  ],
1443
1443
  theme
1444
1444
  });
1445
+ const detailedDescription = await select4({
1446
+ message: "\u662F\u5426\u751F\u6210\u8BE6\u7EC6\u7684\u4FEE\u6539\u70B9\u63CF\u8FF0?",
1447
+ choices: [
1448
+ {
1449
+ name: "\u662F\uFF08\u5305\u542B\u4FEE\u6539\u70B9\u5217\u8868\uFF0C\u63A8\u8350\uFF09",
1450
+ value: true,
1451
+ description: "\u5982\uFF1Afeat(auth): \u6DFB\u52A0\u7528\u6237\u767B\u5F55\u529F\u80FD\n\n- \u5B9E\u73B0\u7528\u6237\u540D\u5BC6\u7801\u767B\u5F55\u63A5\u53E3\n- \u6DFB\u52A0\u767B\u5F55\u72B6\u6001\u9A8C\u8BC1\u4E2D\u95F4\u4EF6"
1452
+ },
1453
+ {
1454
+ name: "\u5426\uFF08\u4EC5\u751F\u6210\u6807\u9898\uFF09",
1455
+ value: false,
1456
+ description: "\u5982\uFF1Afeat(auth): \u6DFB\u52A0\u7528\u6237\u767B\u5F55\u529F\u80FD"
1457
+ }
1458
+ ],
1459
+ theme
1460
+ });
1445
1461
  config2.aiCommit = {
1446
1462
  enabled: true,
1447
1463
  provider: aiProvider,
1448
1464
  apiKey: apiKey || void 0,
1449
- language
1465
+ language,
1466
+ detailedDescription
1450
1467
  };
1451
1468
  const defaultModels = {
1452
1469
  github: "gpt-4o-mini",
@@ -1790,9 +1807,62 @@ function getGitDiff() {
1790
1807
  return "";
1791
1808
  }
1792
1809
  }
1793
- function buildPrompt(diff, language) {
1810
+ function buildPrompt(diff, language, detailedDescription = false) {
1794
1811
  const isZh = language === "zh-CN";
1795
- const systemPrompt = isZh ? `\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684 Git commit message \u751F\u6210\u52A9\u624B\u3002\u8BF7\u6839\u636E\u63D0\u4F9B\u7684 git diff \u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684 commit message\u3002
1812
+ if (detailedDescription) {
1813
+ const systemPrompt = isZh ? `\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684 Git commit message \u751F\u6210\u52A9\u624B\u3002\u8BF7\u6839\u636E\u63D0\u4F9B\u7684 git diff \u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684\u8BE6\u7EC6 commit message\u3002
1814
+
1815
+ \u683C\u5F0F\u8981\u6C42\uFF1A
1816
+ 1. \u7B2C\u4E00\u884C\uFF1A<type>(<scope>): <subject>
1817
+ 2. \u7A7A\u884C
1818
+ 3. \u8BE6\u7EC6\u63CF\u8FF0\uFF1A\u5217\u51FA\u4E3B\u8981\u4FEE\u6539\u70B9\uFF0C\u6BCF\u4E2A\u4FEE\u6539\u70B9\u4E00\u884C\uFF0C\u4EE5 "- " \u5F00\u5934
1819
+
1820
+ \u89C4\u5219\uFF1A
1821
+ - type \u5FC5\u987B\u662F\u4EE5\u4E0B\u4E4B\u4E00\uFF1Afeat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
1822
+ - scope \u662F\u53EF\u9009\u7684\uFF0C\u8868\u793A\u5F71\u54CD\u8303\u56F4
1823
+ - subject \u7528\u4E2D\u6587\u63CF\u8FF0\uFF0C\u7B80\u6D01\u660E\u4E86\uFF0C\u4E0D\u8D85\u8FC7 50 \u5B57
1824
+ - \u8BE6\u7EC6\u63CF\u8FF0\u8981\u5217\u51FA 3-6 \u4E2A\u4E3B\u8981\u4FEE\u6539\u70B9\uFF0C\u6BCF\u4E2A\u4FEE\u6539\u70B9\u7B80\u6D01\u660E\u4E86
1825
+ - \u5982\u679C\u4FEE\u6539\u8F83\u5C11\uFF0C\u53EF\u4EE5\u53EA\u5217\u51FA 2-3 \u4E2A\u4FEE\u6539\u70B9
1826
+ - \u4E0D\u8981\u6709\u5176\u4ED6\u89E3\u91CA\u6216\u591A\u4F59\u5185\u5BB9
1827
+
1828
+ \u793A\u4F8B\uFF1A
1829
+ feat(auth): \u6DFB\u52A0\u7528\u6237\u767B\u5F55\u529F\u80FD
1830
+
1831
+ - \u5B9E\u73B0\u7528\u6237\u540D\u5BC6\u7801\u767B\u5F55\u63A5\u53E3
1832
+ - \u6DFB\u52A0\u767B\u5F55\u72B6\u6001\u9A8C\u8BC1\u4E2D\u95F4\u4EF6
1833
+ - \u5B8C\u5584\u767B\u5F55\u9519\u8BEF\u5904\u7406\u903B\u8F91
1834
+ - \u66F4\u65B0\u7528\u6237\u8BA4\u8BC1\u76F8\u5173\u6587\u6863` : `You are a professional Git commit message generator. Generate a detailed commit message following Conventional Commits specification based on the provided git diff.
1835
+
1836
+ Format requirements:
1837
+ 1. First line: <type>(<scope>): <subject>
1838
+ 2. Empty line
1839
+ 3. Detailed description: List main changes, one per line, starting with "- "
1840
+
1841
+ Rules:
1842
+ - type must be one of: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
1843
+ - scope is optional, indicates the affected area
1844
+ - subject should be concise, no more than 50 characters
1845
+ - Detailed description should list 3-6 main changes, each change should be concise
1846
+ - If changes are minimal, list 2-3 changes
1847
+ - No explanations or extra content
1848
+
1849
+ Example:
1850
+ feat(auth): add user login functionality
1851
+
1852
+ - Implement username/password login API
1853
+ - Add login status validation middleware
1854
+ - Improve login error handling logic
1855
+ - Update user authentication documentation`;
1856
+ const userPrompt = isZh ? `\u8BF7\u6839\u636E\u4EE5\u4E0B git diff \u751F\u6210\u8BE6\u7EC6\u7684 commit message\uFF08\u5305\u542B\u4FEE\u6539\u70B9\u5217\u8868\uFF09\uFF1A
1857
+
1858
+ ${diff}` : `Generate a detailed commit message (including change list) based on the following git diff:
1859
+
1860
+ ${diff}`;
1861
+ return `${systemPrompt}
1862
+
1863
+ ${userPrompt}`;
1864
+ } else {
1865
+ const systemPrompt = isZh ? `\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684 Git commit message \u751F\u6210\u52A9\u624B\u3002\u8BF7\u6839\u636E\u63D0\u4F9B\u7684 git diff \u751F\u6210\u7B26\u5408 Conventional Commits \u89C4\u8303\u7684 commit message\u3002
1796
1866
 
1797
1867
  \u89C4\u5219\uFF1A
1798
1868
  1. \u683C\u5F0F\uFF1A<type>(<scope>): <subject>
@@ -1819,14 +1889,15 @@ Examples:
1819
1889
  - feat(auth): add user login functionality
1820
1890
  - fix(api): resolve data fetching failure
1821
1891
  - docs(readme): update installation guide`;
1822
- const userPrompt = isZh ? `\u8BF7\u6839\u636E\u4EE5\u4E0B git diff \u751F\u6210 commit message\uFF1A
1892
+ const userPrompt = isZh ? `\u8BF7\u6839\u636E\u4EE5\u4E0B git diff \u751F\u6210 commit message\uFF1A
1823
1893
 
1824
1894
  ${diff}` : `Generate a commit message based on the following git diff:
1825
1895
 
1826
1896
  ${diff}`;
1827
- return `${systemPrompt}
1897
+ return `${systemPrompt}
1828
1898
 
1829
1899
  ${userPrompt}`;
1900
+ }
1830
1901
  }
1831
1902
  async function callGitHubAPI(prompt, apiKey, model, maxTokens) {
1832
1903
  const response = await fetch(AI_PROVIDERS.github.endpoint, {
@@ -1921,18 +1992,31 @@ async function callOllamaAPI(prompt, model, maxTokens) {
1921
1992
  );
1922
1993
  }
1923
1994
  }
1995
+ function cleanAIResponse(response) {
1996
+ const lines = response.split("\n").map((line) => line.trim()).filter((line) => line);
1997
+ const uniqueLines = [];
1998
+ const seen = /* @__PURE__ */ new Set();
1999
+ for (const line of lines) {
2000
+ if (!seen.has(line)) {
2001
+ seen.add(line);
2002
+ uniqueLines.push(line);
2003
+ }
2004
+ }
2005
+ return uniqueLines.join("\n");
2006
+ }
1924
2007
  async function generateAICommitMessage(config2) {
1925
2008
  const aiConfig = config2.aiCommit || {};
1926
2009
  const provider = aiConfig.provider || "github";
1927
2010
  const language = aiConfig.language || "zh-CN";
1928
- const maxTokens = aiConfig.maxTokens || 200;
2011
+ const detailedDescription = aiConfig.detailedDescription !== false;
2012
+ const maxTokens = aiConfig.maxTokens || (detailedDescription ? 400 : 200);
1929
2013
  const diff = getGitDiff();
1930
2014
  if (!diff) {
1931
2015
  throw new Error("\u6CA1\u6709\u68C0\u6D4B\u5230\u4EE3\u7801\u66F4\u6539");
1932
2016
  }
1933
- const maxDiffLength = 4e3;
2017
+ const maxDiffLength = detailedDescription ? 6e3 : 4e3;
1934
2018
  const truncatedDiff = diff.length > maxDiffLength ? diff.slice(0, maxDiffLength) + "\n..." : diff;
1935
- const prompt = buildPrompt(truncatedDiff, language);
2019
+ const prompt = buildPrompt(truncatedDiff, language, detailedDescription);
1936
2020
  const providerInfo = AI_PROVIDERS[provider];
1937
2021
  if (!providerInfo) {
1938
2022
  throw new Error(`\u4E0D\u652F\u6301\u7684 AI \u63D0\u4F9B\u5546: ${provider}`);
@@ -1944,18 +2028,24 @@ async function generateAICommitMessage(config2) {
1944
2028
  `${providerInfo.name} \u9700\u8981 API key\u3002\u8BF7\u8FD0\u884C 'gw init' \u914D\u7F6E AI commit\uFF0C\u6216\u5728 .gwrc.json \u4E2D\u8BBE\u7F6E aiCommit.apiKey`
1945
2029
  );
1946
2030
  }
2031
+ let response;
1947
2032
  switch (provider) {
1948
2033
  case "github":
1949
- return await callGitHubAPI(prompt, apiKey, model, maxTokens);
2034
+ response = await callGitHubAPI(prompt, apiKey, model, maxTokens);
2035
+ break;
1950
2036
  case "openai":
1951
- return await callOpenAIAPI(prompt, apiKey, model, maxTokens);
2037
+ response = await callOpenAIAPI(prompt, apiKey, model, maxTokens);
2038
+ break;
1952
2039
  case "claude":
1953
- return await callClaudeAPI(prompt, apiKey, model, maxTokens);
2040
+ response = await callClaudeAPI(prompt, apiKey, model, maxTokens);
2041
+ break;
1954
2042
  case "ollama":
1955
- return await callOllamaAPI(prompt, model, maxTokens);
2043
+ response = await callOllamaAPI(prompt, model, maxTokens);
2044
+ break;
1956
2045
  default:
1957
2046
  throw new Error(`\u4E0D\u652F\u6301\u7684 AI \u63D0\u4F9B\u5546: ${provider}`);
1958
2047
  }
2048
+ return cleanAIResponse(response);
1959
2049
  }
1960
2050
  function isAICommitAvailable(config2) {
1961
2051
  const aiConfig = config2.aiCommit;
@@ -2496,7 +2586,7 @@ process.on("SIGTERM", () => {
2496
2586
  console.log("");
2497
2587
  process.exit(0);
2498
2588
  });
2499
- var version = true ? "0.2.24" : "0.0.0-dev";
2589
+ var version = true ? "0.3.0" : "0.0.0-dev";
2500
2590
  async function mainMenu() {
2501
2591
  console.log(
2502
2592
  colors.green(`
@@ -0,0 +1,52 @@
1
+ {
2
+ "hash": "cb9fc065",
3
+ "configHash": "e91271f8",
4
+ "lockfileHash": "eae41063",
5
+ "browserHash": "fa434d50",
6
+ "optimized": {
7
+ "vue": {
8
+ "src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
9
+ "file": "vue.js",
10
+ "fileHash": "69cff841",
11
+ "needsInterop": false
12
+ },
13
+ "vitepress > @vue/devtools-api": {
14
+ "src": "../../../../node_modules/@vue/devtools-api/dist/index.js",
15
+ "file": "vitepress___@vue_devtools-api.js",
16
+ "fileHash": "5ad8b965",
17
+ "needsInterop": false
18
+ },
19
+ "vitepress > @vueuse/core": {
20
+ "src": "../../../../node_modules/@vueuse/core/index.mjs",
21
+ "file": "vitepress___@vueuse_core.js",
22
+ "fileHash": "9696f0e0",
23
+ "needsInterop": false
24
+ },
25
+ "vitepress > @vueuse/integrations/useFocusTrap": {
26
+ "src": "../../../../node_modules/@vueuse/integrations/useFocusTrap.mjs",
27
+ "file": "vitepress___@vueuse_integrations_useFocusTrap.js",
28
+ "fileHash": "6cc36968",
29
+ "needsInterop": false
30
+ },
31
+ "vitepress > mark.js/src/vanilla.js": {
32
+ "src": "../../../../node_modules/mark.js/src/vanilla.js",
33
+ "file": "vitepress___mark__js_src_vanilla__js.js",
34
+ "fileHash": "08475884",
35
+ "needsInterop": false
36
+ },
37
+ "vitepress > minisearch": {
38
+ "src": "../../../../node_modules/minisearch/dist/es/index.js",
39
+ "file": "vitepress___minisearch.js",
40
+ "fileHash": "1cb3d774",
41
+ "needsInterop": false
42
+ }
43
+ },
44
+ "chunks": {
45
+ "chunk-2CLQ7TTZ": {
46
+ "file": "chunk-2CLQ7TTZ.js"
47
+ },
48
+ "chunk-LE5NDSFD": {
49
+ "file": "chunk-LE5NDSFD.js"
50
+ }
51
+ }
52
+ }