ai-cmg 0.0.1
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 +2 -0
- package/dist/index.js +110 -0
- package/package.json +31 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync, spawnSync } from 'child_process';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import pc from 'picocolors';
|
|
5
|
+
import clipboardy from 'clipboardy';
|
|
6
|
+
import Conf from 'conf';
|
|
7
|
+
const WORKER_URL = 'https://commit.d-code.workers.dev';
|
|
8
|
+
const config = new Conf({ projectName: 'ai-cmg' });
|
|
9
|
+
async function main() {
|
|
10
|
+
// 1. 사용자 힌트(Arguments) 가져오기
|
|
11
|
+
const args = process.argv.slice(2).join(' ');
|
|
12
|
+
if (args) {
|
|
13
|
+
console.log(pc.cyan(`💡 사용자 힌트 감지: "${args}"`));
|
|
14
|
+
}
|
|
15
|
+
// 2. 인증 토큰 확인 (없으면 물어봄)
|
|
16
|
+
let authToken = config.get('authToken');
|
|
17
|
+
if (!authToken) {
|
|
18
|
+
console.log(pc.bgMagenta(pc.white(' 🔐 최초 인증 설정 ')));
|
|
19
|
+
console.log(pc.gray('팀에서 공유된 Access Token을 입력해주세요. (내 컴퓨터에 안전하게 저장됩니다)'));
|
|
20
|
+
const response = await prompts({
|
|
21
|
+
type: 'password',
|
|
22
|
+
name: 'token',
|
|
23
|
+
message: 'Access Token:',
|
|
24
|
+
validate: (value) => value.length > 0 ? true : '토큰을 입력해주세요.'
|
|
25
|
+
});
|
|
26
|
+
if (!response.token)
|
|
27
|
+
return;
|
|
28
|
+
authToken = response.token;
|
|
29
|
+
config.set('authToken', authToken);
|
|
30
|
+
console.log(pc.green('✅ 인증 정보가 저장되었습니다.\n'));
|
|
31
|
+
}
|
|
32
|
+
if (!authToken)
|
|
33
|
+
return;
|
|
34
|
+
console.log(pc.cyan('ℹ️ Staged 변경 사항 분석 중...'));
|
|
35
|
+
try {
|
|
36
|
+
// 3. Git Diff 가져오기
|
|
37
|
+
let diff;
|
|
38
|
+
try {
|
|
39
|
+
diff = execSync('git diff --cached').toString();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.log(pc.red('❌ Git 저장소가 아니거나 git 명령어를 찾을 수 없습니다.'));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!diff.trim()) {
|
|
46
|
+
console.log(pc.yellow('⚠️ 커밋할 변경 사항이 없습니다. "git add"를 먼저 실행해주세요.'));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// 4. API 요청 (Diff + Hint + Auth)
|
|
50
|
+
const response = await fetch(WORKER_URL, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
'X-AUTH-TOKEN': authToken
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify({ diff, hint: args }) // 힌트도 같이 전송
|
|
57
|
+
});
|
|
58
|
+
// 인증 실패 처리 (401)
|
|
59
|
+
if (response.status === 401) {
|
|
60
|
+
console.log(pc.red('\n⛔️ 인증 실패! 토큰이 만료되었거나 틀렸습니다.'));
|
|
61
|
+
console.log(pc.gray('기존 설정 파일을 삭제합니다. 다시 실행하여 토큰을 입력해주세요.'));
|
|
62
|
+
config.delete('authToken');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new Error(`Server Error: ${response.status}`);
|
|
67
|
+
}
|
|
68
|
+
const { message } = await response.json();
|
|
69
|
+
// 5. 결과 출력 및 액션 선택
|
|
70
|
+
console.log('\n' + pc.bgGreen(pc.black(' 🤖 AI 생성 커밋 메시지 ')) + '\n');
|
|
71
|
+
console.log(pc.bold(message));
|
|
72
|
+
console.log('\n' + pc.dim('-----------------------------------') + '\n');
|
|
73
|
+
const result = await prompts({
|
|
74
|
+
type: 'select',
|
|
75
|
+
name: 'action',
|
|
76
|
+
message: '어떻게 하시겠습니까?',
|
|
77
|
+
choices: [
|
|
78
|
+
{ title: '🚀 이대로 커밋하기', value: 'commit' },
|
|
79
|
+
{ title: '✏️ 에디터에서 수정 후 커밋', value: 'edit' },
|
|
80
|
+
{ title: '📋 클립보드에 복사', value: 'copy' },
|
|
81
|
+
{ title: '❌ 취소', value: 'cancel' }
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
const action = result.action;
|
|
85
|
+
if (!action)
|
|
86
|
+
return;
|
|
87
|
+
switch (action) {
|
|
88
|
+
case 'commit':
|
|
89
|
+
spawnSync('git', ['commit', '-m', message], { stdio: 'inherit' });
|
|
90
|
+
console.log(pc.green('✅ 커밋 완료!'));
|
|
91
|
+
break;
|
|
92
|
+
case 'edit':
|
|
93
|
+
spawnSync('git', ['commit', '-e', '-m', message], { stdio: 'inherit' });
|
|
94
|
+
console.log(pc.green('✅ 커밋 완료!'));
|
|
95
|
+
break;
|
|
96
|
+
case 'copy':
|
|
97
|
+
clipboardy.writeSync(message);
|
|
98
|
+
console.log(pc.green('✅ 복사 완료!'));
|
|
99
|
+
break;
|
|
100
|
+
case 'cancel':
|
|
101
|
+
console.log(pc.gray('취소됨'));
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
107
|
+
console.error(pc.red('오류 발생:'), message);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-cmg",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "AI Commit Message Generator",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ai-commit": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepare": "npm run build",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"publish:public": "npm publish --access public"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"clipboardy": "^5.0.2",
|
|
22
|
+
"conf": "^15.0.2",
|
|
23
|
+
"picocolors": "^1.1.1",
|
|
24
|
+
"prompts": "^2.4.2"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^25.0.9",
|
|
28
|
+
"@types/prompts": "^2.4.9",
|
|
29
|
+
"typescript": "^5.9.3"
|
|
30
|
+
}
|
|
31
|
+
}
|