@itcase/config 1.6.46 → 1.6.48
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
|
@@ -13,8 +13,9 @@ npm install --save-dev @itcase/config
|
|
|
13
13
|
Пакет предоставляет следующие конфигурации:
|
|
14
14
|
|
|
15
15
|
- **Commitlint** — проверка формата сообщений коммитов
|
|
16
|
-
- `
|
|
17
|
-
- `
|
|
16
|
+
- `createCommitlintProjectConfig(SCOPES)` — для разработки
|
|
17
|
+
- `createCommitlintReleaseConfig(SCOPES)` — для релизных веток
|
|
18
|
+
- `commitlint/commitizenAdapter.js` — адаптер Commitizen (type → scope → subScope → subject)
|
|
18
19
|
|
|
19
20
|
- **Husky** — husky-hooks
|
|
20
21
|
|
|
@@ -35,3 +36,52 @@ npm install --save-dev @itcase/config
|
|
|
35
36
|
- **SVGR** — преобразование SVG в React компоненты
|
|
36
37
|
- `svgr/index.js` — базовая конфигурация
|
|
37
38
|
- `svgr/webpack.js` — интеграция с Webpack
|
|
39
|
+
|
|
40
|
+
## Подключение Commitlint
|
|
41
|
+
|
|
42
|
+
1. Установите зависимости в проекте:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install --save-dev @itcase/config @commitlint/cli @commitlint/config-conventional conventional-changelog-conventionalcommits
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Создайте в корне проекта файл `commitlint.config.mjs`:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
import {
|
|
52
|
+
createCommitlintProjectConfig,
|
|
53
|
+
createCommitlintReleaseConfig,
|
|
54
|
+
} from '@itcase/config/commitlint/index.js'
|
|
55
|
+
|
|
56
|
+
const SCOPES = {
|
|
57
|
+
auth: [],
|
|
58
|
+
common: [],
|
|
59
|
+
dashboard: [],
|
|
60
|
+
logbook: ['events', 'filters'],
|
|
61
|
+
map: ['layers', 'controls', 'markers'],
|
|
62
|
+
report: ['monitoring', 'analytics', 'export', 'filters'],
|
|
63
|
+
other: [],
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default process.env.RELEASE_BRANCH === 'true'
|
|
67
|
+
? createCommitlintReleaseConfig(SCOPES)
|
|
68
|
+
: createCommitlintProjectConfig(SCOPES)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
3. Подключите проверку в husky (например, в `.husky/commit-msg`):
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npx commitlint --edit "$1"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
4. **(Опционально)** Интерактивное оформление коммитов через Commitizen. Установите:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm install --save-dev commitizen @commitlint/cz-commitlint
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Добавьте файл `.cz.json`
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{ "path": "@itcase/config/commitlint/commitizenAdapter.js" }
|
|
87
|
+
```
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom Commitizen adapter: type → scope → subScope (optional) → subject.
|
|
3
|
-
* Settings from commitlintProject.js; SCOPES from project commitlint.config.mjs.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
import path from 'path'
|
|
7
2
|
import { pathToFileURL } from 'url'
|
|
8
3
|
|
|
4
|
+
const COMMITLINT_CONFIG_FILE = 'commitlint.config.mjs'
|
|
9
5
|
const SUB_SCOPE_MESSAGE = 'Select sub-scope (optional):'
|
|
10
6
|
const SUBJECT_REQUIRED = 'Subject is required'
|
|
11
7
|
|
|
@@ -16,7 +12,7 @@ function buildScope(scope, subScope) {
|
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
function toChoices(values) {
|
|
19
|
-
return values.map((value) => ({ name: value, value }))
|
|
15
|
+
return values.map((value) => ({ name: value, value: value }))
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
function buildTypeChoices(types, typeEnum) {
|
|
@@ -37,8 +33,9 @@ async function loadConfig() {
|
|
|
37
33
|
|
|
38
34
|
const { prompt: promptOverrides, rules } = await load()
|
|
39
35
|
|
|
40
|
-
const
|
|
41
|
-
|
|
36
|
+
const configModule = await import(
|
|
37
|
+
pathToFileURL(path.resolve(process.cwd(), COMMITLINT_CONFIG_FILE)).href
|
|
38
|
+
)
|
|
42
39
|
const SCOPES = configModule.default?.SCOPES || {}
|
|
43
40
|
|
|
44
41
|
return { commitlintProject, promptOverrides, rules, SCOPES }
|
|
@@ -59,10 +56,12 @@ function prompter(inquirer, commit) {
|
|
|
59
56
|
const typeEnum = over?.type?.enum ?? q.type.enum
|
|
60
57
|
const typeChoices = buildTypeChoices(types, typeEnum)
|
|
61
58
|
|
|
59
|
+
const isScopesArray = Array.isArray(SCOPES)
|
|
60
|
+
const scopesFromConfig = isScopesArray ? SCOPES : Object.keys(SCOPES)
|
|
62
61
|
const baseScopes = Array.isArray(scopeEnum)
|
|
63
62
|
? scopeEnum.filter((s) => !s.includes(' / '))
|
|
64
|
-
:
|
|
65
|
-
const scopeList = baseScopes.length > 0 ? baseScopes :
|
|
63
|
+
: scopesFromConfig
|
|
64
|
+
const scopeList = baseScopes.length > 0 ? baseScopes : scopesFromConfig
|
|
66
65
|
|
|
67
66
|
const messages = {
|
|
68
67
|
type: over?.type?.description ?? q.type.description,
|
|
@@ -88,14 +87,15 @@ function prompter(inquirer, commit) {
|
|
|
88
87
|
name: 'subScope',
|
|
89
88
|
message: SUB_SCOPE_MESSAGE,
|
|
90
89
|
choices: function (answers) {
|
|
91
|
-
const subs = SCOPES[answers.scope] || []
|
|
90
|
+
const subs = isScopesArray ? [] : SCOPES[answers.scope] || []
|
|
92
91
|
return [
|
|
93
92
|
...toChoices(subs),
|
|
94
93
|
new inquirer.Separator(),
|
|
95
|
-
{ name: '
|
|
94
|
+
{ name: 'none', value: '' },
|
|
96
95
|
]
|
|
97
96
|
},
|
|
98
97
|
when: function (answers) {
|
|
98
|
+
if (isScopesArray) return false
|
|
99
99
|
const subs = SCOPES[answers.scope]
|
|
100
100
|
return answers.scope && subs?.length > 0
|
|
101
101
|
},
|
|
@@ -19,11 +19,16 @@ export const promptSubjectDescription =
|
|
|
19
19
|
'Write a short, imperative tense description of the change'
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Builds flat scope-enum list from SCOPES
|
|
23
|
-
*
|
|
22
|
+
* Builds flat scope-enum list from SCOPES.
|
|
23
|
+
* - If SCOPES is string[]: returns it as-is (no sub-scopes).
|
|
24
|
+
* - If SCOPES is Record<string, string[]>: base scopes + "scope / subScope".
|
|
25
|
+
* @param {string[] | Record<string, string[]>} scopeSubscopes
|
|
24
26
|
* @returns {string[]}
|
|
25
27
|
*/
|
|
26
28
|
export function buildScopeEnum(scopeSubscopes) {
|
|
29
|
+
if (Array.isArray(scopeSubscopes)) {
|
|
30
|
+
return [...scopeSubscopes]
|
|
31
|
+
}
|
|
27
32
|
const base = Object.keys(scopeSubscopes)
|
|
28
33
|
return [
|
|
29
34
|
...base,
|
|
@@ -8,7 +8,7 @@ import { commitlintRelease } from './commitlintRelease.js'
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @param {object} baseConfig
|
|
11
|
-
* @param {Record<string, string[]>} scopes
|
|
11
|
+
* @param {string[] | Record<string, string[]>} scopes
|
|
12
12
|
* @returns {object}
|
|
13
13
|
*/
|
|
14
14
|
function createConfig(baseConfig, scopes) {
|
|
@@ -24,7 +24,7 @@ function createConfig(baseConfig, scopes) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* @param {Record<string, string[]>} scopes
|
|
27
|
+
* @param {string[] | Record<string, string[]>} scopes
|
|
28
28
|
* @returns {object}
|
|
29
29
|
*/
|
|
30
30
|
export function createCommitlintProjectConfig(scopes) {
|
|
@@ -32,7 +32,7 @@ export function createCommitlintProjectConfig(scopes) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* @param {Record<string, string[]>} scopes
|
|
35
|
+
* @param {string[] | Record<string, string[]>} scopes
|
|
36
36
|
* @returns {object}
|
|
37
37
|
*/
|
|
38
38
|
export function createCommitlintReleaseConfig(scopes) {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './commitlintCommon.js'
|
|
9
9
|
|
|
10
10
|
const commitlintProject = {
|
|
11
|
-
parserPreset,
|
|
11
|
+
parserPreset: parserPreset,
|
|
12
12
|
ignores: [
|
|
13
13
|
(commit) => /^Merge branch/.test(commit),
|
|
14
14
|
(commit) => /^Merge pull request/.test(commit),
|
|
@@ -33,7 +33,7 @@ const commitlintProject = {
|
|
|
33
33
|
],
|
|
34
34
|
'scope-enum': [2, 'always', ['PLEASE', 'SET', 'SCOPE-ENUM']],
|
|
35
35
|
},
|
|
36
|
-
defaultIgnores,
|
|
36
|
+
defaultIgnores: defaultIgnores,
|
|
37
37
|
prompt: {
|
|
38
38
|
settings: {
|
|
39
39
|
enableMultipleScopes: true,
|
|
@@ -8,14 +8,14 @@ import {
|
|
|
8
8
|
} from './commitlintCommon.js'
|
|
9
9
|
|
|
10
10
|
const commitlintRelease = {
|
|
11
|
-
parserPreset,
|
|
11
|
+
parserPreset: parserPreset,
|
|
12
12
|
extends: ['@commitlint/config-conventional'],
|
|
13
13
|
rules: {
|
|
14
14
|
...commonRules,
|
|
15
15
|
'type-case': [0],
|
|
16
16
|
'type-enum': [2, 'always', ['patch', 'minor', 'major']],
|
|
17
17
|
},
|
|
18
|
-
defaultIgnores,
|
|
18
|
+
defaultIgnores: defaultIgnores,
|
|
19
19
|
prompt: {
|
|
20
20
|
settings: {},
|
|
21
21
|
questions: {
|