diff --git a/README.md b/README.md index c945ac9..45d2c44 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index c8cc7a7..b05d72f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "git-emoji-commit", - "version": "1.23.0", + "version": "1.23.1-alpha.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "git-emoji-commit", - "version": "1.23.0", + "version": "1.23.1-alpha.3", "license": "ISC", "dependencies": { "commander": "^10.0.0", diff --git a/package.json b/package.json index 73acefd..6ddf775 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli.ts b/src/cli.ts index f64a8d7..07db070 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -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; @@ -21,7 +26,7 @@ const commitTypes: Record = { description: "new feature", }, style: { - emoji: "๐Ÿ’…", + emoji: "๐ŸŽจ", name: "STYLE", description: "layout or style change", }, @@ -36,7 +41,7 @@ const commitTypes: Record = { description: "update packages, gitignore etc; (no prod code)", }, doc: { - emoji: "๐Ÿ“–", + emoji: "๐Ÿ“š", name: "DOC", description: "documentation", }, @@ -65,6 +70,11 @@ const commitTypes: Record = { name: "BUILD", description: "build for production", }, + naked: { + emoji: "", + name: "", + description: "naked commit", + }, }; const questions = [ @@ -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) { @@ -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); @@ -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( @@ -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(questions); const commitType = answers.commitType; await makeCommit(commitType, answers.commitMessage); } else { diff --git a/src/version.ts b/src/version.ts index d48e5df..c96164d 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = "1.23.0"; \ No newline at end of file +export const version = "1.23.1-alpha.3"; \ No newline at end of file