cz-cubics

中文文档
0.0.12发布于 2026/11/03MITTypeScriptCommonJS构建来源已验证

A customizable Commitizen adapter

原始使用文档
文档目录13 节
  1. Installation
  2. Configuration
  3. Config file shape
  4. CZCubicsConfig
  5. CZCubicsCommitType
  6. headFormat tokens ( CZCubicsHeaderTokens )
  7. Example .czrc
  8. Commit message structure
  9. commitlint integration
  10. Requirements
  11. Husky hook
  12. License
  13. Special Thanks

cz-cubics

A customizable Commitizen adapter with emoji-prefixed conventional commit messages, plus a ready-to-extend commitlint config.

Commitizen friendly npm bundle size

Installation

pnpm add -D cz-cubics commitizen

Register it as your Commitizen adapter in package.json:

{
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-cubics"
    }
  }
}

or in .czrc:

{
  "path": "./node_modules/cz-cubics"
}

Then commit with:

pnpm commit

(assuming a "commit": "cz" script, or run commitizen/git cz directly)

Configuration

Config is resolved from the nearest of the following files, searched via find-up in this order:

  1. .czrc
  2. package.json

The first matching file that contains a config["cz-cubics"] key wins if both exist, .czrc takes precedence.

Config file shape

.czrc

{
  "config": {
    "cz-cubics": {
      "headFormat": "{type}{scope}: {subject}"
    }
  }
}

package.json

{
  "config": {
    "commitizen": {
      "path": "node_modules/cz-cubics"
    },
    "cz-cubics": {
      "headFormat": "{type}{scope}: {subject}"
    }
  }
}

Note cz-cubics sits as a sibling of commitizen under config, not nested inside it.

Custom configurations will be validated, invalid types, unknown skipQuestions values, or unrecognized {token}s in headFormat throws errors, rather than failing silently or on the first issue.

CZCubicsConfig

PropertyTypeDefaultDescription
typesCZCubicsCommitType[]contents of defaultTypes.jsonThe list of commit types offered to the user.
skipQuestionsstring[][]Skip any of: scope, body, issues, breaking. type and subject are mandatory and cannot be skipped.
scopesstring[]-Predefined scope choices (Inquirer.js choices array) shown in the scope autocomplete prompt.
questionsObject-Overrides for the generated Inquirer questions.
subjectMaxLengthnumber100Maximum allowed length of the subject line.
headFormatstring"{emoji} {type}{scope}: {subject}"Template for the commit header. Supports the tokens below.

CZCubicsCommitType

Each entry in types (and in defaultTypes.json) has the shape:

{
  "name": "feat",
  "emoji": "✨",
  "description": "A new feature"
}
PropertyTypeDefaultDescription
namestring-The conventional commit type keyword (e.g. feat, fix).
emojistring""Emoji shown next to the type and inserted into the header via {emoji}.
descriptionstring-Explanatory text shown in the type selection prompt.

headFormat tokens (CZCubicsHeaderTokens)

TokenResolves to
{emoji}The selected type's emoji.
{type}The selected type's name.
{scope}(scope) if a scope was entered, otherwise empty.
{subject}The trimmed subject line.

Any run of consecutive whitespace left behind by an omitted token (e.g. no scope) is collapsed to a single space.

Example .czrc

{
  "config": {
    "cz-cubics": {
      "types": [
        { "name": "feat", "emoji": "✨", "description": "A new feature" },
        { "name": "fix", "emoji": "🐛", "description": "A bug fix" }
      ],
      "scopes": ["api", "ui", "docs"],
      "skipQuestions": ["issues", "breaking"],
      "subjectMaxLength": 72,
      "headFormat": "{emoji} {type}{scope}: {subject}"
    }
  }
}

Commit message structure

The final message is assembled as:

<head>

<body>

BREAKING CHANGE: <breakingBody>

<footer (issues)>
  • head => built from headFormat, truncated to the terminal's column width.
  • body => the free-text body answer, wrapped to the terminal width. Newline can be added by using a pipe |
  • breaking => included only if a breaking change body was provided. Newline can be added by using a pipe |
  • footer => issue references, formatted via formatIssues.

Empty sections are omitted; the result is trimmed of trailing whitespace.

commitlint integration

This package ships its own commitlint.config.js, which consumers can extend directly instead of duplicating rules:

/** @type {import("@commitlint/types").UserConfig} */
module.exports = {
  extends: ["./node_modules/cz-cubics/commitlint.config.js"],
  // add or override rules here
};

when the type in package.json is "module" the cjs version can be used instead

/** @type {import("@commitlint/types").UserConfig} */
module.exports = {
  extends: ["./node_modules/cz-cubics/commitlint.config.cjs"],
  // add or override rules here
};

It includes:

  • type-empty: never,
  • subject-empty: never,
  • subject-case: sentence-case, always enforced.
  • subject-max-length: 100, always enforced, taken from your resolved subjectMaxLength config.
  • type-enum: restricted to the name of each entry in your resolved types config, so only your configured commit types pass.
  • header-start-emoji: always enforced the header must start with an Extended_Pictographic character (an emoji), matching the leading {emoji} token in headFormat.
  • header-has-emoji: off by default (severity 0) same emoji detection, but checks the entire header line rather than just the leading token. Enable it (severity 2) with "always" if you want emoji allowed anywhere in the header rather than only at the start.
  • A parserPreset whose headerPattern and headerCorrespondence are built dynamically from your resolved headFormat, rather than hardcoded. This means:
    • Changing headFormat in your config automatically changes what the linter parses and validates.
    • Required tokens ({type}, {subject}) use a matching strategy that still lets the overall header parse successfully even when one of them is empty
    • Optional tokens ({emoji}, {scope}) are correctly treated as absent when omitted, rather than requiring a placeholder value.

Requirements

cz-cubics/commitlint.config.js is a plain config object with no runtime dependency on any commitlint package itself. However, to actually lint commits you need @commitlint/cli installed in your own project, since that's what reads and executes the config:

pnpm add -D @commitlint/cli

Husky hook

Wire it up in .husky/commit-msg:

pnpm commitlint --edit "$1"

Make sure the hook file is executable (chmod +x .husky/commit-msg) and that core.hooksPath points at .husky (set automatically by the prepare: "husky" script).

License

MIT

Special Thanks

版本与发布记录

cz-cubics 共发布 12 个版本,首次发布于 2026/09/01;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.12latest2026/11/03今天
0.0.112026/11/03今天
0.0.102026/09/051 个月前
0.0.92026/09/051 个月前
0.0.82026/09/032 个月前
0.0.72026/09/032 个月前

关于 cz-cubics 的常见问题

cz-cubics 是什么?

可定制的commizen适配器

如何安装 cz-cubics?

在项目目录运行 npm install cz-cubics,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:commitizen(^4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

cz-cubics 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

cz-cubics 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

cz-cubics 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

cz-cubics 可以商用吗?

cz-cubics 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

cz-cubics 还在维护吗?

最新版本 0.0.12 发布于 2026/11/03(今天);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/09/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。