1.2.4 • Published 9 months ago

cnb v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

šŸš€ Create New Branch

✨ cnb is a simple and customizable CLI tool that helps you create Git branches following naming conventions, and validates (lints) branch names to ensure they follow the configured conventions.

šŸŽ¬ Demo

cnb

šŸ“¦ Installation

Install the package as a dev dependency:

npm i -D cnb

šŸ› ļø Usage

Creating a New Branch

  1. Add the following alias to your .gitconfig:
[alias]
cnb = "!npx cnb"
  1. Add the following script to your package.json:
"scripts": {
	"prepare": "git config --local include.path ../.gitconfig",
}
  1. Make sure the prepare script runs before trying the new git alias. You can do this by running (only once):
npm i

Or explicitly run the script:

npm run prepare
  1. Run the following command to create a new branch with naming conventions:
git cnb

This will prompt you with a set of options to choose from (e.g., feat, fix, chore, etc.). You'll also provide a short description that will be formatted into kebab-case.

Example:

  • Selected type: feat
  • Description: configure notifications

The branch created will be: feat/configure-notifications.

If your configuration requires a ticket ID (based on your config file), the flow will prompt you to enter that first.

Linting a Branch Name

You can also use cnb to lint and validate if the current branch name follows your configured conventions.

  1. Add the following script to your package.json:
"scripts": {
	"cnb:check": "cnb --check"
}
  1. Run the script to lint the current branch name:
npm run cnb:check

šŸ“ Configuration

You can customize the behavior of cnb by creating a configuration file in your project root called cnb.config.ts (for ES6 environments) or cnb.config.cjs (for CommonJS environments).

Configuration Options

OptionTypeDescriptionDefault
branchTypesstring[]The types of branches you can select (e.g., feat, fix, chore, style)['feat', 'fix', 'chore', 'style']
maxDescriptionLengthnumberThe maximum length allowed for the branch description.20
skipTicketIdbooleanWhether to skip the ticket ID prompt.false
ticketIdPrefixstringThe prefix to add to the ticket ID (e.g., JIRA-).T-
separatorstringThe character(s) used to separate the ticket ID, branch type, and branch name (e.g., /, _)./

Example cnb.config.ts (ES6)

import type { CnbConfig } from 'cnb';

const config: CnbConfig = {
	branchTypes: ['feat', 'fix', 'chore', 'style'],
	maxDescriptionLength: 20,
	skipTicketId: false,
	ticketIdPrefix: 'JIRA-',
};

export default config;

Example cnb.config.cjs (CommonJS)

module.exports = {
	branchTypes: ['feat', 'fix', 'chore', 'style'],
	maxDescriptionLength: 20,
	skipTicketId: false,
	ticketIdPrefix: 'JIRA-',
};

šŸ› ļø Note for ES6 vs. CommonJS Users

  • For ES6 users: Create your configuration file as cnb.config.ts and use export default.
  • For CommonJS users: Create your configuration file as cnb.config.cjs and use module.exports.

šŸ‘„ Authors

šŸ“„ License

MIT

1.2.4

9 months ago

1.2.3

9 months ago

1.2.2

9 months ago

1.2.1

9 months ago

1.2.0

9 months ago

1.1.10

9 months ago

1.1.9

9 months ago

1.1.8

9 months ago

1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.1-develop.1

6 years ago

0.0.1-develop.0

6 years ago