commit-pack 1.1.4 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,64 +1,112 @@
1
- # auto-commit
1
+ # commit-pack
2
2
 
3
- ## 1. 概述
3
+ 自动化的项目代码质量和提交标准化设置。集成 ESLint、Prettier、Husky、lint-staged、commitlint 和 commitizen,强制执行一致的代码风格和标准化的提交消息。
4
4
 
5
- Eslint 代码质量
5
+ ## ✨ 特性
6
6
 
7
- Prettier 代码风格
7
+ - **代码质量**: 集成 ESLint,支持 TypeScript 解析器和推荐配置
8
+ - **代码格式化**: Prettier 带有预设的格式化规则
9
+ - **Git 钩子**: Husky 驱动的提交前和提交消息验证
10
+ - **暂存文件**: lint-staged 只对暂存文件运行检查
11
+ - **提交验证**: commitlint 确保符合常规提交格式
12
+ - **交互式提交**: commitizen 提供引导式提交创建
13
+ - **多包管理器**: 支持 pnpm、npm、yarn 和 bun
14
+ - **支持 Monorepo**: 使用 `-w` 标志处理基于工作区的项目
15
+ - **安全回滚**: 初始化失败时自动回滚
8
16
 
9
- eslint-config-prettier 关闭所有可能干扰 Prettier 规则的 ESLint 规则
17
+ ## 🚀 快速开始
10
18
 
11
- eslint-plugin-prettier 将 Prettier 规则转换为 ESLint 规则
12
-
13
- Husky 自动化检查修改(git hook)
14
-
15
- lint-staged 只对已更改文件检查
16
-
17
- commitlint 检查提交信息规范性
18
-
19
- commitizen 自动化脚本生成 commit message
20
-
21
- vscode 插件
22
-
23
- ## 2. 快速入门
24
-
25
- </br>
26
-
27
- ### 🚀 安装
28
- ```
19
+ ### 安装
20
+ ```bash
21
+ # 使用 pnpm
29
22
  pnpm add -D commit-pack@latest
30
23
  ```
31
- ```
24
+
25
+ ```bash
26
+ # 使用 bun
32
27
  bun add -d commit-pack@latest
33
28
  ```
29
+
30
+ ```bash
31
+ # 使用 npm
32
+ npm install -D commit-pack@latest
34
33
  ```
35
- npm i -D commit-pack@latest
36
- ```
37
- ```
34
+
35
+ ```bash
36
+ # 使用 yarn
38
37
  yarn add -D commit-pack@latest
39
38
  ```
40
- </br>
41
39
 
42
- ### 🍀 初始化
43
- ```
40
+ ### 初始化
41
+ ```bash
42
+ # 在项目根目录初始化
44
43
  pnpm exec commit-pack-init
45
44
  ```
46
- ```
45
+
46
+ ```bash
47
+ # 使用 bun
47
48
  bunx commit-pack-init
48
49
  ```
49
- ```
50
+
51
+ ```bash
52
+ # 使用 npx
50
53
  npx commit-pack-init
51
54
  ```
52
- ```
55
+
56
+ ```bash
57
+ # 使用 yarn
53
58
  yarn dlx commit-pack-init
54
59
  ```
55
60
 
61
+ ### Monorepo 支持
62
+ ```bash
63
+ # 为 monorepo 中的特定工作区初始化
64
+ pnpm exec commit-pack-init -w workspace-name
65
+ # 或
66
+ pnpm exec commit-pack-init --workspace=workspace-name
67
+ ```
56
68
 
69
+ ## 🛠️ 包含的内容
57
70
 
71
+ ### ESLint 配置
72
+ - 支持 TypeScript 的 `@typescript-eslint/parser`
73
+ - 推荐的 TypeScript 规则
74
+ - 与 Prettier 的集成以避免冲突
75
+ - 适用于 monorepo 的根配置
58
76
 
77
+ **.eslintrc**
78
+ ```json
79
+ {
80
+ "root": true,
81
+ "parser": "@typescript-eslint/parser",
82
+ "extends": [
83
+ "eslint:recommended",
84
+ "plugin:@typescript-eslint/recommended",
85
+ "plugin:@typescript-eslint/eslint-recommended",
86
+ "prettier"
87
+ ],
59
88
 
60
- **.prettierrc**
89
+ "plugins": [
90
+ "@typescript-eslint",
91
+ "prettier"
92
+ ],
61
93
 
94
+ "rules": {
95
+ "prettier/prettier": "error",
96
+ "arrow-body-style": "off",
97
+ "prefer-arrow-callback": "off"
98
+ }
99
+ }
100
+ ```
101
+
102
+ ### Prettier 配置
103
+ - 字符串使用单引号
104
+ - 打印宽度为 100 个字符
105
+ - 不使用分号
106
+ - 支持 Tailwind CSS 插件
107
+ - 一致的间距和格式
108
+
109
+ **.prettierrc**
62
110
  ```json
63
111
  {
64
112
  "singleQuote": true,
@@ -73,29 +121,205 @@ yarn dlx commit-pack-init
73
121
  }
74
122
  ```
75
123
 
124
+ ### Commitlint 配置
125
+ - 强制执行常规提交格式
126
+ - 自定义表情符号前缀的提交类型
127
+ - 范围验证
128
+ - 详细的提交消息结构
129
+
130
+ **.commitlintrc.json**
131
+ ```json
132
+ {
133
+ "extends": ["@commitlint/config-conventional"],
134
+ "parserPreset": {
135
+ "parserOpts": {
136
+ "headerPattern": "^(.+?)\\((.+?)\\): (.+)$",
137
+ "headerCorrespondence": ["type", "scope", "subject"]
138
+ }
139
+ },
140
+ "rules": {
141
+ "scope-empty": [2, "never"],
142
+ "type-enum": [
143
+ 2,
144
+ "always",
145
+ [
146
+ "✨ feat",
147
+ "🐛 fix",
148
+ "🎉 init",
149
+ "✏️ docs",
150
+ "💄 style",
151
+ "♻️ refactor",
152
+ "⚡️ perf",
153
+ "✅ test",
154
+ "⏪️ revert",
155
+ "📦 build",
156
+ "🚀 chore",
157
+ "👷 ci"
158
+ ]
159
+ ]
160
+ }
161
+ }
162
+ ```
163
+
164
+ ### Commitizen 配置
165
+ - 交互式提交界面
166
+ - 预定义的表情符号提交类型
167
+ - 可自定义范围
168
+ - 引导式提交消息创建
76
169
 
170
+ **.cz-config.js**
171
+ ```js
172
+ module.exports = {
173
+ types: [
174
+ { value: "✨ feat", name: " ✨ feat: 新功能" },
175
+ { value: "🐛 fix", name: " 🐛 fix: 修复bug" },
176
+ { value: "🎉 init", name: " 🎉 init: 初始化" },
177
+ { value: "✏️ docs", name: " ✏️ docs: 文档变更" },
178
+ { value: "💄 style", name: " 💄 style: 更改样式" },
179
+ { value: "♻️ refactor", name: " ♻️ refactor: 重构" },
180
+ { value: "⚡️ perf", name: " ⚡️ perf: 性能优化" },
181
+ { value: "✅ test", name: " ✅ test: 测试" },
182
+ { value: "⏪️ revert", name: " ⏪️ revert: 回退" },
183
+ { value: "📦 build", name: " 📦 build: 打包" },
184
+ { value: "🚀 chore", name: " 🚀 chore: 构建/工程依赖/工具" },
185
+ { value: "👷 ci", name: " 👷 ci: CI related changes" },
186
+ ],
77
187
 
78
- **.eslintrc**
188
+ scopes: [
189
+ { name: "components" },
190
+ { name: "page" },
191
+ { name: "css" },
192
+ { name: "api" },
193
+ { name: "README.md" },
194
+ { name: "custom" },
195
+ ],
196
+
197
+ messages: {
198
+ type: "请选择提交类型(必填)",
199
+ scope: "请选择文件修改范围(必填):",
200
+ customScope: "请输自定义文件修改范围(必填)",
201
+ subject: "请简要描述提交(必填)",
202
+ body: "请输入详细描述(可选)",
203
+ breaking: "列出任何breaking changes(可选)",
204
+ footer: "请输入要关闭的issue(可选)",
205
+ confirmCommit: "确定提交吗",
206
+ },
207
+
208
+ allowCustomScopes: true,
209
+ allowBreakingChanges: ["✨ feat", "🐛 fix"],
210
+ subjectLimit: 49,
211
+ };
212
+ ```
213
+
214
+ ## 📋 可用脚本
215
+
216
+ 初始化后,以下脚本将被添加到您的 `package.json` 中:
217
+
218
+ - `lint`: 对所有 TypeScript/JavaScript/JSON 文件运行 ESLint
219
+ - `format`: 使用 Prettier 格式化所有文件
220
+ - `commit`: 使用 commitizen 进行交互式提交
221
+
222
+ ## 🤝 贡献
223
+
224
+ 1. Fork 仓库
225
+ 2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
226
+ 3. 进行修改
227
+ 4. 运行 linter (`pnpm run lint`) 和格式化 (`pnpm run format`)
228
+ 5. 使用 commitizen 界面提交更改 (`pnpm run commit`)
229
+ 6. 推送到分支 (`git push origin feature/amazing-feature`)
230
+ 7. 创建 Pull Request
231
+
232
+ ## ©️ 许可证
233
+
234
+ 此项目根据 MIT 许可证授权 - 详见 [LICENSE](LICENSE) 文件。
235
+
236
+ ---
237
+
238
+ # commit-pack
239
+
240
+ Automated project setup for code quality and commit standardization. Integrates ESLint, Prettier, Husky, lint-staged, commitlint, and commitizen to enforce consistent code style and standardized commit messages.
241
+
242
+ ## ✨ Features
243
+
244
+ - **Code Quality**: Integrates ESLint with TypeScript parser and recommended configs
245
+ - **Code Formatting**: Prettier with opinionated formatting rules
246
+ - **Git Hooks**: Husky-powered pre-commit and commit-message validation
247
+ - **Staged Files**: lint-staged runs checks only on staged files
248
+ - **Commit Validation**: commitlint ensures conventional commit format
249
+ - **Interactive Commits**: commitizen provides guided commit creation
250
+ - **Multi-Package Manager**: Supports pnpm, npm, yarn, and bun
251
+ - **Monorepo Ready**: Handles workspace-based projects with `-w` flag
252
+ - **Rollback Safe**: Automatic rollback if initialization fails
253
+
254
+ ## 🚀 Quick Start
255
+
256
+ ### Installation
257
+ ```bash
258
+ # Using pnpm
259
+ pnpm add -D commit-pack@latest
260
+ ```
261
+
262
+ ```bash
263
+ # Using bun
264
+ bun add -d commit-pack@latest
265
+ ```
266
+
267
+ ```bash
268
+ # Using npm
269
+ npm install -D commit-pack@latest
270
+ ```
271
+
272
+ ```bash
273
+ # Using yarn
274
+ yarn add -D commit-pack@latest
275
+ ```
276
+
277
+ ### Initialization
278
+ ```bash
279
+ # Initialize in the root of your project
280
+ pnpm exec commit-pack-init
281
+ ```
282
+
283
+ ```bash
284
+ # Using bun
285
+ bunx commit-pack-init
286
+ ```
287
+
288
+ ```bash
289
+ # Using npx
290
+ npx commit-pack-init
291
+ ```
292
+
293
+ ```bash
294
+ # Using yarn
295
+ yarn dlx commit-pack-init
296
+ ```
297
+
298
+ ### Monorepo Support
299
+ ```bash
300
+ # Initialize for a specific workspace in monorepo
301
+ pnpm exec commit-pack-init -w workspace-name
302
+ # or
303
+ pnpm exec commit-pack-init --workspace=workspace-name
304
+ ```
305
+
306
+ ## 🛠️ What's Included
79
307
 
80
- ````json
308
+ ### ESLint Configuration
309
+ - TypeScript support with `@typescript-eslint/parser`
310
+ - Recommended TypeScript rules
311
+ - Integration with Prettier to avoid conflicts
312
+ - Root configuration to work in monorepos
313
+
314
+ **.eslintrc**
315
+ ```json
81
316
  {
82
- // 这是根配置文件,ESLint 不会在父目录中查找其他配置文件。
83
317
  "root": true,
84
-
85
- // 指定要使用的解析器,这里是 TypeScript 的解析器。
86
318
  "parser": "@typescript-eslint/parser",
87
-
88
319
  "extends": [
89
- // 扩展 ESLint 推荐的规则
90
320
  "eslint:recommended",
91
-
92
- // 扩展 @typescript-eslint/eslint-plugin 推荐规则
93
321
  "plugin:@typescript-eslint/recommended",
94
-
95
- // 扩展 @typescript-eslint/eslint-plugin 推荐的规则,禁用与 eslint:recommended 冲突的规则
96
322
  "plugin:@typescript-eslint/eslint-recommended",
97
-
98
- // 扩展 Prettier 配置以禁用可能与 Prettier 冲突的 ESLint 规则 即 eslint-config-prettier 确保放在最后
99
323
  "prettier"
100
324
  ],
101
325
 
@@ -105,22 +329,42 @@ yarn dlx commit-pack-init
105
329
  ],
106
330
 
107
331
  "rules": {
108
- // 将 Prettier 格式化强制为 ESLint 错误。
109
332
  "prettier/prettier": "error",
110
-
111
- // 禁用强制在箭头函数体周围使用大括号的规则。
112
333
  "arrow-body-style": "off",
113
-
114
- // 禁用强制为回调使用箭头函数的规则。
115
334
  "prefer-arrow-callback": "off"
116
335
  }
117
336
  }
118
337
  ```
119
- ````
120
338
 
339
+ ### Prettier Configuration
340
+ - Single quotes for strings
341
+ - Print width of 100 characters
342
+ - No semicolons
343
+ - Tailwind CSS plugin support
344
+ - Consistent spacing and formatting
121
345
 
122
- **.commitlintrc.json**
346
+ **.prettierrc**
347
+ ```json
348
+ {
349
+ "singleQuote": true,
350
+ "printWidth": 100,
351
+ "jsxSingleQuote": true,
352
+ "bracketSameLine": true,
353
+ "semi": false,
354
+ "plugins": ["prettier-plugin-tailwindcss"],
355
+ "tabWidth": 2,
356
+ "bracketSpacing": true,
357
+ "trailingComma": "none"
358
+ }
359
+ ```
360
+
361
+ ### Commitlint Configuration
362
+ - Enforces conventional commit format
363
+ - Custom emoji-prefixed commit types
364
+ - Scope validation
365
+ - Detailed commit message structure
123
366
 
367
+ **.commitlintrc.json**
124
368
  ```json
125
369
  {
126
370
  "extends": ["@commitlint/config-conventional"],
@@ -154,8 +398,13 @@ yarn dlx commit-pack-init
154
398
  }
155
399
  ```
156
400
 
157
- **.cz-config.js**
401
+ ### Commitizen Configuration
402
+ - Interactive commit interface
403
+ - Predefined commit types with emojis
404
+ - Customizable scopes
405
+ - Guided commit message creation
158
406
 
407
+ **.cz-config.js**
159
408
  ```js
160
409
  module.exports = {
161
410
  types: [
@@ -198,3 +447,35 @@ module.exports = {
198
447
  subjectLimit: 49,
199
448
  };
200
449
  ```
450
+
451
+ ## 📋 Available Scripts
452
+
453
+ After initialization, the following scripts will be added to your `package.json`:
454
+
455
+ - `lint`: Run ESLint on all TypeScript/JavaScript/JSON files
456
+ - `format`: Format all files using Prettier
457
+ - `commit`: Interactive commit using commitizen
458
+
459
+ ## 🤝 Contributing
460
+
461
+ 1. Fork the repository
462
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
463
+ 3. Make your changes
464
+ 4. Run the linter (`pnpm run lint`) and formatter (`pnpm run format`)
465
+ 5. Commit your changes using the commitizen interface (`pnpm run commit`)
466
+ 6. Push to the branch (`git push origin feature/amazing-feature`)
467
+ 7. Open a Pull Request
468
+
469
+ ## ©️ License
470
+
471
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
472
+
473
+ ## 🙏 Acknowledgments
474
+
475
+ - [ESLint](https://eslint.org/) - Pluggable JavaScript linter
476
+ - [Prettier](https://prettier.io/) - Opinionated code formatter
477
+ - [Husky](https://typicode.github.io/husky/) - Git hooks made easy
478
+ - [lint-staged](https://github.com/okonet/lint-staged) - Run linters on staged files
479
+ - [commitlint](https://commitlint.js.org/) - Lint commit messages
480
+ - [commitizen](https://github.com/commitizen/cz-cli) - Interactive commit prompts
481
+ - [TypeScript](https://www.typescriptlang.org/) - Typed JavaScript at any scale