@pubinfo/commitlint 2.0.0-rc.3 → 2.0.0-rc.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/bin/commit.js +1 -1
- package/dist/index.d.ts +17 -61
- package/dist/index.js +2 -2
- package/dist/lint.message-TYD-xclw.js +2341 -0
- package/dist/run.d.ts +3 -1
- package/dist/run.js +119 -1
- package/package.json +1 -1
- package/dist/run-Ckp4pYFS.d.ts +0 -4
- package/dist/run-kpuZDnr9.js +0 -587
package/dist/run.d.ts
CHANGED
package/dist/run.js
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createCzConfig, createGitMessage, lintMessage, runCzConfig, runGitMessage, runNpx, runPrompt, runSimpleGitHooks } from "./lint.message-TYD-xclw.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { defineCommand, runMain as runMain$1 } from "citty";
|
|
2
5
|
|
|
6
|
+
//#region package.json
|
|
7
|
+
var name = "@pubinfo/commitlint";
|
|
8
|
+
var type = "module";
|
|
9
|
+
var version = "2.0.0-rc.4";
|
|
10
|
+
var description = "commitlint config for Pubinfo projects";
|
|
11
|
+
var exports = { ".": "./dist/index.js" };
|
|
12
|
+
var main$1 = "./dist/index.js";
|
|
13
|
+
var module = "./dist/index.js";
|
|
14
|
+
var types = "./dist/index.d.ts";
|
|
15
|
+
var typesVersions = { "*": { "*": ["./dist/*", "./*"] } };
|
|
16
|
+
var bin = { "pubinfo-commit": "./bin/commit.js" };
|
|
17
|
+
var files = ["bin", "dist"];
|
|
18
|
+
var scripts = {
|
|
19
|
+
"build": "tsdown",
|
|
20
|
+
"stub": "tsdown --watch"
|
|
21
|
+
};
|
|
22
|
+
var dependencies = {
|
|
23
|
+
"@commitlint/config-conventional": "catalog:commit",
|
|
24
|
+
"@commitlint/lint": "catalog:commit",
|
|
25
|
+
"@commitlint/load": "catalog:commit",
|
|
26
|
+
"citty": "catalog:node",
|
|
27
|
+
"czg": "catalog:commit"
|
|
28
|
+
};
|
|
29
|
+
var package_default = {
|
|
30
|
+
name,
|
|
31
|
+
type,
|
|
32
|
+
version,
|
|
33
|
+
description,
|
|
34
|
+
exports,
|
|
35
|
+
main: main$1,
|
|
36
|
+
module,
|
|
37
|
+
types,
|
|
38
|
+
typesVersions,
|
|
39
|
+
bin,
|
|
40
|
+
files,
|
|
41
|
+
scripts,
|
|
42
|
+
dependencies
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/cli.ts
|
|
47
|
+
/**
|
|
48
|
+
* 本文件提供 `pubinfo-commit` 可执行入口(由 package.json bin 指向)。
|
|
49
|
+
* 作用:
|
|
50
|
+
* 1. 在交互模式下通过 cz-git 生成符合约定式规范的提交信息(中文提示)。
|
|
51
|
+
* 2. 在 `commit-msg` 钩子中以 `--edit` 方式读取 Git 临时文件并进行 lint 校验。
|
|
52
|
+
* 3. 通过 `--init` 一键生成交互配置、提交模板与 hook 配置。
|
|
53
|
+
*
|
|
54
|
+
* 注意:不直接调用 `git commit`,保持透明度,让调用方自主执行提交动作。
|
|
55
|
+
*/
|
|
56
|
+
const main = defineCommand({
|
|
57
|
+
meta: {
|
|
58
|
+
name: package_default.name,
|
|
59
|
+
version: package_default.version,
|
|
60
|
+
description: package_default.description
|
|
61
|
+
},
|
|
62
|
+
args: {
|
|
63
|
+
edit: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "Git 钩子传入的 commit message 文件路径 (--edit $1)"
|
|
66
|
+
},
|
|
67
|
+
init: {
|
|
68
|
+
type: "boolean",
|
|
69
|
+
description: "初始化 commit 环境 (模板 / cz / git hooks)"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
run: async ({ args }) => {
|
|
73
|
+
const { edit, init } = args;
|
|
74
|
+
if (init) {
|
|
75
|
+
const pubinfoDir = `${process.cwd()}/.pubinfo`;
|
|
76
|
+
if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
|
|
77
|
+
const gitMessageStatus = createGitMessage();
|
|
78
|
+
const czConfigStatus = createCzConfig(pubinfoDir);
|
|
79
|
+
const gitHookStatus = runGitMessage();
|
|
80
|
+
const simpleGitHooks = runSimpleGitHooks();
|
|
81
|
+
const czConfig = runCzConfig(".pubinfo/cz.config.cjs");
|
|
82
|
+
const npxStatus = runNpx();
|
|
83
|
+
console.log("[pubinfo-commit] 初始化结果:");
|
|
84
|
+
console.log(`- cz.config.cjs: ${czConfigStatus ? "已创建" : "已存在"}`);
|
|
85
|
+
console.log(`- .gitmessage: ${gitMessageStatus ? "已创建" : "已存在"}`);
|
|
86
|
+
console.log(`- Git hooks: ${gitHookStatus ? "已写入" : "已存在"}`);
|
|
87
|
+
console.log(`- package.json 配置 cz-git: ${czConfig ? "已写入" : "已存在"}`);
|
|
88
|
+
console.log(`- package.json 配置 simple-git-hooks: ${simpleGitHooks ? "已写入" : "已存在"}`);
|
|
89
|
+
console.log(`- npx simple-git-hooks 安装: ${npxStatus ? "成功" : "失败,请手动安装"}`);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (edit) {
|
|
93
|
+
try {
|
|
94
|
+
const raw = fs.readFileSync(String(edit), "utf8").trim();
|
|
95
|
+
if (!raw) {
|
|
96
|
+
console.error("[pubinfo-commit] 空的 commit message 文件");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
await lintMessage(raw);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error("[pubinfo-commit] 读取 --edit 文件失败", e);
|
|
102
|
+
}
|
|
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);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/run.ts
|
|
116
|
+
function runMain() {
|
|
117
|
+
return runMain$1(main);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
3
121
|
export { runMain };
|
package/package.json
CHANGED
package/dist/run-Ckp4pYFS.d.ts
DELETED