@ruan-cat/commitlint-config
Version:
阮喵喵自用的 commitlint.config.cjs 配置。
361 lines (353 loc) • 14.4 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => index_default,
getUserConfig: () => getUserConfig
});
module.exports = __toCommonJS(index_exports);
// ../../node_modules/.pnpm/tsup@8.5.0_@microsoft+api-extractor@7.52.8_@types+node@22.15.34__jiti@2.4.2_postcss@8.5.6_tsx_fnja4vux7ox3o7scyevzjr435i/node_modules/tsup/assets/cjs_shims.js
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
// src/index.ts
var import_node_path = require("path");
var import_node_url = require("url");
var fs = __toESM(require("fs"), 1);
var import_glob = require("glob");
var import_js_yaml = require("js-yaml");
var import_consola = require("consola");
var import_lodash = require("lodash");
// src/config.ts
var config = {
rules: {
// @see: https://commitlint.js.org/#/reference-rules
},
prompt: {
alias: { fd: "docs: fix typos" },
messages: {
type: "\u9009\u62E9\u4F60\u8981\u63D0\u4EA4\u7684\u7C7B\u578B :",
scope: "\u9009\u62E9\u4E00\u4E2A\u63D0\u4EA4\u8303\u56F4\uFF08\u53EF\u9009\uFF09:",
customScope: "\u8BF7\u8F93\u5165\u81EA\u5B9A\u4E49\u7684\u63D0\u4EA4\u8303\u56F4 :",
subject: "\u586B\u5199\u7B80\u77ED\u7CBE\u70BC\u7684\u53D8\u66F4\u63CF\u8FF0 :\n",
body: '\u586B\u5199\u66F4\u52A0\u8BE6\u7EC6\u7684\u53D8\u66F4\u63CF\u8FF0\uFF08\u53EF\u9009\uFF09\u3002\u4F7F\u7528 "|" \u6362\u884C :\n',
breaking: '\u5217\u4E3E\u975E\u517C\u5BB9\u6027\u91CD\u5927\u7684\u53D8\u66F4\uFF08\u53EF\u9009\uFF09\u3002\u4F7F\u7528 "|" \u6362\u884C :\n',
footerPrefixesSelect: "\u9009\u62E9\u5173\u8054issue\u524D\u7F00\uFF08\u53EF\u9009\uFF09:",
customFooterPrefix: "\u8F93\u5165\u81EA\u5B9A\u4E49issue\u524D\u7F00 :",
footer: "\u5217\u4E3E\u5173\u8054issue (\u53EF\u9009) \u4F8B\u5982: #31, #I3244 :\n",
confirmCommit: "\u662F\u5426\u63D0\u4EA4\u6216\u4FEE\u6539commit ?"
},
/**
* 基于monorepo内项目,决定提交范围域
*
* 该配置可以用 getUserConfig 函数设置
*/
// scopes,
// https://cz-git.qbb.sh/zh/recipes/#多选模式
enableMultipleScopes: true,
scopeEnumSeparator: ",",
allowCustomScopes: true,
allowEmptyScopes: true,
customScopesAlign: "bottom",
customScopesAlias: "custom",
emptyScopesAlias: "empty",
types: [
{ value: "\u2728 feat", name: "\u2728 feat: \u65B0\u589E\u529F\u80FD | A new feature" },
{ value: "\u{1F41E} fix", name: "\u{1F41E} fix: \u4FEE\u590D\u7F3A\u9677 | A bug fix" },
{ value: "\u{1F4C3} docs", name: "\u{1F4C3} docs: \u6587\u6863\u66F4\u65B0 | Documentation only changes" },
{ value: "\u{1F9EA} test", name: "\u{1F9EA} test: \u6D4B\u8BD5\u76F8\u5173 | Adding missing tests or correcting existing tests" },
{
value: "\u{1F527} build",
name: "\u{1F527} build: \u6784\u5EFA\u76F8\u5173 | Changes that affect the build system or external dependencies"
},
{ value: "\u{1F40E} ci", name: "\u{1F40E} ci: \u6301\u7EED\u96C6\u6210 | Changes to our CI configuration files and scripts" },
{ value: "\u{1F4E2} publish", name: "\u{1F4E2} publish: \u53D1\u5305 | \u4F9D\u8D56\u5305\u53D1\u5E03\u7248\u672C\u3002" },
{
value: "\u{1F984} refactor",
name: "\u{1F984} refactor: \u4EE3\u7801\u91CD\u6784 | A code change that neither fixes a bug nor adds a feature"
},
{ value: "\u{1F388} perf", name: "\u{1F388} perf: \u6027\u80FD\u63D0\u5347 | A code change that improves performance" },
{ value: "\u{1F389} init", name: "\u{1F389} init: \u521D\u59CB\u5316 | \u9879\u76EE\u521D\u59CB\u5316\u3002" },
{ value: "\u2699\uFE0F config", name: "\u2699\uFE0F config: \u66F4\u65B0\u914D\u7F6E | \u914D\u7F6E\u66F4\u65B0\u3002\u901A\u7528\u6027\u7684\u914D\u7F6E\u66F4\u65B0\u3002" },
{ value: "\u{1F433} chore", name: "\u{1F433} chore: \u5176\u4ED6\u4FEE\u6539 | Other changes that do not modify src or test files" },
{ value: "\u21A9 revert", name: "\u21A9 revert: \u56DE\u9000\u4EE3\u7801 | Revert to a commit" },
{ value: "\u{1F5D1} del", name: "\u{1F5D1} del: \u5220\u9664\u5783\u573E | \u5220\u9664\u65E0\u610F\u4E49\u7684\u4E1C\u897F\uFF0C\u6CE8\u91CA\uFF0C\u6587\u4EF6\uFF0C\u4EE3\u7801\u6BB5\u7B49\u3002" },
{ value: "\u{1F310} i18n", name: "\u{1F310} i18n: \u56FD\u9645\u5316 | \u4E13\u95E8\u8BBE\u7F6E\u56FD\u9645\u5316\u7684\u7FFB\u8BD1\u6587\u672C\u3002" },
{ value: "\u{1F308} style", name: "\u{1F308} style: \u4EE3\u7801\u683C\u5F0F | Changes that do not affect the meaning of the code" },
{
value: "\u{1F914} save-file",
name: "\u{1F914} save-file: \u4FDD\u5B58\u6587\u4EF6 | \u6587\u4EF6\u4FDD\u5B58\u7C7B\u578B\u3002\u4EC5\u4EC5\u662F\u4E3A\u4E86\u4FDD\u5B58\u6587\u4EF6\u3002\u6709\u65F6\u5019\u4F1A\u9700\u8981\u7D27\u6025\u63D0\u4EA4\uFF0C\u5E76\u5FEB\u901F\u5207\u6362\u5206\u652F\u3002\u6B64\u65F6\u5C31\u9700\u8981\u63D0\u4EA4\u4EE3\u7801\u3002\u5E76\u4FDD\u5B58\u6587\u4EF6\u3002"
},
{ value: "\u270B main-pull-update", name: "\u270B main-pull-update: \u4E3B\u5206\u652F\u62C9\u53D6\u66F4\u65B0 | \u4E3B\u5206\u652F\u62C9\u53D6\u66F4\u65B0\u3002" },
{ value: "\u23E9 mark-progress", name: "\u23E9 mark-progress: \u6807\u8BB0\u8FDB\u5EA6 | \u6807\u8BB0\u8FDB\u5EA6\u3002" }
],
useEmoji: true,
emojiAlign: "center",
useAI: false,
aiNumber: 1,
themeColorCode: "",
upperCaseSubject: false,
/** 允许使用破坏性变更的标记 */
markBreakingChangeMode: true,
allowBreakingChanges: ["feat", "fix"],
breaklineNumber: 100,
breaklineChar: "|",
skipQuestions: [],
issuePrefixes: [
// 如果使用 gitee 作为开发管理
{ value: "link", name: "link: \u94FE\u63A5 ISSUES \u8FDB\u884C\u4E2D" },
{ value: "closed", name: "closed: \u6807\u8BB0 ISSUES \u5DF2\u5B8C\u6210" }
],
customIssuePrefixAlign: "top",
emptyIssuePrefixAlias: "skip",
customIssuePrefixAlias: "custom",
allowCustomIssuePrefix: true,
allowEmptyIssuePrefix: true,
confirmColorize: true,
scopeOverrides: void 0,
defaultBody: "",
defaultIssues: "",
defaultScope: "",
defaultSubject: ""
}
};
// src/index.ts
var import_node_cjs = require("@ruan-cat/utils/node-cjs");
// src/common-scopes.ts
var commonScopes = [
{
code: "config",
value: "config",
desc: "\u5404\u79CD\u914D\u7F6E\u6587\u4EF6"
},
{
code: "turbo",
value: "turbo",
desc: "\u4EFB\u52A1\u8C03\u5EA6\u5668"
},
{
code: "root",
value: "root",
desc: "\u6839\u76EE\u5F55"
},
{
code: "package.json",
value: "package.json",
desc: "\u5305\u914D\u7F6E"
},
{
code: "vite.config.js/ts",
value: "vite",
desc: "vite\u6253\u5305\u5DE5\u5177\u914D\u7F6E"
},
{
code: "vitepress",
value: "\u6587\u6863\u914D\u7F6E",
desc: "vitepress\u6587\u6863\u5DE5\u5177\u914D\u7F6E"
},
{
code: "commitlint.config.cjs",
value: "commitlint",
desc: "cz\u914D\u7F6E\uFF0C\u5373git\u63D0\u4EA4\u5DE5\u5177\u7684\u914D\u7F6E"
},
{
code: "tsconfig",
value: "tsc",
desc: "typescript\u9879\u76EE\u914D\u7F6E"
},
{
code: "router",
value: "router",
desc: "\u8DEF\u7531\u914D\u7F6E"
},
{
code: "vscode/settings.json",
value: "vsc",
desc: "vscode\u914D\u7F6E"
},
{
code: "i18n",
value: "i18n",
desc: "\u56FD\u9645\u5316"
},
{
code: "prompt",
value: "prompt",
desc: "\u63D0\u793A\u8BCD\u3002\u7279\u6307\u548CAI\u534F\u4F5C\u4F7F\u7528\u7684\u63D0\u793A\u8BCD\u6587\u4EF6\u3002"
},
{
code: "api",
value: "api",
desc: "API\u63A5\u53E3"
}
];
// src/index.ts
var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
var __dirname = (0, import_node_path.dirname)(__filename2);
function isScopesTypeItem(item) {
return (0, import_node_cjs.isConditionsEvery)([
//
() => !(0, import_lodash.isNil)(item),
() => (0, import_lodash.isPlainObject)(item),
() => Object.hasOwn(item, "name")
]);
}
function isScopesItemWithDesc(item) {
return (0, import_node_cjs.isConditionsEvery)([
() => !(0, import_lodash.isNil)(item),
() => (0, import_lodash.isPlainObject)(item),
() => Object.hasOwn(item, "code"),
() => Object.hasOwn(item, "value"),
() => Object.hasOwn(item, "desc")
]);
}
function ScopesItemWithDesc_To_ScopesTypeItem(item) {
return {
name: `${item.code} | ${item.desc}`,
value: item.value
};
}
var defScopes = [
{
name: "root | \u6839\u76EE\u5F55",
value: "root"
},
{
name: "utils | \u5DE5\u5177\u5305",
value: "utils"
},
{
name: "demo | \u6D4B\u8BD5\u9879\u76EE",
value: "demo"
}
];
function createLabelName(packageJson) {
const { name, description } = packageJson;
const noneDesc = `\u8BE5\u4F9D\u8D56\u5305\u6CA1\u6709\u63CF\u8FF0\u3002`;
const desc = (0, import_lodash.isUndefined)(description) ? noneDesc : description;
return `${name ?? "bug\uFF1A\u6781\u7AEF\u60C5\u51B5\uFF0C\u8FD9\u4E2A\u5305\u6CA1\u6709\u914D\u7F6Ename\u540D\u79F0"} >>|>> ${desc}`;
}
function createPackagescopes(packageJson) {
const { name } = packageJson;
const names = name == null ? void 0 : name.split("/");
const packageNameWithBusiness = (names == null ? void 0 : names.length) > 1 ? names == null ? void 0 : names[1] : names == null ? void 0 : names[0];
return `${packageNameWithBusiness}`;
}
function getPackagesNameAndDescription() {
const workspaceConfigPath = (0, import_node_path.join)(process.cwd(), "pnpm-workspace.yaml");
if (!fs.existsSync(workspaceConfigPath)) {
return defScopes;
}
const workspaceFile = fs.readFileSync(workspaceConfigPath, "utf8");
const workspaceConfig = (0, import_js_yaml.load)(workspaceFile);
const pkgPatterns = workspaceConfig.packages;
if ((0, import_lodash.isUndefined)(pkgPatterns)) {
return defScopes;
}
let pkgPaths = [];
pkgPatterns.map((pkgPattern) => {
const matchedPath = (0, import_node_cjs.pathChange)((0, import_node_path.join)(process.cwd(), pkgPattern, "package.json"));
const matchedPaths = (0, import_glob.sync)(matchedPath, {
ignore: "**/node_modules/**"
});
pkgPaths = pkgPaths.concat(...matchedPaths);
return matchedPaths;
});
const czGitScopesType = pkgPaths.map(function(pkgJsonPath) {
if (fs.existsSync(pkgJsonPath)) {
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
return {
// 标签名称 对外展示的标签名称
name: createLabelName(pkgJson),
// 取值
value: createPackagescopes(pkgJson)
};
}
return {
name: "\u8B66\u544A\uFF0C\u6CA1\u627E\u5230\u5305\u540D\uFF0C\u8BF7\u67E5\u770B\u8FD9\u4E2A\u5305\u8DEF\u5F84\u662F\u4E0D\u662F\u6545\u969C\u4E86\uFF1A",
value: "pkgJsonPath"
};
});
return czGitScopesType;
}
function getInitScopes() {
let scopes = defScopes;
scopes = getPackagesNameAndDescription();
return scopes;
}
function setScopesInUserConfig(params) {
const { scopes, userConfig } = params;
userConfig.prompt.scopes = scopes;
}
function getUserConfig(params = {}) {
const {
userScopes = defScopes,
config: config2 = {
isPrintScopes: true
}
} = params;
const item = userScopes == null ? void 0 : userScopes[0];
let userScopesInScopesTypeItem = [];
if (!(0, import_lodash.isNil)(item)) {
if (isScopesTypeItem(item)) {
userScopesInScopesTypeItem = userScopes;
} else if (isScopesItemWithDesc(item)) {
userScopesInScopesTypeItem = userScopes.map(ScopesItemWithDesc_To_ScopesTypeItem);
} else {
throw new Error("userScopes \u7684\u7C7B\u578B\u4E0D\u6B63\u786E\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E\u3002");
}
}
const commonScopesInScopesTypeItem = commonScopes.map(ScopesItemWithDesc_To_ScopesTypeItem);
const initScopes = getInitScopes();
const scopes = (0, import_lodash.uniqWith)(
// 去重
(0, import_lodash.concat)(
// 合并
[],
initScopes,
commonScopesInScopesTypeItem,
userScopesInScopesTypeItem
),
// 用对象判断的方式 判断去重
import_lodash.isEqual
);
if ((config2 == null ? void 0 : config2.isPrintScopes) === true) {
import_consola.consola.box(scopes);
import_consola.consola.success(` \u53EF\u7528\u7684\u63D0\u4EA4\u8303\u56F4\u5982\u4E0B\uFF1A `);
}
const userConfig = defExportCommitlintConfig;
setScopesInUserConfig({ scopes, userConfig });
return userConfig;
}
var defExportCommitlintConfig = (0, import_lodash.cloneDeep)(config);
setScopesInUserConfig({ scopes: defScopes, userConfig: defExportCommitlintConfig });
var index_default = defExportCommitlintConfig;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getUserConfig
});