Skip to content

指南:使用提示

¥Guide: Use prompt

@commitlint/prompt-cli 有助于快速编写提交消息,并确保它们遵循 commitlint.config.js 中配置的提交约定。

¥@commitlint/prompt-cli helps with fast authoring of commit messages and ensures they adhere to the commit convention configured in commitlint.config.js.

安装

¥Install

  1. 如果需要,创建一个 git 存储库

    ¥Create a git repository if needed

    sh
    git init
  2. 如果需要,创建一个 package.json 文件

    ¥Create a package.json if needed

    sh
    npm init
  3. 如果需要,请安装并配置

    ¥Install and configure if needed

    sh
    npm install --save-dev @commitlint/cli @commitlint/config-conventional @commitlint/prompt-cli
    
    echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

提供快捷方式

¥Provide a shortcut

为了使 prompt-cli 易于使用,请在你的 package.json 中添加一个 npm run-script。

¥To make prompt-cli easy to use, add a npm run-script to your package.json

json
{
  "scripts": {
    "commit": "commit"
  }
}

通过执行以下命令测试提示

¥Test the prompt by executing

bash
git add .
npm run commit

@commitlint/prompt-cli 的替代方案:commitizen

¥An alternative to @commitlint/prompt-cli: commitizen

另一种编写符合 commitlint.config.js 中配置的提交约定的提交消息的方法是使用 commitizen。有关更多信息,请查看他们的 官方网站

¥Another way to author commit messages that adhere to the commit convention configured in commitlint.config.js is to use commitizen. For more information, checkout their official website.

commitlint 为 commitizen 提供了两个适配器:

¥commitlint provides two adapters for commitizen:

  1. @commitlint/prompt 提供与 @commitlint/prompt-cli 相同的交互方式。

    ¥@commitlint/prompt provides a way to interact same as @commitlint/prompt-cli

  2. @commitlint/cz-commitlintcz-conventional-changelog 启发,提供了一种更现代的交互方式。

    ¥@commitlint/cz-commitlint is inspired by cz-conventional-changelog, it provides a more modern way to interact.