@pubinfo/commitlint 2.0.8-beta.2 → 2.0.8
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
|
@@ -22,6 +22,7 @@ declare function runGitMessage(rootPath?: string): boolean;
|
|
|
22
22
|
//#region src/init/simple.git.hook.d.ts
|
|
23
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 };
|
|
@@ -2287,6 +2287,7 @@ function runGitMessage(rootPath = process$1.cwd()) {
|
|
|
2287
2287
|
//#region src/init/simple.git.hook.ts
|
|
2288
2288
|
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
2289
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 {
|
|
@@ -2295,23 +2296,6 @@ function runSimpleGitHooks(script = "pubinfo-commit", cwd$1 = process$1.cwd(), e
|
|
|
2295
2296
|
const hooks = json["simple-git-hooks"] || {};
|
|
2296
2297
|
const desiredPre = "pnpm lint-staged";
|
|
2297
2298
|
const desiredCommitMsg = `pnpm exec ${script} --edit $1`;
|
|
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
2299
|
json["simple-git-hooks"] = hooks;
|
|
2316
2300
|
if (hooks["pre-commit"] !== desiredPre) hooks["pre-commit"] = desiredPre;
|
|
2317
2301
|
if (hooks["commit-msg"] !== desiredCommitMsg) hooks["commit-msg"] = desiredCommitMsg;
|
|
@@ -2333,6 +2317,24 @@ function runNpx(cwd$1 = process$1.cwd()) {
|
|
|
2333
2317
|
return false;
|
|
2334
2318
|
}
|
|
2335
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
|
+
}
|
|
2336
2338
|
|
|
2337
2339
|
//#endregion
|
|
2338
2340
|
//#region src/prompt/index.ts
|
|
@@ -2402,4 +2404,4 @@ async function lintAndReturn(message) {
|
|
|
2402
2404
|
}
|
|
2403
2405
|
|
|
2404
2406
|
//#endregion
|
|
2405
|
-
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, isCommitlintEnabled, 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
|
|
9
|
+
var version = "2.0.8";
|
|
10
10
|
var description = "commitlint config for Pubinfo projects";
|
|
11
11
|
var exports = { ".": "./dist/index.js" };
|
|
12
12
|
var main$1 = "./dist/index.js";
|
|
@@ -84,12 +84,12 @@ const main = defineCommand({
|
|
|
84
84
|
if (!enabled) {
|
|
85
85
|
const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
|
|
86
86
|
const removedCli = runSimpleGitHooks("pubinfo commit", cwd, false);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
|
|
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,跳过初始化。");
|
|
91
90
|
return;
|
|
92
91
|
}
|
|
92
|
+
configureGitHooksPath(true, cwd);
|
|
93
93
|
const pubinfoDir = `${cwd}/.pubinfo`;
|
|
94
94
|
if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
|
|
95
95
|
const gitMessageStatus = createGitMessage();
|
|
@@ -108,7 +108,10 @@ const main = defineCommand({
|
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
if (edit) {
|
|
111
|
-
if (!enabled)
|
|
111
|
+
if (!enabled) {
|
|
112
|
+
configureGitHooksPath(false, process.cwd());
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
112
115
|
try {
|
|
113
116
|
const raw = fs.readFileSync(String(edit), "utf8").trim();
|
|
114
117
|
if (!raw) {
|
|
@@ -121,6 +124,11 @@ const main = defineCommand({
|
|
|
121
124
|
}
|
|
122
125
|
return;
|
|
123
126
|
}
|
|
127
|
+
if (!enabled) {
|
|
128
|
+
console.log("[pubinfo-commit] commitlint 已关闭,交互模式不可用。");
|
|
129
|
+
configureGitHooksPath(false, process.cwd());
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
124
132
|
const result = await runPrompt();
|
|
125
133
|
if (!result) {
|
|
126
134
|
console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
|