├── .vscode └── settings.json ├── bin └── index.js ├── .prettierrc ├── src ├── helper.js ├── commands.js └── cli.js ├── .github └── lint.yml ├── LICENSE.md ├── .eslintrc.json ├── package.json ├── .gitignore ├── README.md └── CONTRIBUTING.md /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "Unstaged" 4 | ] 5 | } -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import cli from "../src/cli.js"; 3 | 4 | cli(); 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false, 4 | "semi": true, 5 | "singleQuote": false 6 | } 7 | -------------------------------------------------------------------------------- /src/helper.js: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | 3 | export function logExec(message) { 4 | console.log("\n\n"); 5 | console.log(chalk.bgRed("⛔️ Whops! Something went wrong. Try again!")); 6 | console.log(message); 7 | } 8 | -------------------------------------------------------------------------------- /.github/lint.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | - main 6 | pull_request: 7 | branches: 8 | - "*" 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Install Dependencies 17 | run: npm install 18 | 19 | - name: Run lint 20 | run: npm run lint 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright 2023 khattakdev 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 8 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true, 4 | "es2021": true 5 | }, 6 | "extends": "standard", 7 | "overrides": [], 8 | "parserOptions": { 9 | "ecmaVersion": "latest", 10 | "sourceType": "module" 11 | }, 12 | "rules": { 13 | "no-unused-vars": [ 14 | "error", 15 | { 16 | "argsIgnorePattern": "^_", 17 | "varsIgnorePattern": "^_", 18 | "caughtErrorsIgnorePattern": "^_" 19 | } 20 | ], 21 | "no-undef": ["error"], 22 | "prefer-const": ["error"], 23 | "no-var": ["error"], 24 | "no-ternary": "error", 25 | "no-return-await": "error", 26 | "no-plusplus": "error", 27 | "eqeqeq": ["error", "always"], 28 | "quotes": ["error", "double"], 29 | "semi": ["error", "always"] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimalcommit", 3 | "version": "1.0.1", 4 | "description": "A minimalist approach toward git commits to keep things simple.", 5 | "main": "./bin/index.js", 6 | "scripts": { 7 | "lint": "eslint ." 8 | }, 9 | "bin": { 10 | "mct": "bin/index.js" 11 | }, 12 | "type": "module", 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/khattakdev/minimalcommit.git" 16 | }, 17 | "keywords": [ 18 | "git", 19 | "commit", 20 | "push", 21 | "pull" 22 | ], 23 | "author": "khattakdev", 24 | "license": "ISC", 25 | "bugs": { 26 | "url": "https://github.com/khattakdev/minimalcommit/issues" 27 | }, 28 | "homepage": "https://github.com/khattakdev/minimalcommit#readme", 29 | "dependencies": { 30 | "chalk": "^5.2.0", 31 | "inquirer": "^9.1.5" 32 | }, 33 | "devDependencies": { 34 | "eslint": "^8.37.0", 35 | "eslint-config-standard": "^17.0.0", 36 | "eslint-plugin-import": "^2.27.5", 37 | "eslint-plugin-node": "^11.1.0", 38 | "eslint-plugin-promise": "^6.1.1", 39 | "eslint-plugin-standard": "^5.0.0", 40 | "husky": "^8.0.3", 41 | "lint-staged": "^13.2.0", 42 | "prettier": "^2.8.7" 43 | }, 44 | "husky": { 45 | "hooks": { 46 | "pre-commit": "lint-staged" 47 | } 48 | }, 49 | "lint-staged": { 50 | "*.js": "eslint --fix" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* -------------------------------------------------------------------------------- /src/commands.js: -------------------------------------------------------------------------------- 1 | import { exec } from "child_process"; 2 | import chalk from "chalk"; 3 | import { logExec } from "./helper.js"; 4 | 5 | export function checkIfRepoisGit() { 6 | return new Promise((resolve, reject) => { 7 | exec("git rev-parse --is-inside-work-tree", (err, stdout, stderr) => { 8 | if (stdout == "true\n") resolve(stdout); 9 | if (stderr.includes("not a git repository")) { 10 | console.log("\n\n"); 11 | console.log( 12 | chalk.bgRed("⛔️ Whops! The directory is not a git repository.") 13 | ); 14 | console.log( 15 | "💡 Git repo not initialized. Run " + chalk.bgWhite("git init") 16 | ); 17 | reject(stderr); 18 | process.exit(0); 19 | } 20 | if (err) { 21 | logExec(err); 22 | reject(err); 23 | process.exit(0); 24 | } 25 | if (stderr) { 26 | logExec(stderr); 27 | reject(stderr); 28 | process.exit(0); 29 | } 30 | }); 31 | }); 32 | } 33 | 34 | export async function getStagedFiles() { 35 | return new Promise((resolve, reject) => { 36 | exec("git diff --cached --name-only", (err, stdout, stderr) => { 37 | if (err) { 38 | logExec(err); 39 | reject(err); 40 | } 41 | if (stderr) { 42 | logExec(stderr); 43 | reject(stderr); 44 | } 45 | 46 | if (stdout.length <= 0) { 47 | console.log(chalk.bgRed("⛔️ Whops! No files available to commit.")); 48 | resolve(null); 49 | } else { 50 | resolve(stdout); 51 | } 52 | }); 53 | }); 54 | } 55 | 56 | export function commitFiles(message) { 57 | exec(`git commit -m "${message}"`, (err, stdout, stderr) => { 58 | if (err) { 59 | logExec(err); 60 | process.exit(0); 61 | } 62 | if (stderr) { 63 | logExec(stderr); 64 | process.exit(0); 65 | } 66 | console.log(stdout); 67 | }); 68 | } 69 | 70 | export async function getUnstagedFiles() { 71 | return new Promise((resolve, reject) => { 72 | exec("git status --porcelain", (err, stdout, stderr) => { 73 | if (err) { 74 | logExec(err); 75 | reject(err); 76 | } 77 | if (stderr) { 78 | logExec(stderr); 79 | reject(stderr); 80 | } 81 | 82 | resolve(stdout); 83 | }); 84 | }); 85 | } 86 | 87 | export async function stageFiles(files) { 88 | return new Promise((resolve, reject) => { 89 | exec(`git add ${files}`, (err, stdout, stderr) => { 90 | if (err) { 91 | logExec(err); 92 | reject(err); 93 | } 94 | if (stderr) { 95 | logExec(stderr); 96 | reject(stderr); 97 | } 98 | 99 | resolve(stdout); 100 | }); 101 | }); 102 | } 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minimal Commit 2 | 3 | > _A minimalist approach toward `git commit` to keep commits simple._ 4 | 5 | ![Minimal Commit Image](https://github.com/Haimantika/minimalcommit/assets/32809211/133f42ad-3483-46ee-9bdf-f29a06356737) 6 | 7 | 8 | ## What is Minimal Commit? 9 | 10 | Minimal commit is a Node.js based CLI (command line interface) tool that helps you and your team mates to stay consistent with the `git commit` messages. To commit files using **Minimal Commit**, you have a list of options to choose from, this list consist type of work you did. This makes things simple and less confusing by choosing an option from a list. 11 | 12 | The list of options is limited to only **nine types**. This is done on purpose to keep the list as short as possible to avoid confusion. The more options you have, the more confusing it will be. 13 | 14 | ## Types 15 | Following are the nine types of commits. 16 | - `✨ feat` to be used for a new feature 17 | - `🐛 fix` to be used for bug fixes 18 | - `💥 break` to be used for breaking changes 19 | - `♻️ ref` to be used for making code/folder refactor 20 | - `🧪 test` to be used for writing test cases 21 | - `🔖 ver` to be used for version changes 22 | - `📝 docs` to be used for documentation 23 | - `🎨 style` to be used for CSS changes 24 | - `🛠 config` for configuration, and dependencies changes 25 | - `📦 misc` to be used for others 26 | 27 | ## Installation 28 | 29 | To install **Minimal Commit**, you can use the following command. 30 | 31 | ``` 32 | npm install -g minimalcommit 33 | ``` 34 | 35 | ## Why Minimal Commit? 36 | 37 | - Straight Forward 38 | - Easy to read 39 | - Visually appealing 40 | 41 | ## Usage 42 | ``` 43 | mct 44 | ``` 45 | 46 | ![Minimal Commit demo](https://user-images.githubusercontent.com/37709578/229569956-592effaa-63e6-4f15-8870-6c5f9061f19f.gif) 47 | 48 | 49 | ## How to write commits? 50 | 51 | Here’s the general syntax of Minimal Commit. 52 | 53 | ``` 54 | : 55 | ``` 56 | 57 | > ⚠️ All of the commits must be written in the present tense. 58 | > Following are some examples: 59 | 60 | ``` 61 | ✨ feat: added sign-up feature ❌ 62 | ✨ feat: add sign up feature ✅ 63 | 64 | 🛠 config: removed extra extension files ❌ 65 | 🛠 config: remove extra extension files ✅ 66 | ``` 67 | 68 | The commit title should be precise, and to the point but at the same time, it shouldn't be vague. All of the extra details should go in the description (_⚠️ Descriptions are not supported yet_.) 69 | 70 | ``` 71 | ✨ feat: add new feature ❌ 72 | ✨ feat: add sign up feature with forgot password and auth with Google ❌ 73 | ✨ feat: add sign up feature using OAuth ✅ 74 | ✨ feat: add sign up feature ✅ 75 | ``` 76 | 77 | Following are some more examples: 78 | 79 | ``` 80 | 🛠 config: add .gitignore file 81 | ♻️ ref: move functions to helper.js 82 | 📦 misc: add initial test cases 83 | 📦 docs: update docs with v2.0 features 84 | ``` 85 | 86 | ### Examples 87 | 88 | - You added `.yaml` file for GitHub Actions 89 | 90 | `✨ config: add .yaml file for github actions` 91 | 92 | - You added some tests cases for the user interface 93 | 94 | `📦 misc: add test cases for ui` 95 | 96 | - You moved some part of the code to components folder 97 | 98 | `♻️ ref: move pages code into components` 99 | 100 | - You updated the code that caused some breaking changes 101 | 102 | `💥break: update sign-up api endpoints` 103 | 104 | - You made some changes to the user interface 105 | 106 | `🎨 style: update the auto pages` 107 | 108 | ## Contributing 109 | All code contributions, must go through a pull request and be approved by the maintainer before being merged. This is to ensure a proper review of all the code. 110 | We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the [contribution guide](https://github.com/Haimantika/minimalcommit/blob/main/CONTRIBUTING.md). 111 | 112 | ## Support 113 | 114 | If you like the work, please give this repo a ⭐️ and feel free to contribute to this project through issues, and pull requests. 115 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thank you for considering contributing to Minimal Commit! Your contributions are valuable in helping us improve and grow. 2 | 3 | ## Prerequisites 4 | Before you start contributing to the project, here's the prerequisities that you need to have: 5 | 6 | 1. **Git:** You'll need git to clone the repository and manage version control. If git is not installed, download and install it from [Git Downloads](https://git-scm.com/downloads). 7 | 8 | 2. **Node.js:** The project is built using Node.js. You can download and install Node.js from [Node.js Downloads](https://nodejs.org/en/download/). Make sure to install a LTS (Long Term Support) version. 9 | 10 | 3. **npm (Node Package Manager):** npm is usually bundled with Node.js. To check if you have npm installed, run the following command in your terminal: `npm -v` 11 | 12 | 4. If it's not installed, you can update it using the following command: `npm install -g npm` 13 | 14 | 15 | ## Local Setup 16 | 17 | Follow these steps to set up the "minimalcommit" project locally on your machine: 18 | 19 | 1. **Fork the Repository:** 20 | To set up a working development environment, just fork the project git repository. 21 | 22 | 2. **Clone the Repository:** 23 | Open your terminal and navigate to the directory where you want to store the project. Then, run the following command to clone the repository: `git clone https://github.com/yourusername/minimalcommit.git` 24 | 25 | 26 | 3. **Change Directory:** 27 | Navigate into the project directory: `cd minimalcommit` 28 | 29 | 4. **Install Dependencies:** 30 | Use npm to install the project's dependencies: `npm install` 31 | 32 | 5. **Testing the Project:** 33 | 34 | There are two ways to test the project: 35 | 36 | - **Run the CLI :** You can test the project by running the CLI using the following command: 37 | ``` 38 | node src/cli.js 39 | ``` 40 | 41 | - **Link the Project Locally:** To test the project locally as a global command, you can use the `npm link` command. First, navigate to the project directory and run the following command: 42 | ``` 43 | npm link minimalcommit 44 | ``` 45 | After linking the project, you can use it as a global command. 46 | 47 | That's it! You now have the "minimalcommit" Node.js project set up locally on your machine, and you can start working on it according to the provided instructions. 48 | 49 | 50 | To contribute to minimal commit, please follow these guidelines when working on issues: 51 | 52 | ## Check for Existing Issues 53 | Before you start working on any feature, enhancement, or bug fix, it's important to check if there's an existing issue for it. This helps prevent duplicate work and ensures that the issue is still relevant. 54 | 55 | ## Create an Issue 56 | If you cannot find an existing issue related to the task you want to work on, please create a new issue. A well-documented issue should include the following information: 57 | 58 | - A clear and concise title that describes the problem or feature. 59 | - A detailed description of the issue, including steps to reproduce it if it's a bug. 60 | - The version of the software the issue is related to. 61 | - Any relevant screenshots or code examples. 62 | - Any additional context that might be helpful in understanding the issue. 63 | 64 | ## Request Ownership of the Issue 65 | If you find an existing issue that you'd like to work on and it has not been assigned to anyone, you can request ownership of the issue. 66 | 67 | Here's how to do it: 68 | 69 | - Comment on the issue expressing your interest. 70 | - Mention how you would like to approach the issue 71 | - Wait for a response from the maintainers of the project. 72 | 73 | ## Next Steps 74 | Once the issue is assigned to you, it's time to start working on it. Make sure to adhere to our coding and documentation standards. Keep your assigned issue updated with your progress and any challenges you encounter. If you're unable to continue working on the issue for any reason, please let us know as soon as possible. 75 | 76 | ## Request to Work on Stalled Issues 77 | If an issue has been assigned to someone else and there have been no updates or activity for more than a week, you may request to work on it. This helps keep the project moving and ensures that issues are not left unattended for extended periods. 78 | 79 | To request to work on a stalled issue: 80 | 81 | - Comment on the issue, expressing your interest and the reason you believe it's stalled. 82 | - Wait for a response from the maintainers. They will assess the situation and may reassign the issue to you if the original assignee is unresponsive. 83 | 84 | Thank you for your contributions and for helping us make this project better. Your dedication and collaboration are greatly appreciated! 85 | -------------------------------------------------------------------------------- /src/cli.js: -------------------------------------------------------------------------------- 1 | import inquirer from "inquirer"; 2 | import chalk from "chalk"; 3 | 4 | import { 5 | commitFiles, 6 | getStagedFiles, 7 | checkIfRepoisGit, 8 | getUnstagedFiles, 9 | stageFiles, 10 | } from "./commands.js"; 11 | 12 | function logOption(title, description) { 13 | return chalk.bgWhite(title) + " - " + description; 14 | } 15 | 16 | async function cli() { 17 | const [isGit, stagedFiles] = await Promise.all([ 18 | checkIfRepoisGit(), 19 | getStagedFiles(), 20 | ]); 21 | if (isGit && !stagedFiles) { 22 | await promptToCommit(); 23 | } else if (isGit && stagedFiles) { 24 | if (process.argv[2] === "--help" || process.argv[2] === "-h") { 25 | const options = [ 26 | { name: "--help , -h", desc: "Show help", type: "boolean" }, 27 | { name: "--version, -v", desc: "Show version number", type: "boolean" }, 28 | { name: "--types, -t", desc: "Show commit types", type: "boolean" }, 29 | ]; 30 | console.log("Command\t\tDescription\t\tType"); 31 | console.log("-------\t\t-----------\t\t----"); 32 | options.forEach((option) => { 33 | const { name, desc, type } = option; 34 | console.log(`${name.padEnd(16)}${desc.padEnd(24)}${type}`); 35 | }); 36 | console.log("\n"); 37 | process.exit(0); 38 | } else { 39 | await addCommit(); 40 | } 41 | } 42 | } 43 | 44 | const promptToCommit = async () => { 45 | const files = await getUnstagedFiles(); 46 | if (files.trim().length === 0) { 47 | console.log(chalk.bgRed("⛔️ Whops! You haven't made any changes.")); 48 | process.exit(0); 49 | } 50 | const styledList = files 51 | .trim() 52 | .split("\n") 53 | .map((file) => { 54 | /* 55 | Possible States 56 | 57 | ??: Untracked 58 | A: Added 59 | M: Modified 60 | D: Deleted 61 | R: Renamed 62 | C: Copied 63 | U: Updated but unmerged 64 | !: Git doesn't know about the file or folder (it's not in the repository) 65 | */ 66 | const fileName = file.trim(); 67 | if (fileName.startsWith("??")) return fileName.replace("??", "🆕"); 68 | if (fileName.startsWith("A")) return fileName.replace("A", "📝"); 69 | if (fileName.startsWith("M")) return fileName.replace("M", "🔄️"); 70 | if (fileName.startsWith("D")) return fileName.replace("D", "🗑️"); 71 | if (fileName.startsWith("R")) return fileName.replace("R", "🔄️"); 72 | if (fileName.startsWith("C")) return fileName.replace("C", "📝"); 73 | if (fileName.startsWith("U")) return fileName.replace("U", "⚠️"); 74 | if (fileName.startsWith("!")) return fileName.replace("!", "❓"); 75 | return fileName; 76 | }); 77 | if (styledList.length < 1) { 78 | console.log(chalk.bgRed("No changes made since last commit!")); 79 | } 80 | return await inquirer 81 | .prompt([ 82 | { 83 | name: "list", 84 | message: 85 | "Select the files you want to add with, and use (CTRL + D to exit)", 86 | type: "checkbox", 87 | choices: styledList, 88 | }, 89 | ]) 90 | .then((answer) => { 91 | if (answer.list.length < 1) { 92 | console.log(chalk.bgRed("⛔️ Oops, You forgot to select files")); 93 | process.exit(0); 94 | } 95 | const filesToStage = answer.list.map((f) => { 96 | if (f.startsWith("🆕")) return f.replace("🆕", "").trim(); 97 | if (f.startsWith("📝")) return f.replace("📝", "").trim(); 98 | if (f.startsWith("🔄️")) return f.replace("🔄️", "").trim(); 99 | if (f.startsWith("🗑️")) return f.replace("🗑️", "").trim(); 100 | if (f.startsWith("🔄️")) return f.replace("🔄️", "").trim(); 101 | if (f.startsWith("📝")) return f.replace("📝", "").trim(); 102 | if (f.startsWith("⚠️")) return f.replace("⚠️", "").trim(); 103 | if (f.startsWith("❓")) return f.replace("❓", "").trim(); 104 | }); 105 | stageFiles(filesToStage.join(" ")); 106 | }) 107 | .then(() => { 108 | console.log(chalk.bgGreenBright("✅ Files Added")); 109 | addCommit(); 110 | }) 111 | .catch((err) => { 112 | console.log( 113 | chalk.bgRed("⛔️ Oops, that was not supposed to happen") + 114 | chalk.bgGrey("If that happens again, please raise an issue") 115 | ); 116 | process.exit(0); 117 | }); 118 | }; 119 | 120 | const addCommit = async () => { 121 | return await inquirer 122 | .prompt([ 123 | { 124 | name: "type", 125 | message: "Howdy 👋, What type of changes have you made?", 126 | type: "list", 127 | choices: [ 128 | "✨ feat", 129 | "🐛 fix", 130 | "💥 break", 131 | "♻️ ref", 132 | "🧪 test", 133 | "🔖 ver", 134 | "📝 docs", 135 | "🎨 style", 136 | "🛠 config", 137 | "📦 misc", 138 | ], 139 | }, 140 | { 141 | name: "message", 142 | message: "Write a commit message ✍️ : ", 143 | type: "input", 144 | }, 145 | ]) 146 | .then((answer) => { 147 | const message = `${answer.type}: ${answer.message}`; 148 | console.log("\n"); 149 | 150 | if (answer.message == "") { 151 | console.log(chalk.bgRed("⛔️ Message can't be empty")); 152 | process.exit(0); 153 | } else if (!answer.message.includes(" ")) { 154 | console.log(chalk.bgRed("⛔️ Message is too short")); 155 | process.exit(0); 156 | } 157 | // it includes the prefix as well 158 | console.log(message, message.length); 159 | if (message.length > 72) { 160 | console.log( 161 | chalk.bgRed("⛔️ Message is too long") + 162 | "\n" + 163 | chalk.bgYellow("⚠️ Please keep the message below 72 characters") 164 | ); 165 | process.exit(0); 166 | } 167 | 168 | commitFiles(message); 169 | }); 170 | if (message.argv[2] === "--help" || message.argv[2] === "-h") { 171 | console.log("Command\t\t\tDescription\t\tType"); 172 | console.log("-------\t\t\t-----------\t\t----"); 173 | console.log("--help, -h\t\tShow help\t\tBoolean"); 174 | console.log("--version, -v\t\tShow version number\tBoolean"); 175 | console.log("--types, -t\t\tShow commit types\tBoolean"); 176 | console.log("\n"); 177 | process.exit(0); 178 | } 179 | }; 180 | 181 | export default cli; 182 | --------------------------------------------------------------------------------