【git】怎样实现规范git commit -m的格式

打印 上一主题 下一主题

主题 662|帖子 662|积分 1986

.husky/commit-msg

  1. #!/usr/bin/env sh
  2. . "$(dirname -- "$0")/_/husky.sh"
  3. yarn commitlint --edit $1
复制代码
.vscode/settings.json

  1.                 "ahooks",
  2.         "aliyuncs",
  3.         "antd",
  4.         "commitlint", // 新增
  5.         "deadcode",
  6.         "denormalize",
  7.         "echarts",
  8.         "EDITMSG", // 新增
  9.         "favicons",
  10.         "iconfont",
  11.         "IIFE",
复制代码
commitlint.config.ts

  1. import type { UserConfig } from '@commitlint/types';
  2. import { RuleConfigSeverity } from '@commitlint/types';
  3. import dotenv from 'dotenv';
  4. import fs from 'fs';
  5. import path from 'path';
  6. dotenv.config({ path: path.resolve(__dirname, '.env.local') });
  7. const Configuration: UserConfig = {
  8.     extends: ['@commitlint/config-conventional'],
  9.     rules: {
  10.         'type-case': [RuleConfigSeverity.Error, 'always', ['lower-case']],
  11.         'type-enum': [RuleConfigSeverity.Error, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert']],
  12.         'subject-rule': [RuleConfigSeverity.Error, 'always']
  13.     },
  14.     plugins: [
  15.         {
  16.             rules: {
  17.                 'type-enum': ({ type }) => {
  18.                     const typeList = ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert'];
  19.                     return [typeList.includes(type || ''), `类型错误,只允许提交类型为【${typeList}】的 commit, 例如:feat: 【1112223334445556667】xxx`];
  20.                 },
  21.                 'subject-rule': ({ type, subject }) => {
  22.                     let _subject = subject || '';
  23.                     const regRex = /^【[0-9]{19}】(?!\s*$).+/;
  24.                     if (process.env.TASK_NO && !regRex.test(_subject)) {
  25.                         const commitEditMsgPath = path.resolve(process.cwd(), '.git', 'COMMIT_EDITMSG');
  26.                         const commitMsgContent = fs.readFileSync(commitEditMsgPath, 'utf-8');
  27.                         const lines = commitMsgContent.split('\n');
  28.                         _subject = `【${process.env.TASK_NO}】${subject}`;
  29.                         if (lines.length > 0) {
  30.                             lines[0] = `${type}: ${_subject}`;
  31.                         }
  32.                         fs.writeFileSync(commitEditMsgPath, lines.join('\n'));
  33.                     }
  34.                     return [regRex.test(_subject), '提交格式不符合规范,需要包含19位任务ID,且包含基础的 commit 信息, 例如:feat: 【1112223334445556667】xxx'];
  35.                 }
  36.             }
  37.         }
  38.     ]
  39. };
  40. export default Configuration;
复制代码
package.json

  1. "devDependencies": {
  2.         "@commitlint/cli": "^17.8.1", // 新增
  3.         "@commitlint/config-conventional": "^17.8.1", // 新增
  4.         "@types/lodash": "^4.14.202",
  5.         "@types/node": "^20.11.6",
  6.         "@types/react": "^18.0.33",
  7.         "@types/react-dom": "^18.0.11",
  8.         "chalk": "^4.1.2",
  9.         "cross-env": "^7.0.3",
  10.         "dotenv": "^16.4.5", // 新增
  11.         "eslint": "^8.54.0",
  12.         "eslint-config-prettier": "^9.0.0",
  13.         "eslint-import-resolver-alias": "^1.1.2",
  14.         ...
  15. }
复制代码
.env.local

  1. # .env 的本地版本,这里配置的环境变量会覆盖 .env 中的变量。
  2. APP_ENV=sz-test1
  3. # APP_ENV=sz-dev
  4. # TASK_NO=1788498654317685432
  5. TASK="[{"release/2024-07-18" : "1807622818796223578"}]"
复制代码
.env

  1. # 对应测试环境,值从 config/server.ts 中的 key 中选
  2. # 开发时请在本地根目录新建一个 `.env.local` 文件,自行修改为需要的开发环境
  3. # APP_ENV=sz-test
  4. # 多语言相关接口的域名。
  5. # 各环境统一走 生产jk.cc.cn 域名(环境由接口的env参数做区分)
  6. # 这个值基本不会动,除非服务端需要调试特定环境的多语言接口。
  7. # 在使用时:
  8. #   1. 当 APP_ENV=production 时,不使用当前变量,固定走生产的域名 jk.cc.cn。
  9. #   2. 测试环境用当前变量指定的域名,而不是随环境对应的域名。
  10. #   3. 本地开发会忽略该变量,走本地开发域名以mock本地语料
  11. # 自动添加任务编号到 Commit, TASK_NO 根据自己要求填写
  12. # TASK_NO=1803607484162225644
复制代码
README.md

  1. # 运营平台前端项目
  2. ## yarn
  3. - 统一使用 yarn 作为包管理工具
  4. ## 配置本地开发环境
  5. - 切换环境请按 `.env` 中关于 `APP_ENV` 的注释,在`.env.local` 中配置 `APP_ENV` 变量区分连接的环境。
  6. - `yarn install` 时会自动创建一个空白的 `.env.local` 文件
  7. ## 代码校验
  8. macos用户,需要在 `yarn install`之后,于项目目录下执行下面两行命令。使 husky 生效。
  9. ```sh
  10. chmod ug+x .husky/*
  11. chmod ug+x .git/hooks/*
复制代码
UI库



  • 依赖antd 4.24.x版本,但是不要直接从antd引入, UI相关的组件从焦点库引入
  1. // 错误引入方式:
  2. import { Button } from 'antd';
  3. // 正确引入方式
  4. import { Button } from '@/component';
复制代码
权限



  • 抛弃umi的authority配置。菜单直接在路由里面配置权限code,具体权限code是什么,需要找后端
开发须知



  • 请运行:git config --global core.autocrlf false 去除 git 进入暂存区时自动转换为 crlf
  • 请运行:git config --global core.ignorecase false 去除 git 忽略巨细写
  • 编辑器必须开启 eslint 检测和保存自动修复功能(具体配置具体看:编辑器配置 Eslint)
  • master 是主分支,feature+版本号是开发分支,release+版本号是预发布分支
  • 统一使用 yarn 作为包管理工具
野火本地开发



  • 修改 hosts
  1. 172.22.3.196  im.jk.cn
复制代码
差别环境 ip 差别
   business 和 test 服务修改 hosts 即可乐成毗连本地联调只有 workdev 环境可毗连乐成 ( 请求头 Origin 为 localhost 造成毗连失败, 毗连非 dev 的服务毗连会被拒绝 )
  其他

参考umi开发文档 Umi
styled-components 使用方法

基础

  1. // Create a Title component that'll render an <h1> tag with some styles
  2. const Title = styled.h1`
  3.   font-size: 1.5em;
  4.   text-align: center;
  5.   color: #BF4F74;
  6. `;
  7. // Create a Wrapper component that'll render a <section> tag with some styles
  8. const Wrapper = styled.section`
  9.   padding: 4em;
  10.   background: papayawhip;
  11. `;
  12. // Use Title and Wrapper like any other React component – except they're styled!
  13. render(
  14.   <Wrapper>
  15.     <Title>
  16.       Hello World!
  17.     </Title>
  18.   </Wrapper>
  19. );
复制代码
根据属性进行调解

  1. const Button = styled.button<{ $primary?: boolean; }>`
  2.   /* Adapt the colors based on primary prop */
  3.   background: ${props => props.$primary ? "#BF4F74" : "white"};
  4.   color: ${props => props.$primary ? "white" : "#BF4F74"};
  5.   font-size: 1em;
  6.   margin: 1em;
  7.   padding: 0.25em 1em;
  8.   border: 2px solid #BF4F74;
  9.   border-radius: 3px;
  10. `;
  11. render(
  12.   <div>
  13.     <Button>Normal</Button>
  14.     <Button $primary>Primary</Button>
  15.   </div>
  16. );
复制代码
扩展样式

  1. // The Button from the last section without the interpolations
  2. const Button = styled.button`
  3.   color: #BF4F74;
  4.   font-size: 1em;
  5.   margin: 1em;
  6.   padding: 0.25em 1em;
  7.   border: 2px solid #BF4F74;
  8.   border-radius: 3px;
  9. `;
  10. // A new component based on Button, but with some override styles
  11. const TomatoButton = styled(Button)`
  12.   color: tomato;
  13.   border-color: tomato;
  14. `;
  15. render(
  16.   <div>
  17.     <Button>Normal Button</Button>
  18.     <TomatoButton>Tomato Button</TomatoButton>
  19.   </div>
  20. );
复制代码
伪元素、伪选择器和嵌套

  1. const Thing = styled.div.attrs((/* props */) => ({ tabIndex: 0 }))`
  2.   color: blue;
  3.   &:hover {
  4.     color: red; // <Thing> when hovered
  5.   }
  6.   & ~ & {
  7.     background: tomato; // <Thing> as a sibling of <Thing>, but maybe not directly next to it
  8.   }
  9.   & + & {
  10.     background: lime; // <Thing> next to <Thing>
  11.   }
  12.   &.something {
  13.     background: orange; // <Thing> tagged with an additional CSS class ".something"
  14.   }
  15.   .something-else & {
  16.     border: 1px solid; // <Thing> inside another element labeled ".something-else"
  17.   }
  18. `
  19. render(
  20.   <React.Fragment>
  21.     <Thing>Hello world!</Thing>
  22.     <Thing>How ya doing?</Thing>
  23.     <Thing className="something">The sun is shining...</Thing>
  24.     <div>Pretty nice day today.</div>
  25.     <Thing>Don't you think?</Thing>
  26.     <div className="something-else">
  27.       <Thing>Splendid.</Thing>
  28.     </div>
  29.   </React.Fragment>
  30. );
复制代码
强制样式提升

  1. const Thing = styled.div`
  2.    && {
  3.      color: blue;
  4.    }
  5. `
  6. const GlobalStyle = createGlobalStyle`
  7.    div${Thing} {
  8.      color: red;
  9.    }
  10. `
  11. render(
  12.    <React.Fragment>
  13.      <GlobalStyle />
  14.      <Thing>
  15.        I'm blue, da ba dee da ba daa
  16.      </Thing>
  17.    </React.Fragment>
  18. )
复制代码
[code][/code]
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

星球的眼睛

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表