@pubinfo/commitlint 2.0.8-beta.1 → 2.0.8-beta.3
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,8 +20,9 @@ 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
|
+
declare function configureGitHooksPath(enabled?: boolean, cwd?: string): boolean;
|
|
25
26
|
//#endregion
|
|
26
27
|
//#region src/prompt/index.d.ts
|
|
27
28
|
interface PromptResult {
|
|
@@ -39,4 +40,4 @@ declare function isInsideGitRepo(): boolean;
|
|
|
39
40
|
declare function lintMessage(message: string): Promise<boolean>;
|
|
40
41
|
declare function lintAndReturn(message: string): Promise<string>;
|
|
41
42
|
//#endregion
|
|
42
|
-
export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
|
|
43
|
+
export { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
|
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-
|
|
1
|
+
import { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-CLvOoZVL.js";
|
|
2
2
|
|
|
3
|
-
export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
|
|
3
|
+
export { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
|
|
@@ -2286,17 +2286,20 @@ 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
|
+
if (!enabled) return false;
|
|
2290
2291
|
const pkgPath = resolve(cwd$1, "package.json");
|
|
2291
2292
|
if (!import_lib.default.existsSync(pkgPath)) return false;
|
|
2292
2293
|
try {
|
|
2293
2294
|
const raw = import_lib.default.readFileSync(pkgPath, "utf8");
|
|
2294
2295
|
const json = JSON.parse(raw);
|
|
2295
|
-
|
|
2296
|
+
const hooks = json["simple-git-hooks"] || {};
|
|
2296
2297
|
const desiredPre = "pnpm lint-staged";
|
|
2297
|
-
if (json["simple-git-hooks"]["pre-commit"] !== desiredPre) json["simple-git-hooks"]["pre-commit"] = desiredPre;
|
|
2298
2298
|
const desiredCommitMsg = `pnpm exec ${script} --edit $1`;
|
|
2299
|
-
|
|
2299
|
+
json["simple-git-hooks"] = hooks;
|
|
2300
|
+
if (hooks["pre-commit"] !== desiredPre) hooks["pre-commit"] = desiredPre;
|
|
2301
|
+
if (hooks["commit-msg"] !== desiredCommitMsg) hooks["commit-msg"] = desiredCommitMsg;
|
|
2302
|
+
json["simple-git-hooks"] = hooks;
|
|
2300
2303
|
import_lib.default.writeFileSync(pkgPath, `${JSON.stringify(json, null, 2)}\n`, "utf8");
|
|
2301
2304
|
return true;
|
|
2302
2305
|
} catch {
|
|
@@ -2314,6 +2317,24 @@ function runNpx(cwd$1 = process$1.cwd()) {
|
|
|
2314
2317
|
return false;
|
|
2315
2318
|
}
|
|
2316
2319
|
}
|
|
2320
|
+
function configureGitHooksPath(enabled = true, cwd$1 = process$1.cwd()) {
|
|
2321
|
+
try {
|
|
2322
|
+
if (enabled) {
|
|
2323
|
+
execSync("git config --unset core.hooksPath", {
|
|
2324
|
+
cwd: cwd$1,
|
|
2325
|
+
stdio: "ignore"
|
|
2326
|
+
});
|
|
2327
|
+
return true;
|
|
2328
|
+
}
|
|
2329
|
+
execSync("git config core.hooksPath /dev/null", {
|
|
2330
|
+
cwd: cwd$1,
|
|
2331
|
+
stdio: "ignore"
|
|
2332
|
+
});
|
|
2333
|
+
return true;
|
|
2334
|
+
} catch {
|
|
2335
|
+
return enabled;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2317
2338
|
|
|
2318
2339
|
//#endregion
|
|
2319
2340
|
//#region src/prompt/index.ts
|
|
@@ -2383,4 +2404,4 @@ async function lintAndReturn(message) {
|
|
|
2383
2404
|
}
|
|
2384
2405
|
|
|
2385
2406
|
//#endregion
|
|
2386
|
-
export { commitPreset, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
|
|
2407
|
+
export { commitPreset, configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintAndReturn, lintMessage, loadCommitConfig, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks };
|
package/dist/run.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCzConfig, createGitMessage, isInsideGitRepo, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-
|
|
1
|
+
import { configureGitHooksPath, createCzConfig, createGitMessage, isCommitlintEnabled, isInsideGitRepo, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-CLvOoZVL.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.
|
|
9
|
+
var version = "2.0.8-beta.3";
|
|
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
|
|
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
|
+
const disabledHooks = configureGitHooksPath(false, cwd);
|
|
88
|
+
if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
|
|
89
|
+
else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
configureGitHooksPath(true, cwd);
|
|
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,10 @@ const main = defineCommand({
|
|
|
97
108
|
return;
|
|
98
109
|
}
|
|
99
110
|
if (edit) {
|
|
111
|
+
if (!enabled) {
|
|
112
|
+
configureGitHooksPath(false, process.cwd());
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
100
115
|
try {
|
|
101
116
|
const raw = fs.readFileSync(String(edit), "utf8").trim();
|
|
102
117
|
if (!raw) {
|
|
@@ -109,6 +124,11 @@ const main = defineCommand({
|
|
|
109
124
|
}
|
|
110
125
|
return;
|
|
111
126
|
}
|
|
127
|
+
if (!enabled) {
|
|
128
|
+
console.log("[pubinfo-commit] commitlint 已关闭,交互模式不可用。");
|
|
129
|
+
configureGitHooksPath(false, process.cwd());
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
112
132
|
const result = await runPrompt();
|
|
113
133
|
if (!result) {
|
|
114
134
|
console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
|