@pubinfo/commitlint 2.0.8-beta.1 → 2.0.8-beta.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.d.ts CHANGED
@@ -20,7 +20,7 @@ declare function createGitMessage(rootPath?: string): boolean;
20
20
  declare function runGitMessage(rootPath?: string): boolean;
21
21
  //#endregion
22
22
  //#region src/init/simple.git.hook.d.ts
23
- declare function runSimpleGitHooks(script?: string, cwd?: string): boolean;
23
+ declare function runSimpleGitHooks(script?: string, cwd?: string, enabled?: boolean): boolean;
24
24
  declare function runNpx(cwd?: string): boolean;
25
25
  //#endregion
26
26
  //#region src/prompt/index.d.ts
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-BDa4KShI.js";
1
+ import { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-qcqvSiOT.js";
2
2
 
3
3
  export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
@@ -2286,17 +2286,36 @@ function runGitMessage(rootPath = process$1.cwd()) {
2286
2286
  //#endregion
2287
2287
  //#region src/init/simple.git.hook.ts
2288
2288
  var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
2289
- function runSimpleGitHooks(script = "pubinfo-commit", cwd$1 = process$1.cwd()) {
2289
+ function runSimpleGitHooks(script = "pubinfo-commit", cwd$1 = process$1.cwd(), enabled = true) {
2290
2290
  const pkgPath = resolve(cwd$1, "package.json");
2291
2291
  if (!import_lib.default.existsSync(pkgPath)) return false;
2292
2292
  try {
2293
2293
  const raw = import_lib.default.readFileSync(pkgPath, "utf8");
2294
2294
  const json = JSON.parse(raw);
2295
- json["simple-git-hooks"] = json["simple-git-hooks"] || {};
2295
+ const hooks = json["simple-git-hooks"] || {};
2296
2296
  const desiredPre = "pnpm lint-staged";
2297
- if (json["simple-git-hooks"]["pre-commit"] !== desiredPre) json["simple-git-hooks"]["pre-commit"] = desiredPre;
2298
2297
  const desiredCommitMsg = `pnpm exec ${script} --edit $1`;
2299
- if (json["simple-git-hooks"]["commit-msg"] !== desiredCommitMsg) json["simple-git-hooks"]["commit-msg"] = desiredCommitMsg;
2298
+ if (!enabled) {
2299
+ let changed = false;
2300
+ if (hooks["pre-commit"] === desiredPre) {
2301
+ delete hooks["pre-commit"];
2302
+ changed = true;
2303
+ }
2304
+ if (hooks["commit-msg"] === desiredCommitMsg) {
2305
+ delete hooks["commit-msg"];
2306
+ changed = true;
2307
+ }
2308
+ if (!Object.keys(hooks).length && json["simple-git-hooks"]) {
2309
+ delete json["simple-git-hooks"];
2310
+ changed = true;
2311
+ } else if (changed) json["simple-git-hooks"] = hooks;
2312
+ if (changed) import_lib.default.writeFileSync(pkgPath, `${JSON.stringify(json, null, 2)}\n`, "utf8");
2313
+ return changed;
2314
+ }
2315
+ json["simple-git-hooks"] = hooks;
2316
+ if (hooks["pre-commit"] !== desiredPre) hooks["pre-commit"] = desiredPre;
2317
+ if (hooks["commit-msg"] !== desiredCommitMsg) hooks["commit-msg"] = desiredCommitMsg;
2318
+ json["simple-git-hooks"] = hooks;
2300
2319
  import_lib.default.writeFileSync(pkgPath, `${JSON.stringify(json, null, 2)}\n`, "utf8");
2301
2320
  return true;
2302
2321
  } catch {
package/dist/run.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createCzConfig, createGitMessage, isInsideGitRepo, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-BDa4KShI.js";
1
+ import { createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-qcqvSiOT.js";
2
2
  import process from "node:process";
3
3
  import fs from "node:fs";
4
4
  import { defineCommand, runMain as runMain$1 } from "citty";
@@ -6,7 +6,7 @@ import { defineCommand, runMain as runMain$1 } from "citty";
6
6
  //#region package.json
7
7
  var name = "@pubinfo/commitlint";
8
8
  var type = "module";
9
- var version = "2.0.8-beta.1";
9
+ var version = "2.0.8-beta.2";
10
10
  var description = "commitlint config for Pubinfo projects";
11
11
  var exports = { ".": "./dist/index.js" };
12
12
  var main$1 = "./dist/index.js";
@@ -74,12 +74,23 @@ const main = defineCommand({
74
74
  },
75
75
  run: async ({ args }) => {
76
76
  const { edit, init } = args;
77
+ const enabled = await isCommitlintEnabled();
77
78
  if (!isInsideGitRepo()) {
78
79
  console.error("[pubinfo-commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
79
80
  return;
80
81
  }
81
82
  if (init) {
82
- const pubinfoDir = `${process.cwd()}/.pubinfo`;
83
+ const cwd = process.cwd();
84
+ if (!enabled) {
85
+ const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
86
+ const removedCli = runSimpleGitHooks("pubinfo commit", cwd, false);
87
+ if (removedDefault || removedCli) {
88
+ runNpx(cwd);
89
+ console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已清理 simple-git-hooks 配置。");
90
+ } else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
91
+ return;
92
+ }
93
+ const pubinfoDir = `${cwd}/.pubinfo`;
83
94
  if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
84
95
  const gitMessageStatus = createGitMessage();
85
96
  const czConfigStatus = createCzConfig(pubinfoDir);
@@ -97,6 +108,7 @@ const main = defineCommand({
97
108
  return;
98
109
  }
99
110
  if (edit) {
111
+ if (!enabled) return;
100
112
  try {
101
113
  const raw = fs.readFileSync(String(edit), "utf8").trim();
102
114
  if (!raw) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pubinfo/commitlint",
3
3
  "type": "module",
4
- "version": "2.0.8-beta.1",
4
+ "version": "2.0.8-beta.2",
5
5
  "description": "commitlint config for Pubinfo projects",
6
6
  "exports": {
7
7
  ".": "./dist/index.js"