@pubinfo/cli 2.1.1 → 2.1.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/commit-DXqpQHUB.js +95 -0
- package/dist/index.js +2 -2
- package/package.json +5 -5
- package/dist/commit-DmeFnmwn.js +0 -96
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/commit.ts
|
|
5
|
+
/**
|
|
6
|
+
* `pubinfo commit` 子命令:
|
|
7
|
+
* 统一封装项目级提交体验,复用 `@pubinfo/commitlint` 的核心能力。
|
|
8
|
+
* 功能概述:
|
|
9
|
+
* 1. 交互式生成符合规范的提交信息(中文 + 可选 emoji)。
|
|
10
|
+
* 2. 支持 `--edit` 供 commit-msg 钩子调用,读取临时文件并执行 lint。
|
|
11
|
+
* 4. 支持 `--init` 一键初始化(cz 配置 / 模板 / git hooks)。
|
|
12
|
+
* 5. 不直接执行 `git commit`,保持透明,调用者自行决定是否提交。
|
|
13
|
+
*/
|
|
14
|
+
var commit_default = {
|
|
15
|
+
meta: {
|
|
16
|
+
name: "commit",
|
|
17
|
+
description: "交互式规范 Commit Lint 提交"
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
edit: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "从 commit-msg 钩子传入的临时文件路径 (--edit $1)"
|
|
23
|
+
},
|
|
24
|
+
init: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
description: "初始化提交环境 (cz 配置 / 模板 / git hooks)"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
run: async ({ args }) => {
|
|
30
|
+
const { createCzConfig, createGitMessage, runCzConfig, runNpx, runSimpleGitHooks, runGitMessage, lintMessage, runPrompt, isInsideGitRepo, isCommitlintEnabled, configureGitHooksPath } = await import("@pubinfo/commitlint");
|
|
31
|
+
if (!isInsideGitRepo()) console.error("[pubinfo commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
|
|
32
|
+
else {
|
|
33
|
+
const commitlintEnabled = await isCommitlintEnabled();
|
|
34
|
+
if (args.init) {
|
|
35
|
+
const cwd$1 = process.cwd();
|
|
36
|
+
if (!commitlintEnabled) {
|
|
37
|
+
const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd$1, false);
|
|
38
|
+
const removedCli = runSimpleGitHooks("pubinfo commit", cwd$1, false);
|
|
39
|
+
const disabledHooks = configureGitHooksPath(false, cwd$1);
|
|
40
|
+
if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
|
|
41
|
+
else console.log("[pubinfo commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
configureGitHooksPath(true, cwd$1);
|
|
45
|
+
const pubinfoDir = `${cwd$1}/.pubinfo`;
|
|
46
|
+
if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
|
|
47
|
+
const gitMessageStatus = createGitMessage();
|
|
48
|
+
const czConfigStatus = createCzConfig(pubinfoDir);
|
|
49
|
+
const gitHookStatus = runGitMessage();
|
|
50
|
+
const simpleGitHooks = runSimpleGitHooks("pubinfo commit");
|
|
51
|
+
const czConfig = runCzConfig(".pubinfo/cz.config.cjs");
|
|
52
|
+
const npxStatus = runNpx();
|
|
53
|
+
console.log("[pubinfo-commit] 初始化结果:");
|
|
54
|
+
console.log(`- cz.config.cjs: ${czConfigStatus ? "已创建" : "已存在"}`);
|
|
55
|
+
console.log(`- .gitmessage: ${gitMessageStatus ? "已创建" : "已存在"}`);
|
|
56
|
+
console.log(`- Git hooks: ${gitHookStatus ? "已写入" : "已存在"}`);
|
|
57
|
+
console.log(`- package.json 配置 cz-git: ${czConfig ? "已写入" : "已存在"}`);
|
|
58
|
+
console.log(`- package.json 配置 simple-git-hooks: ${simpleGitHooks ? "已写入" : "已存在"}`);
|
|
59
|
+
console.log(`- npx simple-git-hooks 安装: ${npxStatus ? "成功" : "失败,请手动安装"}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (args.edit) {
|
|
63
|
+
if (!commitlintEnabled) {
|
|
64
|
+
configureGitHooksPath(false, process.cwd());
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const raw = fs.readFileSync(String(args.edit), "utf8").trim();
|
|
69
|
+
if (!raw) {
|
|
70
|
+
console.error("[pubinfo commit] 空的 commit message");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
await lintMessage(raw);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error("[pubinfo commit] 读取 --edit 文件失败", e);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!commitlintEnabled) {
|
|
80
|
+
console.log("[pubinfo commit] commitlint 已关闭,交互模式不可用。");
|
|
81
|
+
configureGitHooksPath(false, process.cwd());
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const result = await runPrompt();
|
|
85
|
+
if (!result) {
|
|
86
|
+
console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
await lintMessage(result.raw);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { commit_default as default };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
|
|
4
4
|
//#region package.json
|
|
5
5
|
var name = "@pubinfo/cli";
|
|
6
|
-
var version = "2.1.
|
|
6
|
+
var version = "2.1.2";
|
|
7
7
|
var description = "CLI for Pubinfo";
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
@@ -14,7 +14,7 @@ const commands = {
|
|
|
14
14
|
build: () => import("./build-CBpkrIHc.js").then(_rDefault),
|
|
15
15
|
preview: () => import("./preview-CL5eJUy5.js").then(_rDefault),
|
|
16
16
|
setup: () => import("./setup-tGwcxPxN.js").then(_rDefault),
|
|
17
|
-
commit: () => import("./commit-
|
|
17
|
+
commit: () => import("./commit-DXqpQHUB.js").then(_rDefault),
|
|
18
18
|
icon: () => import("./icon-Dp4dXbYT.js").then(_rDefault),
|
|
19
19
|
upgrade: () => import("./upgrade-BnDm_Nce.js").then(_rDefault)
|
|
20
20
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.2",
|
|
5
5
|
"description": "CLI for Pubinfo",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./bin/pubinfo.mjs"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"node": "^20.19.0 || >=22.12.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@pubinfo/vite": "2.1.
|
|
21
|
+
"@pubinfo/vite": "2.1.2"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"cheerio": "^1.1.2",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"execa": "^9.6.0",
|
|
27
27
|
"globby": "^14.1.0",
|
|
28
28
|
"pkg-types": "^2.3.0",
|
|
29
|
-
"@pubinfo/commitlint": "2.1.
|
|
30
|
-
"@pubinfo/shared": "2.1.
|
|
29
|
+
"@pubinfo/commitlint": "2.1.2",
|
|
30
|
+
"@pubinfo/shared": "2.1.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^24.0.10",
|
|
34
|
-
"@pubinfo/vite": "2.1.
|
|
34
|
+
"@pubinfo/vite": "2.1.2"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"dev": "tsdown --watch",
|
package/dist/commit-DmeFnmwn.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
|
|
4
|
-
//#region src/commands/commit.ts
|
|
5
|
-
/**
|
|
6
|
-
* `pubinfo commit` 子命令:
|
|
7
|
-
* 统一封装项目级提交体验,复用 `@pubinfo/commitlint` 的核心能力。
|
|
8
|
-
* 功能概述:
|
|
9
|
-
* 1. 交互式生成符合规范的提交信息(中文 + 可选 emoji)。
|
|
10
|
-
* 2. 支持 `--edit` 供 commit-msg 钩子调用,读取临时文件并执行 lint。
|
|
11
|
-
* 4. 支持 `--init` 一键初始化(cz 配置 / 模板 / git hooks)。
|
|
12
|
-
* 5. 不直接执行 `git commit`,保持透明,调用者自行决定是否提交。
|
|
13
|
-
*/
|
|
14
|
-
var commit_default = {
|
|
15
|
-
meta: {
|
|
16
|
-
name: "commit",
|
|
17
|
-
description: "交互式规范 Commit Lint 提交"
|
|
18
|
-
},
|
|
19
|
-
args: {
|
|
20
|
-
edit: {
|
|
21
|
-
type: "string",
|
|
22
|
-
description: "从 commit-msg 钩子传入的临时文件路径 (--edit $1)"
|
|
23
|
-
},
|
|
24
|
-
init: {
|
|
25
|
-
type: "boolean",
|
|
26
|
-
description: "初始化提交环境 (cz 配置 / 模板 / git hooks)"
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
run: async ({ args }) => {
|
|
30
|
-
const { createCzConfig, createGitMessage, runCzConfig, runNpx, runSimpleGitHooks, runGitMessage, lintMessage, runPrompt, isInsideGitRepo, isCommitlintEnabled, configureGitHooksPath } = await import("@pubinfo/commitlint");
|
|
31
|
-
if (!isInsideGitRepo()) {
|
|
32
|
-
console.error("[pubinfo commit] 未检测到 Git 仓库。请在已初始化的 Git 项目中运行,或执行 `git init` 后重试。");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const commitlintEnabled = await isCommitlintEnabled();
|
|
36
|
-
if (args.init) {
|
|
37
|
-
const cwd$1 = process.cwd();
|
|
38
|
-
if (!commitlintEnabled) {
|
|
39
|
-
const removedDefault = runSimpleGitHooks("pubinfo-commit", cwd$1, false);
|
|
40
|
-
const removedCli = runSimpleGitHooks("pubinfo commit", cwd$1, false);
|
|
41
|
-
const disabledHooks = configureGitHooksPath(false, cwd$1);
|
|
42
|
-
if (removedDefault || removedCli || disabledHooks) console.log("[pubinfo commit] 检测到 pubinfo.config 中已关闭 commitlint,已停用 git hooks。");
|
|
43
|
-
else console.log("[pubinfo commit] 检测到 pubinfo.config 中已关闭 commitlint,跳过初始化。");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
configureGitHooksPath(true, cwd$1);
|
|
47
|
-
const pubinfoDir = `${cwd$1}/.pubinfo`;
|
|
48
|
-
if (!fs.existsSync(pubinfoDir)) fs.mkdirSync(pubinfoDir);
|
|
49
|
-
const gitMessageStatus = createGitMessage();
|
|
50
|
-
const czConfigStatus = createCzConfig(pubinfoDir);
|
|
51
|
-
const gitHookStatus = runGitMessage();
|
|
52
|
-
const simpleGitHooks = runSimpleGitHooks("pubinfo commit");
|
|
53
|
-
const czConfig = runCzConfig(".pubinfo/cz.config.cjs");
|
|
54
|
-
const npxStatus = runNpx();
|
|
55
|
-
console.log("[pubinfo-commit] 初始化结果:");
|
|
56
|
-
console.log(`- cz.config.cjs: ${czConfigStatus ? "已创建" : "已存在"}`);
|
|
57
|
-
console.log(`- .gitmessage: ${gitMessageStatus ? "已创建" : "已存在"}`);
|
|
58
|
-
console.log(`- Git hooks: ${gitHookStatus ? "已写入" : "已存在"}`);
|
|
59
|
-
console.log(`- package.json 配置 cz-git: ${czConfig ? "已写入" : "已存在"}`);
|
|
60
|
-
console.log(`- package.json 配置 simple-git-hooks: ${simpleGitHooks ? "已写入" : "已存在"}`);
|
|
61
|
-
console.log(`- npx simple-git-hooks 安装: ${npxStatus ? "成功" : "失败,请手动安装"}`);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (args.edit) {
|
|
65
|
-
if (!commitlintEnabled) {
|
|
66
|
-
configureGitHooksPath(false, process.cwd());
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
const raw = fs.readFileSync(String(args.edit), "utf8").trim();
|
|
71
|
-
if (!raw) {
|
|
72
|
-
console.error("[pubinfo commit] 空的 commit message");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
await lintMessage(raw);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
console.error("[pubinfo commit] 读取 --edit 文件失败", e);
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!commitlintEnabled) {
|
|
82
|
-
console.log("[pubinfo commit] commitlint 已关闭,交互模式不可用。");
|
|
83
|
-
configureGitHooksPath(false, process.cwd());
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const result = await runPrompt();
|
|
87
|
-
if (!result) {
|
|
88
|
-
console.error("[pubinfo-commit] 未找到 cz-git 或交互被中断");
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
await lintMessage(result.raw);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
//#endregion
|
|
96
|
-
export { commit_default as default };
|