Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 UPDATE: v0.2.7 #21

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions source/app.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import React from 'react';
import {Text, Newline} from 'ink';
import BigText from 'ink-big-text';
import Gradient from 'ink-gradient';
import isGit from 'is-git-repository';
import isCommitterSet from './utils/errors.js';
import info from './utils/info.js';
import askForCommitMessage from './utils/commit.js';
import { getOpenAIKey, setOpenAIKey, deleteOPenAIKey } from './utils/api.js';
import {getOpenAIKey, setOpenAIKey, deleteOPenAIKey} from './utils/api.js';
import Logo from './utils/logo.js';

export default function App({flags}) {
if(flags.setopenai) {
if (flags.setopenai) {
setOpenAIKey(flags.setopenai);
}
if(flags.delopenai) {
if (flags.delopenai) {
deleteOPenAIKey();
}
if (!getOpenAIKey()) {
console.log('Please provide an OpenAI API key.');
console.log('You can get one from https://platform.openai.com/account/api-keys')
console.log('Run `magicc --setopenai=<api-key>` to save your API key and try again.');
console.log(
'You can get one from https://platform.openai.com/account/api-keys',
);
console.log(
'Run `magicc --setopenai=<api-key>` to save your API key and try again.',
);
} else {
console.log('You have an OpenAI API key, you can now generate a commit message.');
console.log(
'You have an OpenAI API key, you can now generate a commit message.',
);
const gitCheck = isGit();
const committerCheck = isCommitterSet();
if (gitCheck && committerCheck) {
Expand All @@ -29,20 +32,5 @@ export default function App({flags}) {
console.log('This is not a git repository.');
}
}
return (
<>
<Gradient name='passion'>
<BigText text='Magicc' />
<Text>You can do `magicc`, you can build anything that you desire. 🪄</Text>
</Gradient>
<Text>
Version: <Text color='green'>{info('version')}</Text> |
Author: <Text color='blue'>{info('author')}</Text><Newline/>
<Text>
Need Help? <Text color="cyan">magicc --help</Text>
</Text><Newline/>
==================================================
</Text>
</>
);
return <Logo />;
}
10 changes: 6 additions & 4 deletions source/cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node
import React from 'react';
import {render} from 'ink';
import meow from 'meow';
import App from './app.js';
import Logo from './utils/logo.js';
import { render } from 'ink';

render(<Logo />, {patchConsole: false});

const cli = meow(
`
Usage
`Usage
$ magicc

Options
Expand All @@ -33,4 +35,4 @@ const cli = meow(
},
);

render(<App flags={cli.flags}/>);
render(<App flags={cli.flags} />, {patchConsole: false});
16 changes: 9 additions & 7 deletions source/utils/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import readline from 'readline';
import React from 'react';
import {Box, render, Text, useApp} from 'ink';
import SelectInput from 'ink-select-input';
import Logo from './logo.js';

async function askForCommitMessage() {
const prompt = await generatePrompt();
Expand All @@ -24,8 +25,7 @@ async function askForCommitMessage() {
.catch(error => {
console.error('Failed to commit changes:', error);
});
}
else {
} else {
console.log('Changes not committed.');
}
exit();
Expand All @@ -43,13 +43,15 @@ async function askForCommitMessage() {
];

return (
<Box flexDirection="column">
<Text>{`Suggested commit message: ${prompt}\nDo you want to proceed?`}</Text>
<SelectInput items={items} onSelect={handleSelect} />
</Box>
<Logo>
<Box flexDirection="column">
<Text>{`Suggested commit message: ${prompt}\nDo you want to proceed?`}</Text>
<SelectInput items={items} onSelect={handleSelect} />
</Box>
</Logo>
);
};

if (prompt) {
render(<SelectSuggestedCommit />);
} else {
Expand Down
29 changes: 29 additions & 0 deletions source/utils/logo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import info from './info.js';
import BigText from 'ink-big-text';
import Gradient from 'ink-gradient';
import {Text, Newline} from 'ink';

export default function Logo({children}) {
return (
<>
<Gradient name="passion">
<BigText text="Magicc" />
<Text>
You can do `magicc`, you can build anything that you desire. 🪄
</Text>
</Gradient>
<Text>
Version: <Text color="green">{info('version')}</Text> | Author:{' '}
<Text color="blue">{info('author')}</Text>
<Newline />
<Text>
Need Help? <Text color="cyan">magicc --help</Text>
</Text>
<Newline />
==================================================
</Text>
{children}
</>
);
}
Loading