阿里云域名注册好了怎么做网站,国家信用信息系统,建设网站要多久,大兴网站建设价格项目规范管理
目的
为了使团队多人协作更加的规范#xff0c;所以需要每次在 git 提交的时候#xff0c;做一次硬性规范提交#xff0c;规范 git 的提交信息
使用commitizen规范git提交(交互式提交 自定义提示文案 Commit规范)
安装依赖 pnpm install -D commitizen c…项目规范管理
目的
为了使团队多人协作更加的规范所以需要每次在 git 提交的时候做一次硬性规范提交规范 git 的提交信息
使用commitizen规范git提交(交互式提交 自定义提示文案 Commit规范)
安装依赖 pnpm install -D commitizen cz-conventional-changelog commitlint/config-conventional commitlint/cli commitlint-config-cz cz-customizable配置package.json
{scripts: {commit:comment: 引导设置规范化的提交信息,commit: git-cz},config: {commitizen: {path: node_modules/cz-customizable},cz-customizable: {// 若项目配置了type: module, 就需要修改配置文件的后缀名为cjs, 并添加这个配置config: .cz-config.cjs}}
}新增配置文件commitlint.config.js
module.exports {extends: [commitlint/config-conventional, cz],rules: {type-enum: [2,always,[feature, // 新功能featurebug, // 此项特别针对bug号用于向测试反馈bug列表的bug修改情况fix, // 修补bugui, // 更新 uidocs, // 文档documentationstyle, // 格式不影响代码运行的变动perf, // 性能优化release, // 发布deploy, // 部署refactor, // 重构即不是新增功能也不是修改bug的代码变动test, // 增加测试chore, // 构建过程或辅助工具的变动revert, // feat(pencil): add ‘graphiteWidth’ option (撤销之前的commit)merge, // 合并分支 例如 merge前端页面 feature-xxxx修改线程地址build, // 打包],],// type 格式 小写type-case: [2, always, lower-case],// type 不能为空type-empty: [2, never],// scope 范围不能为空scope-empty: [2, never],// scope 范围格式scope-case: [0],// scope 枚举范围scope-enum: [1, always],// subject 主要 message 不能为空subject-empty: [2, never],// subject 以什么为结束标志禁用subject-full-stop: [0, never],// subject 格式禁用subject-case: [0, never],// body 以空行开头body-leading-blank: [1, always],header-max-length: [0, always, 72],},
}添加自定义提示.cz-config.cjsmodule.exports {types: [{ value: feature, name: ✨ Features | 增加新功能 },{ value: bug, name: Bug Fixes | 测试反馈bug列表中的bug号 },{ value: fix, name: Bug Fixes | 修复bug },{ value: ui, name: UI| 更新UI },{ value: docs, name: Documentation |文档变更 },{ value: style, name: Styles | 风格(不影响代码运行的变动) },{ value: perf, name: ⚡Performance Improvements | 性能优化 },{ value: refactor, name: ♻ Code Refactoring |重构(既不是增加feature也不是修复bug) },{ value: release, name: release: 发布 },{ value: deploy, name: Chore |部署 },{ value: test, name: ✅ Tests |增加测试 },{ value: chore, name: Chore |构建过程或辅助工具的变动(更改配置文件) },{ value: revert, name: ⏪ Revert | 回退回退 },{ value: build, name: Build System |打包 },],// override the messages, defaults are as followsmessages: {type: 请选择提交类型:,customScope: 请输入您修改的范围(可选):,subject: 请简要描述提交 message (必填):,body: 请输入详细描述(可选待优化去除跳过即可):,footer: 请输入要关闭的issue(待优化去除跳过即可):,confirmCommit: 确认使用以上信息提交(y/n/e/h),},// 要是同一个git下有多个项目文件家 可以打开注释选择git要操作的项目// scopes: [{ name: h5 }, { name: manage}],allowCustomScopes: true,skipQuestions: [body, footer],subjectLimit: 72,
}使用prettier格式化代码
安装 pnpm add --save-dev --save-exact prettier创建.prettierrc文件并添加如下配置, 具体配置可以查看官网
{semi: false,tabWidth: 2,useTabs: false,singleQuote: true,printWidth: 150
}使用husky及lint-staged再提交代码时格式化代码
安装(注意这里与prettier官网的给出的示例不太一致 建议看husky官网进行配置) pnpm add --save-dev husky lint-stagedpnpm exec husky initnpm pkg set scripts.preparehusky在package.json添加如下配置
{lint-staged: {**/*: prettier --write --ignore-unknown}
}在.husky新建pre-commit文件并添加如下配置 echo pre-commitecho npx --no-install lint-stagednpx --no-install lint-staged在.husky新建commit-msg文件并添加如下配置 echo commit-msgecho npx --no-install commitlint --edit \$1\npx --no-install commitlint --edit $1完结
在git add后执行pnpm run commit命令根据提示输入commit信息即可。