Skip to content

Commit 0da9756

Browse files
committed
✨ tweak: update project structure
1 parent d00794b commit 0da9756

7 files changed

Lines changed: 296 additions & 13 deletions

File tree

.github/funding.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Developed and maintained by Waren Gonzaga with the help of project contributors.
2+
# GitHub Sponsors: https://github.com/sponsors/warengonzaga
3+
4+
github: warengonzaga
5+
6+
# Sponsoring this project means a lot to me. Your support helps me to continue building great open-source projects just like this.

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## node
12
node_modules
3+
4+
## yarn
5+
yarn-error.log
6+
7+
## build
28
dist
3-
.env
9+
10+
## env
11+
.env

package.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
{
22
"name": "magicc",
3-
"version": "0.0.0",
4-
"license": "MIT",
3+
"version": "0.1.0",
4+
"author": "Waren Gonzaga",
5+
"description": "You can do `magicc`, you can build anything that you desire.",
6+
"keywords": [
7+
"magicc",
8+
"openai",
9+
"git",
10+
"commit",
11+
"tool",
12+
"ai",
13+
"cli"
14+
],
15+
"license": "GPL-3.0",
516
"bin": "dist/cli.js",
617
"type": "module",
718
"engines": {
8-
"node": ">=16"
19+
"node": ">=18"
920
},
1021
"scripts": {
1122
"build": "babel --out-dir=dist source",
1223
"dev": "babel --out-dir=dist --watch source",
24+
"clean": "rm -rf dist",
1325
"test": "prettier --check . && xo && ava"
1426
},
1527
"files": [
1628
"dist"
1729
],
1830
"dependencies": {
31+
"dotenv": "^16.4.5",
1932
"ink": "^4.1.0",
2033
"ink-big-text": "^2.0.0",
2134
"ink-gradient": "^3.0.0",
2235
"meow": "^11.0.0",
36+
"openai": "^4.28.4",
2337
"react": "^18.2.0"
2438
},
2539
"devDependencies": {
2640
"@babel/cli": "^7.21.0",
2741
"@babel/preset-react": "^7.18.6",
2842
"@vdemedes/prettier-config": "^2.0.1",
2943
"ava": "^5.2.0",
44+
"babel-plugin-inline-json-import": "^0.3.2",
3045
"chalk": "^5.2.0",
3146
"eslint-config-xo-react": "^0.27.0",
3247
"eslint-plugin-react": "^7.32.2",
@@ -55,6 +70,9 @@
5570
"babel": {
5671
"presets": [
5772
"@babel/preset-react"
73+
],
74+
"plugins": [
75+
"inline-json-import"
5876
]
5977
}
6078
}

source/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import React from 'react';
22
import {Text} from 'ink';
33
import BigText from 'ink-big-text';
44
import Gradient from 'ink-gradient';
5+
import getGitDiff from './utils/openai.js';
56

67
export default function App() {
8+
getGitDiff();
9+
710
return (
811
<>
912
<Gradient name="passion">
1013
<BigText text="Magicc" />
11-
<Text>You can do `magicc`, you can commit anything that you desire. 🪄</Text>
14+
<Text>You can do `magicc`, you can build anything that you desire. 🪄</Text>
1215
</Gradient>
1316
</>
1417
);

source/utils/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"prompt": "You are a helpful assistant that outputs git commit message based on git diff. Ignore changes in dev dependencies and package-lock.json."
3+
}

source/utils/openai.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import execa from 'execa';
2+
import OpenAI from 'openai';
3+
import dotenv from 'dotenv';
4+
import config from './config.json';
5+
6+
dotenv.config();
7+
8+
const openai = new OpenAI(process.env.OPENAI_API_KEY);
9+
10+
async function getGitDiff() {
11+
try {
12+
const { stdout: gitDiff } = await execa('git', ['diff']);
13+
14+
const completion = await openai.chat.completions.create({
15+
messages: [
16+
{
17+
role: "system",
18+
content: config.prompt,
19+
},
20+
{ role: "user", content: gitDiff },
21+
],
22+
model: "gpt-3.5-turbo-0125"
23+
});
24+
console.log(completion.choices[0].message.content);
25+
} catch (error) {
26+
console.error(error);
27+
}
28+
}
29+
30+
export default getGitDiff;

0 commit comments

Comments
 (0)