@vv0rkz/js-template 1.7.0 → 1.8.2

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.
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'fs'
3
+ import { spawnSync } from 'child_process'
4
+ import { platform } from 'os'
5
+ import { loadConfig } from './config.js'
6
+
7
+ const config = await loadConfig()
8
+ const commitMsgFile = process.argv[2]
9
+ const commitMsg = readFileSync(commitMsgFile, 'utf8').split('\n')[0].trim()
10
+
11
+ const { types, requireIssue, closeKeyword } = config.commits
12
+
13
+ if (/^chore\(release\): v\d+\.\d+\.\d+$/.test(commitMsg)) {
14
+ console.log(`✅ Авто-релизный коммит: ${commitMsg}`)
15
+ process.exit(0)
16
+ }
17
+
18
+ const escClose = closeKeyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
19
+
20
+ const issuePatterns = requireIssue
21
+ .map((t) => `${t}(\\(.+\\))?: (${escClose} )?#[0-9]+ .+`)
22
+ .join('|')
23
+
24
+ const freePatterns = types
25
+ .filter((t) => !requireIssue.includes(t))
26
+ .map((t) => `${t}(\\(.+\\))?: .+`)
27
+ .join('|')
28
+
29
+ const fullPattern = [issuePatterns, freePatterns].filter(Boolean).join('|')
30
+ const regex = new RegExp(`^(${fullPattern})$`)
31
+
32
+ if (!regex.test(commitMsg)) {
33
+ console.log(`❌ Неправильный формат коммита: '${commitMsg}'`)
34
+ showHelp()
35
+ process.exit(1)
36
+ }
37
+
38
+ for (const type of requireIssue) {
39
+ const typeMatch = new RegExp(`^${type}(\\(.+\\))?:`)
40
+ if (typeMatch.test(commitMsg)) {
41
+ const issueMatch = new RegExp(`^${type}(\\(.+\\))?: (${escClose} )?#[0-9]`)
42
+ if (!issueMatch.test(commitMsg)) {
43
+ console.log(`❌ ${type} коммиты должны содержать номер задачи`)
44
+ console.log(`💡 Твой коммит: ${commitMsg}`)
45
+ console.log(`✅ Пример: ${type}: #9 описание`)
46
+ console.log(`✅ Закрыть: ${type}: ${closeKeyword} #9 описание`)
47
+ process.exit(1)
48
+ }
49
+ }
50
+ }
51
+
52
+ const isWin = platform() === 'win32'
53
+ const npx = isWin ? 'npx.cmd' : 'npx'
54
+ const result = spawnSync(npx, ['--no', '--', 'commitlint', '--edit', commitMsgFile], {
55
+ stdio: 'inherit',
56
+ })
57
+
58
+ process.exit(result.status || 0)
59
+
60
+ function showHelp() {
61
+ console.log('')
62
+ console.log('🎯 РАЗРЕШЕННЫЕ ФОРМАТЫ КОММИТОВ:')
63
+ console.log('────────────────────────────────────')
64
+
65
+ for (const type of types) {
66
+ if (requireIssue.includes(type)) {
67
+ console.log(` ${type}: #номер описание`)
68
+ console.log(` ${type}(scope): #номер описание`)
69
+ console.log(` ${type}: ${closeKeyword} #номер описание (закрыть issue)`)
70
+ } else {
71
+ console.log(` ${type}: описание`)
72
+ console.log(` ${type}(scope): описание`)
73
+ }
74
+ }
75
+
76
+ console.log(' chore(release): vX.X.X')
77
+ console.log('')
78
+ console.log('📝 ПРИМЕРЫ:')
79
+ console.log(' feat: #9 добавить нормализацию')
80
+ console.log(' feat(Date): #9 добавить форматирование дат')
81
+ console.log(` feat: ${closeKeyword} #9 добавить нормализацию (закрыть issue)`)
82
+ console.log(` feat(parser): ${closeKeyword} #9 финализировать (scope + закрыть)`)
83
+ console.log(' fix: #10 исправить валидацию')
84
+ console.log(' refactor(utils): оптимизировать хелперы')
85
+ console.log('────────────────────────────────────')
86
+ }