@pubinfo/commitlint 2.1.3 → 2.1.5
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
|
|
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
|
|
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.
|
|
9
|
+
var version = "2.1.5";
|
|
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,67 @@ const main = defineCommand({
|
|
|
36
44
|
}
|
|
37
45
|
},
|
|
38
46
|
run: async ({ args }) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (isGitRepository()) {
|
|
48
|
+
const { edit, init } = args;
|
|
49
|
+
const enabled = await isCommitlintEnabled();
|
|
50
|
+
if (!isInsideGitRepo()) return;
|
|
51
|
+
if (init) {
|
|
52
|
+
const cwd = process.cwd();
|
|
53
|
+
if (!enabled) {
|
|
54
|
+
const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd, false);
|
|
55
|
+
const removedCli = runSimpleGitHooks("pubinfo commit", cwd, false);
|
|
56
|
+
const disabledHooks = configureGitHooksPath(false, cwd);
|
|
57
|
+
if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
|
|
58
|
+
else console.log("[pubinfo-commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
configureGitHooksPath(true, cwd);
|
|
62
|
+
const pubinfoDir = `${cwd}/.pubinfo`;
|
|
63
|
+
if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
|
|
64
|
+
const gitMessageStatus = createGitMessage();
|
|
65
|
+
const czConfigStatus = createCzConfig(pubinfoDir);
|
|
66
|
+
const gitHookStatus = runGitMessage();
|
|
67
|
+
const simpleGitHooks = runSimpleGitHooks();
|
|
68
|
+
const czConfig = runCzConfig(".pubinfo/cz.config.cjs");
|
|
69
|
+
const npxStatus = runNpx();
|
|
70
|
+
console.log("[pubinfo-commit] 初始化结果:");
|
|
71
|
+
console.log(`- cz.config.cjs: ${czConfigStatus ? "已创建" : "已存在"}`);
|
|
72
|
+
console.log(`- .gitmessage: ${gitMessageStatus ? "已创建" : "已存在"}`);
|
|
73
|
+
console.log(`- Git hooks: ${gitHookStatus ? "已写入" : "已存在"}`);
|
|
74
|
+
console.log(`- package.json 配置 cz-git: ${czConfig ? "已写入" : "已存在"}`);
|
|
75
|
+
console.log(`- package.json 配置 simple-git-hooks: ${simpleGitHooks ? "已写入" : "已存在"}`);
|
|
76
|
+
console.log(`- npx simple-git-hooks 安装: ${npxStatus ? "成功" : "失败,请手动安装"}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (edit) {
|
|
80
|
+
if (!enabled) {
|
|
81
|
+
configureGitHooksPath(false, process.cwd());
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const raw = fs.readFileSync(String(edit), "utf8").trim();
|
|
86
|
+
if (!raw) {
|
|
87
|
+
console.error("[pubinfo-commit] 空的 commit message 文件");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await lintMessage(raw);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
console.error("[pubinfo-commit] 读取 --edit 文件失败", e);
|
|
93
|
+
}
|
|
53
94
|
return;
|
|
54
95
|
}
|
|
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
96
|
if (!enabled) {
|
|
97
|
+
console.log("[pubinfo-commit] commitlint 已关闭,交互模式不可用。");
|
|
75
98
|
configureGitHooksPath(false, process.cwd());
|
|
76
99
|
return;
|
|
77
100
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
await lintMessage(raw);
|
|
85
|
-
} catch (e) {
|
|
86
|
-
console.error("[pubinfo-commit] 读取 --edit 文件失败", e);
|
|
101
|
+
const result = await runPrompt();
|
|
102
|
+
if (!result) {
|
|
103
|
+
console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
|
|
104
|
+
return;
|
|
87
105
|
}
|
|
88
|
-
|
|
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;
|
|
106
|
+
await lintMessage(result.raw);
|
|
99
107
|
}
|
|
100
|
-
await lintMessage(result.raw);
|
|
101
108
|
}
|
|
102
109
|
});
|
|
103
110
|
|
package/package.json
CHANGED
|
File without changes
|