@git-ai/cli 1.0.2 → 1.0.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/index.cjs CHANGED
@@ -1,15 +1,14 @@
1
1
  #! /usr/bin/env node
2
- const path = require('path')
3
- const { pathToFileURL } = require('url')
4
-
5
- const run = async () => {
6
- const entryUrl = pathToFileURL(path.resolve(__dirname, '../src/index.mjs'))
7
- const { default: lib } = await import(entryUrl.href)
8
- await lib(process.argv.slice(2))
9
- }
10
-
11
- run().catch((error) => {
12
- console.error(error && error.message ? error.message : error)
13
- process.exit(1)
14
- })
15
-
2
+ const path = require('path');
3
+ const { pathToFileURL } = require('url');
4
+
5
+ const run = async () => {
6
+ const entryUrl = pathToFileURL(path.resolve(__dirname, '../src/index.mjs'));
7
+ const { default: lib } = await import(entryUrl.href);
8
+ await lib(process.argv.slice(2));
9
+ };
10
+
11
+ run().catch((error) => {
12
+ console.error(error && error.message ? error.message : error);
13
+ process.exit(1);
14
+ });
package/bin/index.mjs CHANGED
@@ -1,41 +1,40 @@
1
- #! /usr/bin/env node
2
- const MIN_NODE_VERSION = '12.20.0'
3
-
4
- const parseVersion = (version = '') =>
5
- version
6
- .replace(/^v/, '')
7
- .split('.')
8
- .map((part) => Number(part || 0))
9
-
10
- const isVersionLessThan = (current, target) => {
11
- const currentParts = parseVersion(current)
12
- const targetParts = parseVersion(target)
13
- for (let i = 0; i < Math.max(currentParts.length, targetParts.length); i += 1) {
14
- const currentPart = currentParts[i] || 0
15
- const targetPart = targetParts[i] || 0
16
- if (currentPart < targetPart) return true
17
- if (currentPart > targetPart) return false
18
- }
19
- return false
20
- }
21
-
22
- const notifyNodeVersion = () => {
23
- const currentVersion = process.version
24
- if (isVersionLessThan(process.versions.node, MIN_NODE_VERSION)) {
25
- console.error(
26
- `当前 Node.js 版本为 ${currentVersion},请升级至 ${MIN_NODE_VERSION} 或更高版本后再使用。`,
27
- )
28
- return false
29
- }
30
- return true
31
- }
32
-
33
- if (!notifyNodeVersion()) {
34
- process.exit(1)
35
- }
36
-
37
- import('./index.cjs').catch((error) => {
38
- console.error(error && error.message ? error.message : error)
39
- process.exit(1)
40
- })
41
-
1
+ #! /usr/bin/env node
2
+ const MIN_NODE_VERSION = '12.20.0';
3
+
4
+ const parseVersion = (version = '') =>
5
+ version
6
+ .replace(/^v/, '')
7
+ .split('.')
8
+ .map((part) => Number(part || 0));
9
+
10
+ const isVersionLessThan = (current, target) => {
11
+ const currentParts = parseVersion(current);
12
+ const targetParts = parseVersion(target);
13
+ for (let i = 0; i < Math.max(currentParts.length, targetParts.length); i += 1) {
14
+ const currentPart = currentParts[i] || 0;
15
+ const targetPart = targetParts[i] || 0;
16
+ if (currentPart < targetPart) return true;
17
+ if (currentPart > targetPart) return false;
18
+ }
19
+ return false;
20
+ };
21
+
22
+ const notifyNodeVersion = () => {
23
+ const currentVersion = process.version;
24
+ if (isVersionLessThan(process.versions.node, MIN_NODE_VERSION)) {
25
+ console.error(
26
+ `当前 Node.js 版本为 ${currentVersion},请升级至 ${MIN_NODE_VERSION} 或更高版本后再使用。`
27
+ );
28
+ return false;
29
+ }
30
+ return true;
31
+ };
32
+
33
+ if (!notifyNodeVersion()) {
34
+ process.exit(1);
35
+ }
36
+
37
+ import('./index.cjs').catch((error) => {
38
+ console.error(error && error.message ? error.message : error);
39
+ process.exit(1);
40
+ });
package/package.json CHANGED
@@ -1,46 +1,73 @@
1
- {
2
- "name": "@git-ai/cli",
3
- "version": "1.0.2",
4
- "description": "一个基于 AI 的 Git 提交消息生成器 CLI 工具,可自动分析代码变更并生成符合规范的提交信息",
5
- "type": "module",
6
- "bin": {
7
- "git-ai": "bin/index.cjs"
8
- },
9
- "keywords": [
10
- "git",
11
- "ai",
12
- "commit",
13
- "cli"
14
- ],
15
- "engines": {
16
- "node": ">=12.20.0"
17
- },
18
- "homepage": "https://github.com/code-ba/git-ai",
19
- "bugs": {
20
- "url": "https://github.com/code-ba/git-ai/issues",
21
- "email": "info@cxvh.com"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/code-ba/git-ai.git"
26
- },
27
- "publishConfig": {
28
- "registry": "https://registry.npmjs.org/",
29
- "access": "public"
30
- },
31
- "author": {
32
- "name": "Baran",
33
- "email": "info@cxvh.com",
34
- "url": "https://github.com/code-ba"
35
- },
36
- "license": "MIT",
37
- "dependencies": {
38
- "axios": "1.13.1",
39
- "cli-spinner": "0.2.10",
40
- "commander": "9.5.0",
41
- "configstore": "6.0.0",
42
- "inquirer": "7.3.3",
43
- "npmlog": "6.0.2",
44
- "chalk": "4.1.2"
45
- }
46
- }
1
+ {
2
+ "name": "@git-ai/cli",
3
+ "version": "1.0.4",
4
+ "description": "一个基于 AI 的 Git 提交消息生成器 CLI 工具,可自动分析代码变更并生成符合规范的提交信息",
5
+ "type": "module",
6
+ "bin": {
7
+ "git-ai": "bin/index.cjs"
8
+ },
9
+ "keywords": [
10
+ "git",
11
+ "ai",
12
+ "commit",
13
+ "cli"
14
+ ],
15
+ "engines": {
16
+ "node": ">=12.20.0"
17
+ },
18
+ "homepage": "https://github.com/code-ba/git-ai",
19
+ "bugs": {
20
+ "url": "https://github.com/code-ba/git-ai/issues",
21
+ "email": "info@cxvh.com"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/code-ba/git-ai.git"
26
+ },
27
+ "files": [
28
+ "bin/",
29
+ "src/",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
33
+ "publishConfig": {
34
+ "registry": "https://registry.npmjs.org/",
35
+ "access": "public"
36
+ },
37
+ "author": {
38
+ "name": "Baran",
39
+ "email": "info@cxvh.com",
40
+ "url": "https://github.com/code-ba"
41
+ },
42
+ "license": "MIT",
43
+ "scripts": {
44
+ "lint": "eslint . --ext .js,.mjs,.cjs",
45
+ "lint:fix": "eslint . --ext .js,.mjs,.cjs --fix",
46
+ "format": "prettier --check .",
47
+ "format:write": "prettier --write .",
48
+ "version:bump": "node scripts/bump-version.mjs",
49
+ "prepare": "husky install",
50
+ "prepublishOnly": "npm run lint && npm run format"
51
+ },
52
+ "dependencies": {
53
+ "axios": "1.13.1",
54
+ "chalk": "4.1.2",
55
+ "cli-spinner": "0.2.10",
56
+ "commander": "9.5.0",
57
+ "configstore": "6.0.0",
58
+ "inquirer": "7.3.3",
59
+ "npmlog": "6.0.2"
60
+ },
61
+ "devDependencies": {
62
+ "eslint": "8.57.0",
63
+ "husky": "^9.1.7",
64
+ "lint-staged": "^16.2.7",
65
+ "prettier": "2.8.8"
66
+ },
67
+ "lint-staged": {
68
+ "*.{js,mjs,cjs}": [
69
+ "eslint --fix",
70
+ "prettier --write"
71
+ ]
72
+ }
73
+ }
@@ -1,44 +1,42 @@
1
- import { exitProcess } from "../utils/Utils.mjs";
2
- import Logger from "../utils/Logger.mjs";
3
- /**
4
- * Action 基类
5
- * 所有 action 都应该继承此类并实现 execute 方法
6
- */
7
- class BaseAction {
8
- constructor(args) {
9
- this.args = args;
10
- this.startTimestamp = Date.now();
11
- }
12
-
13
- /**
14
- * 子类需要实现此方法来执行具体的业务逻辑
15
- */
16
- async execute() {
17
- throw new Error("execute() method must be implemented by subclass");
18
- }
19
-
20
- /**
21
- * 运行 action,处理错误和退出逻辑
22
- */
23
- async run() {
24
- const handleCtrlC = () => {
25
- console.log("\n");
26
- Logger.warn("检测到 Ctrl+C,正在安全退出...");
27
- exitProcess(1, this.startTimestamp);
28
- };
29
- process.once("SIGINT", handleCtrlC);
30
-
31
- try {
32
- await this.execute();
33
- process.off("SIGINT", handleCtrlC);
34
- exitProcess(0, this.startTimestamp);
35
- } catch (error) {
36
- process.off("SIGINT", handleCtrlC);
37
- Logger.error(
38
- error && typeof error.message === "string" ? error.message : error
39
- );
40
- exitProcess(1, this.startTimestamp);
41
- }
42
- }
43
- }
44
- export default BaseAction;
1
+ import { exitProcess } from '../utils/Utils.mjs';
2
+ import Logger from '../utils/Logger.mjs';
3
+ /**
4
+ * Action 基类
5
+ * 所有 action 都应该继承此类并实现 execute 方法
6
+ */
7
+ class BaseAction {
8
+ constructor(args) {
9
+ this.args = args;
10
+ this.startTimestamp = Date.now();
11
+ }
12
+
13
+ /**
14
+ * 子类需要实现此方法来执行具体的业务逻辑
15
+ */
16
+ async execute() {
17
+ throw new Error('execute() method must be implemented by subclass');
18
+ }
19
+
20
+ /**
21
+ * 运行 action,处理错误和退出逻辑
22
+ */
23
+ async run() {
24
+ const handleCtrlC = () => {
25
+ console.log('\n');
26
+ Logger.warn('检测到 Ctrl+C,正在安全退出...');
27
+ exitProcess(1, this.startTimestamp);
28
+ };
29
+ process.once('SIGINT', handleCtrlC);
30
+
31
+ try {
32
+ await this.execute();
33
+ process.off('SIGINT', handleCtrlC);
34
+ exitProcess(0, this.startTimestamp);
35
+ } catch (error) {
36
+ process.off('SIGINT', handleCtrlC);
37
+ Logger.error(error && typeof error.message === 'string' ? error.message : error);
38
+ exitProcess(1, this.startTimestamp);
39
+ }
40
+ }
41
+ }
42
+ export default BaseAction;
@@ -1,24 +1,24 @@
1
- import { config } from "../utils/Storage.mjs";
2
- import Logger from "../utils/Logger.mjs";
3
- import BaseAction from "./BaseAction.mjs";
4
-
5
- class SetBaseUrlAction extends BaseAction {
6
- constructor(baseURL = "") {
7
- super(baseURL);
8
- this.baseURL = baseURL.trim();
9
- }
10
-
11
- async execute() {
12
- config.set("baseURL", this.baseURL);
13
- if (this.baseURL) {
14
- Logger.success(`Base URL 已设置为: ${this.baseURL}`);
15
- } else {
16
- Logger.warn(`Base URL 已清空。`);
17
- }
18
- }
19
- }
20
-
21
- export default async function (args) {
22
- const action = new SetBaseUrlAction(args);
23
- await action.run();
24
- }
1
+ import { config } from '../utils/Storage.mjs';
2
+ import Logger from '../utils/Logger.mjs';
3
+ import BaseAction from './BaseAction.mjs';
4
+
5
+ class SetBaseUrlAction extends BaseAction {
6
+ constructor(baseURL = '') {
7
+ super(baseURL);
8
+ this.baseURL = baseURL.trim();
9
+ }
10
+
11
+ async execute() {
12
+ config.set('baseURL', this.baseURL);
13
+ if (this.baseURL) {
14
+ Logger.success(`Base URL 已设置为: ${this.baseURL}`);
15
+ } else {
16
+ Logger.warn(`Base URL 已清空。`);
17
+ }
18
+ }
19
+ }
20
+
21
+ export default async function (args) {
22
+ const action = new SetBaseUrlAction(args);
23
+ await action.run();
24
+ }