commit-pack 1.0.5

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/.babelrc ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "node": "current"
8
+ },
9
+ "modules": "commonjs",
10
+ "exclude": ["transform-regenerator"]
11
+ }
12
+ ]
13
+ ]
14
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "extends": ["@commitlint/config-conventional"],
3
+ "parserPreset": {
4
+ "parserOpts": {
5
+ "headerPattern": "^(.+?)\\((.+?)\\): (.+)$",
6
+ "headerCorrespondence": ["type", "scope", "subject"]
7
+ }
8
+ },
9
+ "rules": {
10
+ "scope-empty": [2, "never"],
11
+ "type-enum": [
12
+ 2,
13
+ "always",
14
+ [
15
+ "✨ feat",
16
+ "🐛 fix",
17
+ "🎉 init",
18
+ "✏️ docs",
19
+ "💄 style",
20
+ "♻️ refactor",
21
+ "⚡️ perf",
22
+ "✅ test",
23
+ "⏪️ revert",
24
+ "📦 build",
25
+ "🚀 chore",
26
+ "👷 ci"
27
+ ]
28
+ ]
29
+ }
30
+ }
package/.cz-config.js ADDED
@@ -0,0 +1,41 @@
1
+ module.exports = {
2
+ types: [
3
+ { value: '✨ feat', name: ' ✨ feat: 新功能' },
4
+ { value: '🐛 fix', name: ' 🐛 fix: 修复bug' },
5
+ { value: '🎉 init', name: ' 🎉 init: 初始化' },
6
+ { value: '✏️ docs', name: ' ✏️ docs: 文档变更' },
7
+ { value: '💄 style', name: ' 💄 style: 更改样式' },
8
+ { value: '♻️ refactor', name: ' ♻️ refactor: 重构' },
9
+ { value: '⚡️ perf', name: ' ⚡️ perf: 性能优化' },
10
+ { value: '✅ test', name: ' ✅ test: 测试' },
11
+ { value: '⏪️ revert', name: ' ⏪️ revert: 回退' },
12
+ { value: '📦 build', name: ' 📦 build: 打包' },
13
+ { value: '🚀 chore', name: ' 🚀 chore: 构建/工程依赖/工具' },
14
+ { value: '👷 ci', name: ' 👷 ci: CI related changes' }
15
+ ],
16
+
17
+ scopes: [
18
+ { name: 'components' },
19
+ { name: 'page' },
20
+ { name: 'css' },
21
+ { name: 'api' },
22
+ { name: 'README.md' },
23
+ { name: 'custom' }
24
+ ],
25
+
26
+ messages: {
27
+ type: '请选择提交类型(必填)',
28
+ scope: '请选择文件修改范围(必填):',
29
+ customScope: '请输自定义文件修改范围(必填)',
30
+ subject: '请简要描述提交(必填)',
31
+ body: '请输入详细描述(可选)',
32
+ breaking: '列出任何breaking changes(可选)',
33
+ footer: '请输入要关闭的issue(可选)',
34
+ confirmCommit: '确定提交吗'
35
+ },
36
+
37
+ allowCustomScopes: true,
38
+ allowBreakingChanges: ['✨ feat', '🐛 fix'],
39
+ subjectLimit: 49
40
+
41
+ }
package/.czrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "path": "cz-customizable"
3
+ }
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules/
2
+
3
+ README.md
package/.eslintrc ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "extends": [
5
+ "eslint:recommended",
6
+ "plugin:@typescript-eslint/recommended",
7
+ "prettier"
8
+ ],
9
+ "plugins": ["@typescript-eslint", "prettier"],
10
+ "rules": {
11
+ "prettier/prettier": "error",
12
+ "arrow-body-style": "off",
13
+ "prefer-arrow-callback": "off"
14
+ }
15
+ }
@@ -0,0 +1,73 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths-ignore:
8
+ - 'pnpm-lock.yaml'
9
+
10
+ permissions:
11
+ contents: write
12
+ jobs:
13
+ release:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ # 1. 检出代码
18
+ - name: Checkout code
19
+ uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0
22
+
23
+ # 2. 设置 Node.js 环境
24
+ - name: Sync node version and setup cache
25
+ uses: actions/setup-node@v4
26
+ with:
27
+ node-version: 20
28
+
29
+ # 3. 安装 pnpm
30
+ - name: Install PNPM
31
+ run: npm i -g pnpm
32
+
33
+ # 4. 验证 pnpm 安装
34
+ - name: Verify pnpm installation
35
+ run: pnpm --version
36
+
37
+ # 5. 安装依赖
38
+ - name: Install dependencies
39
+ run: pnpm install
40
+
41
+ # 6. 配置 Git 信息
42
+ - name: Configure Git
43
+ run: |
44
+ git config user.name "github-actions[bot]"
45
+ git config user.email "github-actions[bot]@users.noreply.github.com"
46
+
47
+ # 7. 更新版本号并创建标签
48
+ - name: Bump version and create tag
49
+ run: pnpm run release
50
+ env:
51
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52
+
53
+ # 8. 配置 Git 身份验证
54
+ - name: 配置 Git 身份验证
55
+ run: |
56
+ git remote set-url origin https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
57
+
58
+ # 9. 推送更改
59
+ - name: Push changes
60
+ run: |
61
+ git push origin main --follow-tags
62
+ env:
63
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64
+
65
+ # 10. 运行构建脚本
66
+ - name: Run build
67
+ run: pnpm run build
68
+
69
+ # 11. 发布到 npm
70
+ - name: Publish to npm
71
+ run: pnpm publish --access public
72
+ env:
73
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1 @@
1
+ npx --no -- commitlint --edit "$1"
@@ -0,0 +1 @@
1
+ npx lint-staged
package/.lintstagedrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"]
3
+ }
@@ -0,0 +1,5 @@
1
+ node_modules/
2
+
3
+ README.md
4
+
5
+ .cz-config.js
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 88,
4
+ "jsxSingleQuote": true,
5
+ "bracketSameLine": true,
6
+ "semi": false,
7
+ "tabWidth": 2,
8
+ "bracketSpacing": true,
9
+ "trailingComma": "none"
10
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ## [1.0.5](https://github.com/Jett191/commit-pack/compare/v1.0.4...v1.0.5) (2024-11-05)
6
+
7
+
8
+
9
+ ## [1.0.4](https://github.com/Jett191/commit-pack/compare/v1.0.3...v1.0.4) (2024-11-05)
10
+
11
+
12
+
13
+ ## [1.0.3](https://github.com/Jett191/commit-pack/compare/v1.0.2...v1.0.3) (2024-11-05)
14
+
15
+
16
+
17
+ ## [1.0.2](https://github.com/Jett191/commit-pack/compare/v1.0.1...v1.0.2) (2024-11-05)
18
+
19
+
20
+
21
+ ## 1.0.1 (2024-11-05)
package/README.md ADDED
@@ -0,0 +1,299 @@
1
+ # auto-commit
2
+
3
+ ## 1. 说明
4
+
5
+ Eslint 代码质量
6
+
7
+ Prettier 代码风格
8
+
9
+ eslint-config-prettier 关闭所有可能干扰 Prettier 规则的 ESLint 规则
10
+
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
+ ### 🍀 Eslint
26
+
27
+ ```sh
28
+ pnpm add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
29
+ ```
30
+
31
+ ==.eslintrc==
32
+
33
+ ```json
34
+ {
35
+ // 表示这是根配置文件,ESLint 不会在父目录中查找其他配置文件。
36
+ "root": true,
37
+ // 指定要使用的解析器,这里是 TypeScript 的解析器。
38
+ "parser": "@typescript-eslint/parser",
39
+ "extends": [
40
+ // 扩展 ESLint 推荐的规则。
41
+ "eslint:recommended",
42
+ // 扩展 @typescript-eslint/eslint-plugin 推荐的规则。
43
+ "plugin:@typescript-eslint/recommended",
44
+ // 扩展 @typescript-eslint/eslint-plugin 推荐的规则,禁用与 eslint:recommended 冲突的规则。
45
+ "plugin:@typescript-eslint/eslint-recommended"
46
+ ],
47
+ // 指定要使用的插件,这里是 @typescript-eslint 插件。
48
+ "plugins": ["@typescript-eslint"]
49
+ }
50
+ ```
51
+
52
+ ==.eslintrcignore==
53
+
54
+ ```json
55
+ node_modules/
56
+
57
+ README.md
58
+ ```
59
+
60
+ 脚本
61
+
62
+ ```json
63
+ "lint": "eslint ./ --ext .ts,.tsx,.json --max-warnings=0",
64
+ ```
65
+
66
+ ### 🍀 prettier
67
+
68
+ ```sh
69
+ pnpm add -D prettier
70
+ ```
71
+
72
+ ==.prettierrc==
73
+
74
+ ```json
75
+ {
76
+ "singleQuote": true,
77
+ "printWidth": 100,
78
+ "jsxSingleQuote": true,
79
+ "bracketSameLine": true,
80
+ "semi": false,
81
+ "plugins": ["prettier-plugin-tailwindcss"],
82
+ "tabWidth": 2,
83
+ "bracketSpacing": true,
84
+ "trailingComma": "none"
85
+ }
86
+ ```
87
+
88
+ ==.prettierrcignore==
89
+
90
+ ```json
91
+ node_modules/
92
+
93
+ README.md
94
+ ```
95
+
96
+ 脚本
97
+
98
+ ```json
99
+ "format": "prettier --config .prettierrc '.' --write"
100
+ ```
101
+
102
+ ### 🍀 eslint-config-prettier && eslint-plugin-prettier
103
+
104
+ ```sh
105
+ pnpm add -D eslint-config-prettier eslint-plugin-prettier
106
+ ```
107
+
108
+ ==.eslintrc==
109
+
110
+ ````json
111
+ {
112
+ // 表示这是根配置文件,ESLint 不会在父目录中查找其他配置文件。
113
+ "root": true,
114
+ // 指定要使用的解析器,这里是 TypeScript 的解析器。
115
+ "parser": "@typescript-eslint/parser",
116
+ "extends": [
117
+ // 扩展 ESLint 推荐的规则。
118
+ "eslint:recommended",
119
+ // 扩展 @typescript-eslint/eslint-plugin 推荐的规则。
120
+ "plugin:@typescript-eslint/recommended",
121
+ // 扩展 @typescript-eslint/eslint-plugin 推荐的规则,禁用与 eslint:recommended 冲突的规则。
122
+ "plugin:@typescript-eslint/eslint-recommended",
123
+ // 扩展 Prettier 配置以禁用可能与 Prettier 冲突的 ESLint 规则。即 eslint-config-prettier 确保放在最后
124
+ "prettier"
125
+ ],
126
+ // 指定要使用的插件,这里是 @typescript-eslint 和 Prettier 插件。
127
+ "plugins": [
128
+ "@typescript-eslint",
129
+ "prettier"
130
+ ],
131
+ "rules": {
132
+ // 将 Prettier 格式化强制为 ESLint 错误。
133
+ "prettier/prettier": "error",
134
+ // 禁用强制在箭头函数体周围使用大括号的规则。
135
+ "arrow-body-style": "off",
136
+ // 禁用强制为回调使用箭头函数的规则。
137
+ "prefer-arrow-callback": "off"
138
+ }
139
+ }
140
+ ```
141
+ ````
142
+
143
+ ### 🍀 husky
144
+
145
+ ```sh
146
+ pnpm add -D husky
147
+ ```
148
+
149
+ ```sh
150
+ pnpm exec husky init
151
+ ```
152
+
153
+ 脚本
154
+
155
+ ```
156
+ "prepare": "husky install"
157
+ ```
158
+
159
+ ==.husky/pre-commit==
160
+
161
+ ```
162
+ pnpm run lint
163
+ ```
164
+
165
+ ### 🍀 int-staged
166
+
167
+ ```sh
168
+ pnpm add -D lint-staged
169
+ ```
170
+
171
+ ==.lintstagedrc==
172
+
173
+ ```sh
174
+ {
175
+ "*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"]
176
+ }
177
+ ```
178
+
179
+ ==更改 .husky/pre-commit==
180
+
181
+ ```
182
+ npx lint-staged
183
+ ```
184
+
185
+ ### 🍀 commitlint
186
+
187
+ ```sh
188
+ pnpm add -D @commitlint/cli @commitlint/config-conventional
189
+ ```
190
+
191
+ ==.commitlintrc.json==
192
+
193
+ ```json
194
+ {
195
+ "extends": ["@commitlint/config-conventional"],
196
+ "parserPreset": {
197
+ "parserOpts": {
198
+ "headerPattern": "^(.+?)\\((.+?)\\): (.+)$",
199
+ "headerCorrespondence": ["type", "scope", "subject"]
200
+ }
201
+ },
202
+ "rules": {
203
+ "scope-empty": [2, "never"],
204
+ "type-enum": [
205
+ 2,
206
+ "always",
207
+ [
208
+ "✨ feat",
209
+ "🐛 fix",
210
+ "🎉 init",
211
+ "✏️ docs",
212
+ "💄 style",
213
+ "♻️ refactor",
214
+ "⚡️ perf",
215
+ "✅ test",
216
+ "⏪️ revert",
217
+ "📦 build",
218
+ "🚀 chore",
219
+ "👷 ci"
220
+ ]
221
+ ]
222
+ }
223
+ }
224
+ ```
225
+
226
+ ==.husky/commit-msg==
227
+
228
+ ```sh
229
+ echo 'npx --no -- commitlint --edit "$1"' > .husky/commit-msg
230
+ ```
231
+
232
+ ### 🍀 commitizen
233
+
234
+ ```sh
235
+ pnpm add -D commitizen@4.2.4 commitlint-config-cz cz-customizabl cz-custom
236
+ ```
237
+
238
+ ==.czrc==
239
+
240
+ ```json
241
+ {
242
+ "path": "cz-customizable"
243
+ }
244
+ ```
245
+
246
+ ==.cz-config.js==
247
+
248
+ ```js
249
+ module.exports = {
250
+ types: [
251
+ { value: "✨ feat", name: " ✨ feat: 新功能" },
252
+ { value: "🐛 fix", name: " 🐛 fix: 修复bug" },
253
+ { value: "🎉 init", name: " 🎉 init: 初始化" },
254
+ { value: "✏️ docs", name: " ✏️ docs: 文档变更" },
255
+ { value: "💄 style", name: " 💄 style: 更改样式" },
256
+ { value: "♻️ refactor", name: " ♻️ refactor: 重构" },
257
+ { value: "⚡️ perf", name: " ⚡️ perf: 性能优化" },
258
+ { value: "✅ test", name: " ✅ test: 测试" },
259
+ { value: "⏪️ revert", name: " ⏪️ revert: 回退" },
260
+ { value: "📦 build", name: " 📦 build: 打包" },
261
+ { value: "🚀 chore", name: " 🚀 chore: 构建/工程依赖/工具" },
262
+ { value: "👷 ci", name: " 👷 ci: CI related changes" },
263
+ ],
264
+
265
+ scopes: [
266
+ { name: "components" },
267
+ { name: "page" },
268
+ { name: "css" },
269
+ { name: "api" },
270
+ { name: "README.md" },
271
+ { name: "custom" },
272
+ ],
273
+
274
+ messages: {
275
+ type: "请选择提交类型(必填)",
276
+ scope: "请选择文件修改范围(必填):",
277
+ customScope: "请输自定义文件修改范围(必填)",
278
+ subject: "请简要描述提交(必填)",
279
+ body: "请输入详细描述(可选)",
280
+ breaking: "列出任何breaking changes(可选)",
281
+ footer: "请输入要关闭的issue(可选)",
282
+ confirmCommit: "确定提交吗",
283
+ },
284
+
285
+ allowCustomScopes: true,
286
+ allowBreakingChanges: ["✨ feat", "🐛 fix"],
287
+ subjectLimit: 49,
288
+ };
289
+ ```
290
+
291
+ ==package.json==
292
+
293
+ ```json
294
+ "config": {
295
+ "commitizen": {
296
+ "path": "node_modules/cz-customizable"
297
+ }
298
+ },
299
+ ```
package/bin/index.js ADDED
@@ -0,0 +1,181 @@
1
+ /* eslint-env node */
2
+
3
+ import fs from 'fs'
4
+ import chalk from 'chalk'
5
+ import { execSync } from 'child_process'
6
+
7
+ // 检测包管理器
8
+ function detectPackageManager() {
9
+ if (fs.existsSync('pnpm-lock.yaml')) {
10
+ return 'pnpm'
11
+ } else if (fs.existsSync('yarn.lock')) {
12
+ return 'yarn'
13
+ } else if (fs.existsSync('bun.lockb')) {
14
+ return 'bun'
15
+ } else {
16
+ return 'npm'
17
+ }
18
+ }
19
+
20
+ const packageManager = detectPackageManager()
21
+ console.log(chalk.green(`检测到使用的包管理器:${packageManager}`))
22
+
23
+ const packageJsonPath = './package.json'
24
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
25
+
26
+ // 确保 devDependencies 存在
27
+ if (!packageJson.devDependencies) {
28
+ packageJson.devDependencies = {}
29
+ }
30
+
31
+ const devDependenciesWithVersion = {
32
+ commitizen: '4.2.4',
33
+ eslint: '8.57.1'
34
+ }
35
+
36
+ const devDependencies = [
37
+ '@typescript-eslint/parser',
38
+ '@typescript-eslint/eslint-plugin',
39
+ 'prettier',
40
+ 'eslint-config-prettier',
41
+ 'eslint-plugin-prettier',
42
+ 'husky',
43
+ 'lint-staged',
44
+ '@commitlint/cli',
45
+ '@commitlint/config-conventional',
46
+ 'commitlint-config-cz',
47
+ 'cz-customizable',
48
+ 'cz-custom'
49
+ ]
50
+
51
+ let dependenciesToInstall = []
52
+
53
+ // 检查并收集需要安装的依赖
54
+ for (const dep of devDependencies) {
55
+ if (!packageJson.devDependencies[dep]) {
56
+ dependenciesToInstall.push(dep)
57
+ }
58
+ }
59
+
60
+ for (const [dep, version] of Object.entries(devDependenciesWithVersion)) {
61
+ if (!packageJson.devDependencies[dep]) {
62
+ dependenciesToInstall.push(`${dep}@${version}`)
63
+ }
64
+ }
65
+
66
+ // 安装缺失的依赖
67
+ if (dependenciesToInstall.length > 0) {
68
+ let installCommand = ''
69
+
70
+ switch (packageManager) {
71
+ case 'pnpm':
72
+ installCommand = `pnpm add -D ${dependenciesToInstall.join(' ')}`
73
+ break
74
+ case 'yarn':
75
+ installCommand = `yarn add ${dependenciesToInstall.join(' ')} --dev`
76
+ break
77
+ case 'bun':
78
+ installCommand = `bun add -d ${dependenciesToInstall.join(' ')}`
79
+ break
80
+ default:
81
+ installCommand = `npm install ${dependenciesToInstall.join(' ')} --save-dev`
82
+ break
83
+ }
84
+
85
+ console.log(chalk.green(`正在安装开发依赖:${dependenciesToInstall.join(', ')}`))
86
+ console.log(chalk.green(`执行命令:${installCommand}`))
87
+ execSync(installCommand, { stdio: 'inherit' })
88
+ } else {
89
+ console.log(chalk.yellow('所有开发依赖已安装,无需安装'))
90
+ }
91
+
92
+ // 初始化 Git 仓库
93
+ console.log(chalk.green('初始化 Git 仓库'))
94
+ try {
95
+ // 检查是否已经是 Git 仓库
96
+ execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' })
97
+ console.log(chalk.yellow('当前已是一个 Git 仓库'))
98
+ } catch (error) {
99
+ console.error(chalk.red('未检测到 Git 仓库,正在初始化...'), error)
100
+ // 初始化 Git 仓库
101
+ execSync('git init', { stdio: 'inherit' })
102
+ }
103
+
104
+ // 根据包管理器,执行对应的 Husky 初始化命令
105
+ let huskyInitCommand = ''
106
+ switch (packageManager) {
107
+ case 'pnpm':
108
+ huskyInitCommand = 'pnpm exec husky init'
109
+ break
110
+ case 'yarn':
111
+ huskyInitCommand = 'yarn dlx husky-init'
112
+ break
113
+ case 'bun':
114
+ huskyInitCommand = 'bunx husky init'
115
+ break
116
+ default:
117
+ huskyInitCommand = 'npx husky init'
118
+ break
119
+ }
120
+
121
+ console.log(chalk.green(`执行 Husky 初始化命令:${huskyInitCommand}`))
122
+ execSync(huskyInitCommand, { stdio: 'inherit' })
123
+
124
+ // 执行 setup-script 中的所有文件
125
+ console.log(chalk.green('执行 setup-script 中的所有文件'))
126
+ try {
127
+ execSync('sh ./prettier.sh', { stdio: 'inherit' })
128
+ execSync('sh ./lintstagedrc.sh', { stdio: 'inherit' })
129
+ execSync('sh ./eslint.sh', { stdio: 'inherit' })
130
+ execSync('sh ./czrc.sh', { stdio: 'inherit' })
131
+ execSync('sh ./husky.sh', { stdio: 'inherit' })
132
+ execSync('sh ./commitlintrc.sh', { stdio: 'inherit' })
133
+ console.log(chalk.green('所有 setup-script 已执行完毕'))
134
+ } catch (error) {
135
+ console.error(chalk.red('执行 setup-script 时出错'), error)
136
+ }
137
+
138
+ // 创建或更新脚本
139
+ if (!packageJson.scripts) {
140
+ packageJson.scripts = {}
141
+ }
142
+
143
+ let modified = false
144
+
145
+ if (!packageJson.scripts.lint) {
146
+ packageJson.scripts.lint = 'eslint ./ --ext .ts,.tsx,.json --max-warnings=0'
147
+ console.log(chalk.green('已添加 "lint" 脚本到 package.json'))
148
+ modified = true
149
+ } else {
150
+ console.log(chalk.yellow('package.json 中已存在 "lint" 脚本,未作修改'))
151
+ }
152
+
153
+ if (!packageJson.scripts.format) {
154
+ packageJson.scripts.format = "prettier --config .prettierrc '.' --write"
155
+ console.log(chalk.green('已添加 "format" 脚本到 package.json'))
156
+ modified = true
157
+ } else {
158
+ console.log(chalk.yellow('package.json 中已存在 "format" 脚本,未作修改'))
159
+ }
160
+
161
+ // 添加或更新 "commit" 脚本
162
+ packageJson.scripts.commit = 'cz'
163
+ console.log(chalk.green('已添加或更新 "commit" 脚本到 package.json'))
164
+ modified = true
165
+
166
+ // 添加或更新 "config.commitizen" 配置
167
+ if (!packageJson.config) {
168
+ packageJson.config = {}
169
+ }
170
+
171
+ packageJson.config.commitizen = {
172
+ path: 'node_modules/cz-customizable'
173
+ }
174
+ console.log(chalk.green('已添加或更新 "config.commitizen" 到 package.json'))
175
+ modified = true
176
+
177
+ // 写入修改后的 package.json
178
+ if (modified) {
179
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8')
180
+ console.log(chalk.green('已更新 package.json'))
181
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "commit-pack",
3
+ "version": "1.0.5",
4
+ "description": "A setup package to automatly check project's style and commit configuration",
5
+ "main": "index.js",
6
+ "publishConfig": {
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "standard-version": {
10
+ "preset": "angular",
11
+ "commitAll": true
12
+ },
13
+ "config": {
14
+ "commitizen": {
15
+ "path": "node_modules/cz-customizable"
16
+ }
17
+ },
18
+ "keywords": [
19
+ "eslint",
20
+ "prettier",
21
+ "husky",
22
+ "lint-staged",
23
+ "commitlint",
24
+ "commitizen"
25
+ ],
26
+ "author": "jett191",
27
+ "license": "MIT",
28
+ "devDependencies": {
29
+ "@babel/cli": "^7.25.9",
30
+ "@babel/core": "^7.26.0",
31
+ "@babel/preset-env": "^7.26.0",
32
+ "@commitlint/cli": "^19.5.0",
33
+ "@commitlint/config-conventional": "^19.5.0",
34
+ "@typescript-eslint/eslint-plugin": "^8.12.2",
35
+ "@typescript-eslint/parser": "^8.12.2",
36
+ "chalk": "^5.3.0",
37
+ "commitizen": "4.2.4",
38
+ "commitlint-config-cz": "^0.13.3",
39
+ "cz-custom": "^0.0.2",
40
+ "cz-customizable": "^7.2.1",
41
+ "eslint": "^8.57.1",
42
+ "eslint-config-prettier": "^9.1.0",
43
+ "eslint-plugin-prettier": "^5.2.1",
44
+ "husky": "^9.1.6",
45
+ "inquirer": "^12.0.0",
46
+ "lint-staged": "^15.2.10",
47
+ "prettier": "^3.3.3",
48
+ "shelljs": "^0.8.5",
49
+ "standard-version": "^9.5.0"
50
+ },
51
+ "scripts": {
52
+ "lint": "eslint ./ --ext .ts,.tsx,.json --max-warnings=0",
53
+ "format": "prettier --config .prettierrc '.' --write",
54
+ "commit": "cz",
55
+ "build": "babel bin/index.js --out-file lib/index.js",
56
+ "release": "standard-version"
57
+ }
58
+ }
@@ -0,0 +1,33 @@
1
+ echo '
2
+ {
3
+ "extends": ["@commitlint/config-conventional"],
4
+ "parserPreset": {
5
+ "parserOpts": {
6
+ "headerPattern": "^(.+?)\\((.+?)\\): (.+)$",
7
+ "headerCorrespondence": ["type", "scope", "subject"]
8
+ }
9
+ },
10
+ "rules": {
11
+ "scope-empty": [2, "never"],
12
+ "type-enum": [
13
+ 2,
14
+ "always",
15
+ [
16
+ "✨ feat",
17
+ "🐛 fix",
18
+ "🎉 init",
19
+ "✏️ docs",
20
+ "💄 style",
21
+ "♻️ refactor",
22
+ "⚡️ perf",
23
+ "✅ test",
24
+ "⏪️ revert",
25
+ "📦 build",
26
+ "🚀 chore",
27
+ "👷 ci"
28
+ ]
29
+ ]
30
+ }
31
+ }
32
+
33
+ ' > .commitlintrc.json
@@ -0,0 +1,50 @@
1
+ echo '
2
+ {
3
+ "path": "cz-customizable"
4
+ }
5
+ ' > .czrc
6
+
7
+ echo '
8
+ module.exports = {
9
+ types: [
10
+ { value: '✨ feat', name: ' ✨ feat: 新功能' },
11
+ { value: '🐛 fix', name: ' 🐛 fix: 修复bug' },
12
+ { value: '🎉 init', name: ' 🎉 init: 初始化' },
13
+ { value: '✏️ docs', name: ' ✏️ docs: 文档变更' },
14
+ { value: '💄 style', name: ' 💄 style: 更改样式' },
15
+ { value: '♻️ refactor', name: ' ♻️ refactor: 重构' },
16
+ { value: '⚡️ perf', name: ' ⚡️ perf: 性能优化' },
17
+ { value: '✅ test', name: ' ✅ test: 测试' },
18
+ { value: '⏪️ revert', name: ' ⏪️ revert: 回退' },
19
+ { value: '📦 build', name: ' 📦 build: 打包' },
20
+ { value: '🚀 chore', name: ' 🚀 chore: 构建/工程依赖/工具' },
21
+ { value: '👷 ci', name: ' 👷 ci: CI related changes' }
22
+ ],
23
+
24
+ scopes: [
25
+ { name: 'components' },
26
+ { name: 'page' },
27
+ { name: 'css' },
28
+ { name: 'api' },
29
+ { name: 'README.md' },
30
+ { name: 'custom' }
31
+ ],
32
+
33
+ messages: {
34
+ type: '请选择提交类型(必填)',
35
+ scope: '请选择文件修改范围(必填):',
36
+ customScope: '请输自定义文件修改范围(必填)',
37
+ subject: '请简要描述提交(必填)',
38
+ body: '请输入详细描述(可选)',
39
+ breaking: '列出任何breaking changes(可选)',
40
+ footer: '请输入要关闭的issue(可选)',
41
+ confirmCommit: '确定提交吗'
42
+ },
43
+
44
+ allowCustomScopes: true,
45
+ allowBreakingChanges: ['✨ feat', '🐛 fix'],
46
+ subjectLimit: 49
47
+
48
+ }
49
+
50
+ ' > .cz-config.js
@@ -0,0 +1,24 @@
1
+ echo '
2
+ {
3
+ "root": true,
4
+ "parser": "@typescript-eslint/parser",
5
+ "extends": [
6
+ "eslint:recommended",
7
+ "plugin:@typescript-eslint/recommended",
8
+ "prettier"
9
+ ],
10
+ "plugins": ["@typescript-eslint", "prettier"],
11
+ "rules": {
12
+ "prettier/prettier": "error",
13
+ "arrow-body-style": "off",
14
+ "prefer-arrow-callback": "off"
15
+ }
16
+ }
17
+ ' > .eslintrc
18
+
19
+
20
+ echo '
21
+ node_modules/
22
+
23
+ README.md
24
+ ' > .eslintignore
@@ -0,0 +1,7 @@
1
+ echo '
2
+ npx lint-staged
3
+ ' > .husky/pre-commit
4
+
5
+ echo '
6
+ npx --no -- commitlint --edit "$1"
7
+ ' > .husky/commit-msg
@@ -0,0 +1,5 @@
1
+ echo '
2
+ {
3
+ "*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"]
4
+ }
5
+ ' > .lintstagedrc
@@ -0,0 +1,21 @@
1
+ echo '
2
+ {
3
+ "singleQuote": true,
4
+ "printWidth": 100,
5
+ "jsxSingleQuote": true,
6
+ "bracketSameLine": true,
7
+ "semi": false,
8
+ "plugins": ["prettier-plugin-tailwindcss"],
9
+ "tabWidth": 2,
10
+ "bracketSpacing": true,
11
+ "trailingComma": "none"
12
+ }
13
+ ' > .prettierrc
14
+
15
+ echo '
16
+ node_modules/
17
+
18
+ README.md
19
+
20
+ .cz-config.js
21
+ ' > .prettierignore