added colors and spaces

This commit is contained in:
Hassan El Mghari
2023-02-13 16:07:43 -05:00
parent 7152f4f311
commit e56fbe4340
3 changed files with 21 additions and 9 deletions

View File

@@ -25,6 +25,7 @@ Now:
- Rewrite this in node to publish as an npm package
- Fix screenshot on npm
- add an npm ignore and add demo to README as well
- make CLI looks nicer
Future tasks:

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env node
import chalk from "chalk";
import { execSync } from "child_process";
import inquirer from "inquirer";
import fetch from "node-fetch";
@@ -7,11 +8,12 @@ import fetch from "node-fetch";
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
async function main() {
console.log("Welcome to AICommit!");
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
if (!OPENAI_API_KEY) {
console.error(
"▲ Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
chalk.white("▲ ") +
"Please specify an OpenAI key using export OPEN_AI_KEY='YOUR_API_KEY'"
);
process.exit(1);
}
@@ -21,7 +23,7 @@ async function main() {
stdio: "ignore",
});
} catch (e) {
console.error("This is not a git repository");
console.error(chalk.white("▲ ") + "This is not a git repository");
process.exit(1);
}
@@ -31,14 +33,17 @@ async function main() {
if (!diff) {
console.log(
"▲ No staged changes found. Make sure there are changes and run `git add .`"
chalk.white("▲ ") +
"No staged changes found. Make sure there are changes and run `git add .`"
);
process.exit(1);
}
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
if (diff.length > 8000) {
console.log("▲ The diff is too large to write a commit message.");
console.log(
chalk.white("▲ ") + "The diff is too large to write a commit message."
);
process.exit(1);
}
@@ -48,10 +53,15 @@ async function main() {
: "Do not preface the commit with anything."
} Return a complete sentence and do not repeat yourself: ${diff}`;
console.log("▲ Generating your AI commit message...\n");
console.log(
chalk.white("▲ ") + chalk.gray("Generating your AI commit message...\n")
);
const aiCommitMessage = await generateCommitMessage(prompt);
console.log(aiCommitMessage);
console.log(
chalk.white("▲ ") + chalk.bold("Commit message: ") + aiCommitMessage
);
console.log("\n");
const confirmationMessage = await inquirer.prompt([
{
@@ -63,7 +73,7 @@ async function main() {
]);
if (confirmationMessage.useCommitMessage === "n") {
console.log("Commit message has not been commited.`");
console.log(chalk.white("▲ ") + "Commit message has not been commited.");
process.exit(1);
}

View File

@@ -1,6 +1,6 @@
{
"name": "aicommits",
"version": "0.1.0",
"version": "0.1.2",
"description": "Writes your git commit messages for you with AI",
"main": "index.js",
"bin": {
@@ -11,6 +11,7 @@
"author": "Hassan El Mghari (@nutlope)",
"license": "MIT",
"dependencies": {
"chalk": "^5.2.0",
"inquirer": "^9.1.4",
"node-fetch": "^3.3.0"
}