Skip to content

Commit a7a65f9

Browse files
authored
🚀 UPDATE: v0.2.5
Merge pull request #13 from warengonzaga/dev
2 parents e5926ac + 5864bef commit a7a65f9

File tree

7 files changed

+746
-688
lines changed

7 files changed

+746
-688
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ dist
1414
## env
1515
.env
1616
.env.*
17+
18+
# yarn v2
19+
.yarn/cache
20+
.yarn/unplugged
21+
.yarn/build-state.yml
22+
.yarn/install-state.gz
23+
.pnp.*

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"name": "magicc",
3-
"version": "0.2.1",
3+
"version": "0.2.5",
44
"author": "Waren Gonzaga",
55
"description": "You can do `magicc`, you can build anything that you desire.",
66
"keywords": [
7+
"magic",
78
"magicc",
89
"openai",
910
"git",
1011
"commit",
12+
"message",
1113
"tool",
1214
"ai",
1315
"cli"
@@ -21,11 +23,14 @@
2123
"scripts": {
2224
"build": "babel --out-dir=dist source",
2325
"dev": "babel --out-dir=dist --watch source",
24-
"clean": "rm -rf dist",
25-
"setup": "npm run setup:ubuntu",
26-
"setup:ubuntu": "npm run clean && npm run build && npm i -g .",
27-
"reset": "npm run reset:ubuntu",
28-
"reset:ubuntu": "npm uninstall -g magicc && npm run setup:ubuntu",
26+
"clean":"npm run clean:linux",
27+
"clean:linux": "rm -rf dist",
28+
"clean:windows": "rmdir /s /q dist",
29+
"setup": "npm run setup:linux",
30+
"setup:linux": "npm run clean:linux && npm run build && npm i -g .",
31+
"setup:windows":"npm run clean:windows && npm run build",
32+
"reset": "npm run reset:linux",
33+
"reset:linux": "npm uninstall -g magicc && npm run setup:linux",
2934
"test": "prettier --check . && xo && ava"
3035
},
3136
"files": [
@@ -38,6 +43,7 @@
3843
"ink": "^4.1.0",
3944
"ink-big-text": "^2.0.0",
4045
"ink-gradient": "^3.0.0",
46+
"ink-select-input": "^6.0.0",
4147
"is-git-repository": "^2.0.0",
4248
"meow": "^11.0.0",
4349
"openai": "^4.28.4",

source/cli.js

100644100755
File mode changed.

source/utils/commit.js

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,61 @@
1-
import generatePrompt from "./openai.js";
1+
import generatePrompt from './openai.js';
22
import {execa} from 'execa';
3-
import readline from "readline";
3+
import readline from 'readline';
4+
import React from 'react';
5+
import {Box, render, Text, useApp} from 'ink';
6+
import SelectInput from 'ink-select-input';
47

58
async function askForCommitMessage() {
6-
const prompt = await generatePrompt();
9+
const prompt = await generatePrompt();
710

8-
const rl = readline.createInterface({
9-
input: process.stdin,
10-
output: process.stdout,
11-
});
11+
const rl = readline.createInterface({
12+
input: process.stdin,
13+
output: process.stdout,
14+
});
1215

13-
if (prompt) {
14-
rl.question(`Suggested commit message: ${prompt}\nDo you want to proceed? (y/N) `, (answer) => {
15-
if (answer.toLowerCase() === "y") {
16-
execa("git", ["commit", "-m", prompt])
17-
.then(() => {
18-
console.log("Changes committed successfully!");
19-
})
20-
.catch((error) => {
21-
console.error("Failed to commit changes:", error);
22-
});
23-
} else {
24-
console.log("Changes not committed.");
25-
}
16+
const SelectSuggestedCommit = () => {
17+
const {exit} = useApp();
18+
const handleSelect = item => {
19+
if (item.value) {
20+
execa('git', ['commit', '-m', prompt])
21+
.then(() => {
22+
console.log('Changes committed successfully!');
23+
})
24+
.catch(error => {
25+
console.error('Failed to commit changes:', error);
26+
});
27+
}
28+
else {
29+
console.log('Changes not committed.');
30+
}
31+
exit();
32+
};
2633

27-
rl.close();
28-
});
29-
} else {
30-
console.log("No changes to commit...");
31-
rl.close();
32-
}
34+
const items = [
35+
{
36+
label: 'No',
37+
value: false,
38+
},
39+
{
40+
label: 'Yes',
41+
value: true,
42+
},
43+
];
44+
45+
return (
46+
<Box flexDirection="column">
47+
<Text>{`Suggested commit message: ${prompt}\nDo you want to proceed?`}</Text>
48+
<SelectInput items={items} onSelect={handleSelect} />
49+
</Box>
50+
);
51+
};
52+
53+
if (prompt) {
54+
render(<SelectSuggestedCommit />);
55+
} else {
56+
console.log('No changes to commit...');
57+
rl.close();
58+
}
3359
}
3460

35-
export default askForCommitMessage;
61+
export default askForCommitMessage;

source/utils/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"message": "You are the author of the changes, you are going to provide a professional git commit message that is no longer than 25 characters in imperative present tense. Stricly no emojis are allowed and no conventional commit message as prefix is already provided. For example, instead of 'fix: fix a bug' make it 'fix a bug'. The message should be in lower case and no period at the end.",
44
"default_model": "gpt-4o-mini",
55
"maxDiffSize": 4000
6-
}
6+
}

source/utils/openai.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function generatePrompt() {
6767

6868
if (gitDiffContent.length > maxDiffSize) {
6969
console.log('Diff content is too large. Skipping OpenAI request.');
70-
return `✨ tweak: update ${firstFilePath}`;
70+
return `✨ tweak (${firstFilePath}): update ${firstFilePath}`;
7171
}
7272

7373
// use the prompt from the config file emoji and send to openai
@@ -88,7 +88,7 @@ async function generatePrompt() {
8888
});
8989

9090
if (await gitStatus() !== false) {
91-
return `${category.choices[0].message.content}: ${message.choices[0].message.content}`;
91+
return `${category.choices[0].message.content} (${firstFilePath}): ${message.choices[0].message.content}`;
9292
} else {
9393
return false;
9494
}

0 commit comments

Comments
 (0)