@ commitlint/ config-nx- specons
启动您的 nx 工程
可分享 commitlint 配置执行 nx 项目和工作空间名称为范围 .
使用方式 @ commitlint/ cli (中文(简体) ) 财务报告和审定财务报表 @ commitlint/ prompt- cli (中文(简体) )。 。 。 .
范围从 nx 项目图读取, 因此一个 nx 插件贡献的项目是
有效范围,即使没有 project.json 或者说 package.json 属于自己的.
开始
npm install --save-dev @commitlint/config-nx-scopes @commitlint/cli
echo "module.exports = {extends: ['@commitlint/config-nx-scopes']};" > commitlint.config.js
过滤工程
您可以通过提供过滤函数作为第二个参数来过滤工程 getProjects()。该函数将使用包含每个工程的对象来调用 name, (中文(简体) ), projectType,以及 tags简单返回布尔以表示项目是否应列入.
举例来说,以下代码演示了如何只选择不是端到端测试的应用程序.
在您的 . committlint.js 文件中 :
async function getConfig() {
const {
default: {
utils: { getProjects },
},
} = await import("@commitlint/config-nx-scopes");
return {
rules: {
"scope-enum": async (ctx) => [
2,
"always",
[
...(await getProjects(
ctx,
({ name, projectType }) => !name.includes("e2e") && projectType == "application",
)),
],
],
},
// . . .
};
}
module.exports = getConfig();
以下是另一个例子,其中标有“阶段:报废”的项目不得用作承诺的范围.
在您的 . committlint.js 文件中 :
async function getConfig() {
const {
default: {
utils: { getProjects },
},
} = await import("@commitlint/config-nx-scopes");
return {
rules: {
"scope-enum": async (ctx) => [
2,
"always",
[...(await getProjects(ctx, ({ tags }) => !tags.includes("stage:end-of-life")))],
],
},
// . . .
};
}
module.exports = getConfig();
实例
❯ cat commitlint.config.js
{
extends: ['@commitlint/config-nx-scopes']
}
❯ tree packages
packages
├── api
├── app
└── web
❯ echo "build(api): change something in api's build" | commitlint
❯ echo "test(foo): this won't pass" | commitlint
⧗ --- input ---
test(foo): this won't pass
✖ scope must be one of [api, app, web] [scope-enum]
✖ found 1 problems, 0 warnings
❯ echo "ci: do some general maintenance" | commitlint
咨询 规则参考 用于列出现有规则.