added colors and spaces
This commit is contained in:
@@ -25,6 +25,7 @@ Now:
|
|||||||
- Rewrite this in node to publish as an npm package
|
- Rewrite this in node to publish as an npm package
|
||||||
- Fix screenshot on npm
|
- Fix screenshot on npm
|
||||||
- add an npm ignore and add demo to README as well
|
- add an npm ignore and add demo to README as well
|
||||||
|
- make CLI looks nicer
|
||||||
|
|
||||||
Future tasks:
|
Future tasks:
|
||||||
|
|
||||||
|
|||||||
26
index.js
26
index.js
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import chalk from "chalk";
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import inquirer from "inquirer";
|
import inquirer from "inquirer";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
@@ -7,11 +8,12 @@ import fetch from "node-fetch";
|
|||||||
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("▲ Welcome to AICommit!");
|
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
|
||||||
|
|
||||||
if (!OPENAI_API_KEY) {
|
if (!OPENAI_API_KEY) {
|
||||||
console.error(
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -21,7 +23,7 @@ async function main() {
|
|||||||
stdio: "ignore",
|
stdio: "ignore",
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("▲ This is not a git repository");
|
console.error(chalk.white("▲ ") + "This is not a git repository");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,14 +33,17 @@ async function main() {
|
|||||||
|
|
||||||
if (!diff) {
|
if (!diff) {
|
||||||
console.log(
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
||||||
if (diff.length > 8000) {
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,10 +53,15 @@ async function main() {
|
|||||||
: "Do not preface the commit with anything."
|
: "Do not preface the commit with anything."
|
||||||
} Return a complete sentence and do not repeat yourself: ${diff}`;
|
} 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);
|
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([
|
const confirmationMessage = await inquirer.prompt([
|
||||||
{
|
{
|
||||||
@@ -63,7 +73,7 @@ async function main() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (confirmationMessage.useCommitMessage === "n") {
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aicommits",
|
"name": "aicommits",
|
||||||
"version": "0.1.0",
|
"version": "0.1.2",
|
||||||
"description": "Writes your git commit messages for you with AI",
|
"description": "Writes your git commit messages for you with AI",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
"author": "Hassan El Mghari (@nutlope)",
|
"author": "Hassan El Mghari (@nutlope)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"chalk": "^5.2.0",
|
||||||
"inquirer": "^9.1.4",
|
"inquirer": "^9.1.4",
|
||||||
"node-fetch": "^3.3.0"
|
"node-fetch": "^3.3.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user