Skip to content

Commit

Permalink
✨ feat(root): 完成动态子包的查询。现在提交时,可以筛选出子包。
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-cat committed Oct 14, 2024
1 parent 7bd0081 commit d98a8dd
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 110 deletions.
209 changes: 99 additions & 110 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const fs = require("fs");
const path = require("path");
const glob = require("glob");
const yaml = require("js-yaml");
// const { createRequire } = require("module");
// const esm = require("esm")(module);
const lodash = require("lodash");

const defScopes = [
"root|根目录",
Expand All @@ -40,16 +39,10 @@ function pathChange(path) {
* 根据 pnpm-workspace.yaml 配置的monorepo有意义的包名,获取包名和包描述
*
* Array<{name: string, description: string}>
* @return { Promise<import("cz-git").ScopesType> }
* Promise<import("cz-git").ScopesType>
* @return { import("cz-git").ScopesType }
*/
async function getPackagesNameAndDescription() {
// const require = createRequire(import.meta.url);
// /**
// * @see https://juejin.cn/post/7240365776737730616
// */
// const lodash = require("lodash-es");
// const lodash = esm("lodash-es");
const lodash = await import("lodash-es");
function getPackagesNameAndDescription() {

// 读取 pnpm-workspace.yaml 文件 文件路径
const workspaceConfigPath = path.join(__dirname, "pnpm-workspace.yaml");
Expand Down Expand Up @@ -121,108 +114,104 @@ async function getPackagesNameAndDescription() {
};
});

// console.log("czGitScopesType :>> ", czGitScopesType);

return czGitScopesType;
}

let scopes = defScopes;

(async () => {
scopes = await getPackagesNameAndDescription();
console.log(" in scopes ", scopes);
// .commitlintrc.js
/** @type {import("cz-git").UserConfig} */
module.exports = {
rules: {
// @see: https://commitlint.js.org/#/reference-rules
scopes = getPackagesNameAndDescription();
console.log(" in scopes ", scopes);

// .commitlintrc.js
/** @type {import("cz-git").UserConfig} */
module.exports = {
rules: {
// @see: https://commitlint.js.org/#/reference-rules
},
prompt: {
alias: { fd: "docs: fix typos" },

messages: {
type: "选择你要提交的类型 :",
scope: "选择一个提交范围(可选):",
customScope: "请输入自定义的提交范围 :",
subject: "填写简短精炼的变更描述 :\n",
body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
breaking: '列举非兼容性重大的变更(可选)。使用 "|" 换行 :\n',
footerPrefixesSelect: "选择关联issue前缀(可选):",
customFooterPrefix: "输入自定义issue前缀 :",
footer: "列举关联issue (可选) 例如: #31, #I3244 :\n",
confirmCommit: "是否提交或修改commit ?",
},
prompt: {
alias: { fd: "docs: fix typos" },

messages: {
type: "选择你要提交的类型 :",
scope: "选择一个提交范围(可选):",
customScope: "请输入自定义的提交范围 :",
subject: "填写简短精炼的变更描述 :\n",
body: '填写更加详细的变更描述(可选)。使用 "|" 换行 :\n',
breaking: '列举非兼容性重大的变更(可选)。使用 "|" 换行 :\n',
footerPrefixesSelect: "选择关联issue前缀(可选):",
customFooterPrefix: "输入自定义issue前缀 :",
footer: "列举关联issue (可选) 例如: #31, #I3244 :\n",
confirmCommit: "是否提交或修改commit ?",
},

/**
* 基于monorepo内项目,决定提交范围域
*/
scopes: scopes,

// https://cz-git.qbb.sh/zh/recipes/#多选模式
enableMultipleScopes: true,
scopeEnumSeparator: ",",

allowCustomScopes: true,
allowEmptyScopes: true,
customScopesAlign: "bottom",
customScopesAlias: "custom",
emptyScopesAlias: "empty",

types: [
{ value: "✨ feat", name: "✨ feat: 新增功能 | A new feature" },
{ value: "🐞 fix", name: "🐞 fix: 修复缺陷 | A bug fix" },
{ value: "📃 docs", name: "📃 docs: 文档更新 | Documentation only changes" },
{ value: "🌈 style", name: "🌈 style: 代码格式 | Changes that do not affect the meaning of the code" },
{
value: "🦄 refactor",
name: "🦄 refactor: 代码重构 | A code change that neither fixes a bug nor adds a feature",
},
{ value: "🎈 perf", name: "🎈 perf: 性能提升 | A code change that improves performance" },
{ value: "🧪 test", name: "🧪 test: 测试相关 | Adding missing tests or correcting existing tests" },
{
value: "🔧 build",
name: "🔧 build: 构建相关 | Changes that affect the build system or external dependencies",
},
{ value: "🐎 ci", name: "🐎 ci: 持续集成 | Changes to our CI configuration files and scripts" },
{ value: "↩ revert", name: "↩ revert: 回退代码 | Revert to a commit" },
{ value: "🐳 chore", name: "🐳 chore: 其他修改 | Other changes that do not modify src or test files" },
{
value: "🤔 save-file",
name: "🤔 save-file: 保存文件 | 文件保存类型。仅仅是为了保存文件。有时候会需要紧急提交,并快速切换分支。此时就需要提交代码。并保存文件。",
},
{ value: "⚙️ config", name: "⚙️ config: 更新配置 | 配置更新。通用性的配置更新。" },
{ value: "✋ main-pull-update", name: "✋ main-pull-update: 主分支拉取更新 | 主分支拉取更新。" },
{ value: "🗑 del", name: "🗑 del: 删除垃圾 | 删除无意义的东西,注释,文件,代码段等。" },
{ value: "⏩ mark-progress", name: "⏩ mark-progress: 标记进度 | 标记进度。" },
],
useEmoji: true,
emojiAlign: "center",
useAI: false,
aiNumber: 1,
themeColorCode: "",

upperCaseSubject: false,
markBreakingChangeMode: false,
allowBreakingChanges: ["feat", "fix"],
breaklineNumber: 100,
breaklineChar: "|",
skipQuestions: [],
issuePrefixes: [
// 如果使用 gitee 作为开发管理
{ value: "link", name: "link: 链接 ISSUES 进行中" },
{ value: "closed", name: "closed: 标记 ISSUES 已完成" },
],
customIssuePrefixAlign: "top",
emptyIssuePrefixAlias: "skip",
customIssuePrefixAlias: "custom",
allowCustomIssuePrefix: true,
allowEmptyIssuePrefix: true,
confirmColorize: true,
scopeOverrides: undefined,
defaultBody: "",
defaultIssues: "",
defaultScope: "",
defaultSubject: "",
},
};
})();
/**
* 基于monorepo内项目,决定提交范围域
*/
scopes: scopes,

// https://cz-git.qbb.sh/zh/recipes/#多选模式
enableMultipleScopes: true,
scopeEnumSeparator: ",",

allowCustomScopes: true,
allowEmptyScopes: true,
customScopesAlign: "bottom",
customScopesAlias: "custom",
emptyScopesAlias: "empty",

types: [
{ value: "✨ feat", name: "✨ feat: 新增功能 | A new feature" },
{ value: "🐞 fix", name: "🐞 fix: 修复缺陷 | A bug fix" },
{ value: "📃 docs", name: "📃 docs: 文档更新 | Documentation only changes" },
{ value: "🌈 style", name: "🌈 style: 代码格式 | Changes that do not affect the meaning of the code" },
{
value: "🦄 refactor",
name: "🦄 refactor: 代码重构 | A code change that neither fixes a bug nor adds a feature",
},
{ value: "🎈 perf", name: "🎈 perf: 性能提升 | A code change that improves performance" },
{ value: "🧪 test", name: "🧪 test: 测试相关 | Adding missing tests or correcting existing tests" },
{
value: "🔧 build",
name: "🔧 build: 构建相关 | Changes that affect the build system or external dependencies",
},
{ value: "🐎 ci", name: "🐎 ci: 持续集成 | Changes to our CI configuration files and scripts" },
{ value: "↩ revert", name: "↩ revert: 回退代码 | Revert to a commit" },
{ value: "🐳 chore", name: "🐳 chore: 其他修改 | Other changes that do not modify src or test files" },
{
value: "🤔 save-file",
name: "🤔 save-file: 保存文件 | 文件保存类型。仅仅是为了保存文件。有时候会需要紧急提交,并快速切换分支。此时就需要提交代码。并保存文件。",
},
{ value: "⚙️ config", name: "⚙️ config: 更新配置 | 配置更新。通用性的配置更新。" },
{ value: "✋ main-pull-update", name: "✋ main-pull-update: 主分支拉取更新 | 主分支拉取更新。" },
{ value: "🗑 del", name: "🗑 del: 删除垃圾 | 删除无意义的东西,注释,文件,代码段等。" },
{ value: "⏩ mark-progress", name: "⏩ mark-progress: 标记进度 | 标记进度。" },
],
useEmoji: true,
emojiAlign: "center",
useAI: false,
aiNumber: 1,
themeColorCode: "",

upperCaseSubject: false,
markBreakingChangeMode: false,
allowBreakingChanges: ["feat", "fix"],
breaklineNumber: 100,
breaklineChar: "|",
skipQuestions: [],
issuePrefixes: [
// 如果使用 gitee 作为开发管理
{ value: "link", name: "link: 链接 ISSUES 进行中" },
{ value: "closed", name: "closed: 标记 ISSUES 已完成" },
],
customIssuePrefixAlign: "top",
emptyIssuePrefixAlias: "skip",
customIssuePrefixAlias: "custom",
allowCustomIssuePrefix: true,
allowEmptyIssuePrefix: true,
confirmColorize: true,
scopeOverrides: undefined,
defaultBody: "",
defaultIssues: "",
defaultScope: "",
defaultSubject: "",
},
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@ruan-cat/vuepress-preset-config": "workspace:^",
"@types/eslint-config-prettier": "^6.11.3",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.10",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.16.11",
"@vuepress/bundler-vite": "2.0.0-rc.18",
Expand All @@ -78,13 +79,15 @@
"execa": "^9.4.0",
"glob": "^11.0.0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"markdown-it": "^14.1.0",
"mkdirp": "^3.0.1",
"pkg-types": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-lint-md": "^1.0.1",
"rimraf": "^5.0.10",
"shx": "^0.3.4",
"sync-import": "^0.0.3",
"tsx": "^4.19.1",
"turbo": "^2.1.3",
"type-fest": "^4.26.1",
Expand Down

0 comments on commit d98a8dd

Please sign in to comment.