Skip to content
Open
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ PR early, PR often.

## commit types

- `--feat` or `-f` to make a feature commit
- `--style` or `-s` to make a style commit
- `--fix` or `-x` to make a fix commit
- `--chore` or `-c` to make a chore commit
- `--doc` or `-d` to make a docs commit
- `--refactor` or `-r` to make a refactor commit
- `--content` or `-n` to make a content commit
- `--test` or `-t` to make a test commit
- `--try` or `-y` to make a try commit
- `--build` or `-b` to make a build commit
| Commit Type | Emoji | Flag |
| ---------------- | ----- | -------------------- |
| New Feature | 📦 | `--feat` or `-f` |
| Style | 🎨 | `--style` or `-s` |
| Bugfix | 🐛 | `--fix` or `-x` |
| Chore | 🧹 | `--chore` or `-c` |
| Documentation | 📚 | `--doc` or `-d` |
| Refactor | 🛠 | `--refactor` or `-r` |
| Content | 📝 | `--content` or `-n` |
| Test | ✅ | `--test` or `-t` |
| Try | 🤞 | `--try` or `-y` |
| Build | 🚀 | `--build` or `-b` |
| Naked (no emoji) | | `--naked` or `-n` |

## details

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "git-emoji-commit",
"version": "1.23.0",
"version": "1.23.1-alpha.3",
"description": "Simple CLI to encourage more concise commits using emojis.",
"main": "dist/cli.js",
"type": "module",
Expand Down
48 changes: 44 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const STAGED_FILES_WARNING_THRESHOLD = 30;

const program = new Command();

interface Answers {
commitType: string;
commitMessage: string;
}

interface CommitType {
emoji: string;
name: string;
Expand All @@ -21,7 +26,7 @@ const commitTypes: Record<string, CommitType> = {
description: "new feature",
},
style: {
emoji: "💅",
emoji: "🎨",
name: "STYLE",
description: "layout or style change",
},
Expand All @@ -36,7 +41,7 @@ const commitTypes: Record<string, CommitType> = {
description: "update packages, gitignore etc; (no prod code)",
},
doc: {
emoji: "📖",
emoji: "📚",
name: "DOC",
description: "documentation",
},
Expand Down Expand Up @@ -65,6 +70,11 @@ const commitTypes: Record<string, CommitType> = {
name: "BUILD",
description: "build for production",
},
naked: {
emoji: "",
name: "",
description: "naked commit",
},
};

const questions = [
Expand Down Expand Up @@ -135,10 +145,31 @@ async function checkVersion() {
}
}

async function getDeltaFiles() {
try {
const { stdout } = await exec("git status -s");
const arrayOfDeltaFiles = stdout
.trim()
.split("\n")
.filter((line) => line.length);
return arrayOfDeltaFiles;
} catch (err) {
// @ts-ignore
if (err.code === 1) {
return [];
}
throw err;
}
}

async function getStagedFiles() {
try {
const { stdout } = await exec("git diff --cached --name-only");
return stdout.trim().split("\n");
const arrayOfStagedFiles = stdout
.trim()
.split("\n")
.filter((line) => line.length);
return arrayOfStagedFiles;
} catch (err) {
// @ts-ignore
if (err.code === 1) {
Expand Down Expand Up @@ -212,6 +243,7 @@ async function confirmCommitHasManyFiles(stagedFilesCount: number) {
.option("-t, --test", "add/edit test")
.option("-y, --try", "add untested to production")
.option("-b, --build", "build for production")
.option("-n, --naked", "no-emoji naked commit")
.version(version)
.parse(process.argv);

Expand All @@ -224,6 +256,14 @@ async function confirmCommitHasManyFiles(stagedFilesCount: number) {
return;
}

const deltaFiles = await getDeltaFiles();
if (deltaFiles.length === 0) {
console.log(
"🪹 There are no files to stage. Make some changes then try again."
);
return;
}

const stagedFiles = await getStagedFiles();
if (stagedFiles.length === 0) {
console.log(
Expand Down Expand Up @@ -251,7 +291,7 @@ async function confirmCommitHasManyFiles(stagedFilesCount: number) {
const commitMessage = program.args[0];

if (!commitMessage) {
const answers = await inquirer.prompt(questions);
const answers = await inquirer.prompt<Answers>(questions);
const commitType = answers.commitType;
await makeCommit(commitType, answers.commitMessage);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "1.23.0";
export const version = "1.23.1-alpha.3";