From e56fbe4340183a8f90fd210fff4f3de5afa6870d Mon Sep 17 00:00:00 2001 From: Hassan El Mghari Date: Mon, 13 Feb 2023 16:07:43 -0500 Subject: [PATCH] added colors and spaces --- README.md | 1 + index.js | 26 ++++++++++++++++++-------- package.json | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1ae5c4d..59c8437 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/index.js b/index.js index 856c1f9..56cc5a8 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/package.json b/package.json index e485a28..9cae2ac 100644 --- a/package.json +++ b/package.json @@ -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" }