@pubinfo/commitlint 2.1.3-beta.2 → 2.1.4

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
@@ -1,3 +1,3 @@
1
- import { a as configureGitHooksPath, c as createGitMessage, d as runCzConfig, f as isCommitlintEnabled, i as runPrompt, l as runGitMessage, m as loadCommitConfig, n as lintMessage, o as runNpx, p as commitPreset, r as isInsideGitRepo, s as runSimpleGitHooks, t as lintAndReturn, u as createCzConfig } from "./lint.message-Cdip9x5S.js";
1
+ import { a as configureGitHooksPath, c as createGitMessage, d as runCzConfig, f as isCommitlintEnabled, i as runPrompt, l as runGitMessage, m as loadCommitConfig, n as lintMessage, o as runNpx, p as commitPreset, r as isInsideGitRepo, s as runSimpleGitHooks, t as lintAndReturn, u as createCzConfig } from "./lint.message.js";
2
2
 
3
3
  export { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
package/dist/run.js CHANGED
@@ -1,15 +1,23 @@
1
- import { a as configureGitHooksPath, c as createGitMessage, d as runCzConfig, f as isCommitlintEnabled, i as runPrompt, l as runGitMessage, n as lintMessage, o as runNpx, r as isInsideGitRepo, s as runSimpleGitHooks, u as createCzConfig } from "./lint.message-Cdip9x5S.js";
1
+ import { a as configureGitHooksPath, c as createGitMessage, d as runCzConfig, f as isCommitlintEnabled, i as runPrompt, l as runGitMessage, n as lintMessage, o as runNpx, r as isInsideGitRepo, s as runSimpleGitHooks, u as createCzConfig } from "./lint.message.js";
2
+ import { spawnSync } from "node:child_process";
2
3
  import process from "node:process";
3
4
  import fs from "node:fs";
4
5
  import { defineCommand, runMain as runMain$1 } from "citty";
5
6
 
6
7
  //#region package.json
7
8
  var name = "@pubinfo/commitlint";
8
- var version = "2.1.3-beta.2";
9
+ var version = "2.1.4";
9
10
  var description = "commitlint config for Pubinfo projects";
10
11
 
11
12
  //#endregion
12
13
  //#region src/cli.ts
14
+ function isGitRepository() {
15
+ try {
16
+ return spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { stdio: "ignore" }).status === 0;
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
13
21
  /**
14
22
  * 本文件提供 `pubinfo-commit` 可执行入口(由 package.json bin 指向)。
15
23
  * 作用:
@@ -36,68 +44,71 @@ const main = defineCommand({
36
44
  }
37
45
  },
38
46
  run: async ({ args }) => {
39
- const { edit, init } = args;
40
- const enabled = await isCommitlintEnabled();
41
- if (!isInsideGitRepo()) {
42
- console.error("[pubinfo-commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
43
- return;
44
- }
45
- if (init) {
46
- const cwd = process.cwd();
47
- if (!enabled) {
48
- const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
49
- const removedCli = runSimpleGitHooks("pubinfo commit", cwd, false);
50
- const disabledHooks = configureGitHooksPath(false, cwd);
51
- if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
52
- else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
47
+ if (!isGitRepository()) console.error("[pubinfo-commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
48
+ else {
49
+ const { edit, init } = args;
50
+ const enabled = await isCommitlintEnabled();
51
+ if (!isInsideGitRepo()) {
52
+ console.error("[pubinfo-commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
53
53
  return;
54
54
  }
55
- configureGitHooksPath(true, cwd);
56
- const pubinfoDir = `${cwd}/.pubinfo`;
57
- if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
58
- const gitMessageStatus = createGitMessage();
59
- const czConfigStatus = createCzConfig(pubinfoDir);
60
- const gitHookStatus = runGitMessage();
61
- const simpleGitHooks = runSimpleGitHooks();
62
- const czConfig = runCzConfig(".pubinfo/cz.config.cjs");
63
- const npxStatus = runNpx();
64
- console.log("[pubinfo-commit] 初始化结果:");
65
- console.log(`- cz.config.cjs: ${czConfigStatus ? "已创建" : "已存在"}`);
66
- console.log(`- .gitmessage: ${gitMessageStatus ? "已创建" : "已存在"}`);
67
- console.log(`- Git hooks: ${gitHookStatus ? "已写入" : "已存在"}`);
68
- console.log(`- package.json 配置 cz-git: ${czConfig ? "已写入" : "已存在"}`);
69
- console.log(`- package.json 配置 simple-git-hooks: ${simpleGitHooks ? "已写入" : "已存在"}`);
70
- console.log(`- npx simple-git-hooks 安装: ${npxStatus ? "成功" : "失败,请手动安装"}`);
71
- return;
72
- }
73
- if (edit) {
74
- if (!enabled) {
75
- configureGitHooksPath(false, process.cwd());
55
+ if (init) {
56
+ const cwd = process.cwd();
57
+ if (!enabled) {
58
+ const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
59
+ const removedCli = runSimpleGitHooks("pubinfo commit", cwd, false);
60
+ const disabledHooks = configureGitHooksPath(false, cwd);
61
+ if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
62
+ else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
63
+ return;
64
+ }
65
+ configureGitHooksPath(true, cwd);
66
+ const pubinfoDir = `${cwd}/.pubinfo`;
67
+ if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
68
+ const gitMessageStatus = createGitMessage();
69
+ const czConfigStatus = createCzConfig(pubinfoDir);
70
+ const gitHookStatus = runGitMessage();
71
+ const simpleGitHooks = runSimpleGitHooks();
72
+ const czConfig = runCzConfig(".pubinfo/cz.config.cjs");
73
+ const npxStatus = runNpx();
74
+ console.log("[pubinfo-commit] 初始化结果:");
75
+ console.log(`- cz.config.cjs: ${czConfigStatus ? "已创建" : "已存在"}`);
76
+ console.log(`- .gitmessage: ${gitMessageStatus ? "已创建" : "已存在"}`);
77
+ console.log(`- Git hooks: ${gitHookStatus ? "已写入" : "已存在"}`);
78
+ console.log(`- package.json 配置 cz-git: ${czConfig ? "已写入" : "已存在"}`);
79
+ console.log(`- package.json 配置 simple-git-hooks: ${simpleGitHooks ? "已写入" : "已存在"}`);
80
+ console.log(`- npx simple-git-hooks 安装: ${npxStatus ? "成功" : "失败,请手动安装"}`);
76
81
  return;
77
82
  }
78
- try {
79
- const raw = fs.readFileSync(String(edit), "utf8").trim();
80
- if (!raw) {
81
- console.error("[pubinfo-commit] 空的 commit message 文件");
83
+ if (edit) {
84
+ if (!enabled) {
85
+ configureGitHooksPath(false, process.cwd());
82
86
  return;
83
87
  }
84
- await lintMessage(raw);
85
- } catch (e) {
86
- console.error("[pubinfo-commit] 读取 --edit 文件失败", e);
88
+ try {
89
+ const raw = fs.readFileSync(String(edit), "utf8").trim();
90
+ if (!raw) {
91
+ console.error("[pubinfo-commit] 空的 commit message 文件");
92
+ return;
93
+ }
94
+ await lintMessage(raw);
95
+ } catch (e) {
96
+ console.error("[pubinfo-commit] 读取 --edit 文件失败", e);
97
+ }
98
+ return;
87
99
  }
88
- return;
89
- }
90
- if (!enabled) {
91
- console.log("[pubinfo-commit] commitlint 已关闭,交互模式不可用。");
92
- configureGitHooksPath(false, process.cwd());
93
- return;
94
- }
95
- const result = await runPrompt();
96
- if (!result) {
97
- console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
98
- return;
100
+ if (!enabled) {
101
+ console.log("[pubinfo-commit] commitlint 已关闭,交互模式不可用。");
102
+ configureGitHooksPath(false, process.cwd());
103
+ return;
104
+ }
105
+ const result = await runPrompt();
106
+ if (!result) {
107
+ console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
108
+ return;
109
+ }
110
+ await lintMessage(result.raw);
99
111
  }
100
- await lintMessage(result.raw);
101
112
  }
102
113
  });
103
114
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/commitlint",
3
3
  "type": "module",
4
- "version": "2.1.3-beta.2",
4
+ "version": "2.1.4",
5
5
  "description": "commitlint config for Pubinfo projects",
6
6
  "exports": {
7
7
  ".": "./dist/index.js"