@itcase/config 1.6.48 → 1.6.49
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/commitlint/commitizenAdapter.js +98 -93
- package/package.json +9 -9
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
1
2
|
import path from 'path'
|
|
2
3
|
import { pathToFileURL } from 'url'
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
+
const COMMITLINT_CONFIG_FILES = [
|
|
6
|
+
'commitlint.config.mjs',
|
|
7
|
+
'commitlint.config.js',
|
|
8
|
+
'commitlint.config.cjs',
|
|
9
|
+
]
|
|
10
|
+
|
|
5
11
|
const SUB_SCOPE_MESSAGE = 'Select sub-scope (optional):'
|
|
6
12
|
const SUBJECT_REQUIRED = 'Subject is required'
|
|
7
13
|
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
function findCommitlintConfig() {
|
|
15
|
+
const cwd = process.cwd()
|
|
16
|
+
for (const name of COMMITLINT_CONFIG_FILES) {
|
|
17
|
+
const filePath = path.resolve(cwd, name)
|
|
18
|
+
if (fs.existsSync(filePath)) return filePath
|
|
19
|
+
}
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Commitlint config not found. Tried: ${COMMITLINT_CONFIG_FILES.join(', ')}`,
|
|
22
|
+
)
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
function buildTypeChoices(types, typeEnum) {
|
|
@@ -26,98 +33,96 @@ function buildTypeChoices(types, typeEnum) {
|
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
async function loadConfig() {
|
|
29
|
-
const
|
|
30
|
-
import('@commitlint/load'),
|
|
31
|
-
import('./commitlintProject.js'),
|
|
32
|
-
])
|
|
33
|
-
|
|
36
|
+
const { default: load } = await import('@commitlint/load')
|
|
34
37
|
const { prompt: promptOverrides, rules } = await load()
|
|
35
38
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const SCOPES = configModule.default?.SCOPES || {}
|
|
39
|
+
const configPath = findCommitlintConfig()
|
|
40
|
+
const configModule = await import(pathToFileURL(configPath).href)
|
|
41
|
+
const SCOPES = configModule.default?.SCOPES ?? {}
|
|
40
42
|
|
|
41
|
-
return {
|
|
43
|
+
return { promptOverrides, rules, SCOPES }
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
function prompter(inquirer, commit) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
async function prompter(inquirer, commit) {
|
|
47
|
+
try {
|
|
48
|
+
const { promptOverrides, rules, SCOPES } = await loadConfig()
|
|
49
|
+
|
|
50
|
+
const questions = promptOverrides?.questions ?? {}
|
|
51
|
+
const scopeEnum = rules['scope-enum']?.[2]
|
|
52
|
+
const types = rules['type-enum']?.[2]
|
|
53
|
+
if (!types?.length) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'Commitlint config must set rules["type-enum"][2] (list of types)',
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
const typeEnum = questions.type?.enum ?? {}
|
|
59
|
+
const typeChoices = buildTypeChoices(types, typeEnum)
|
|
60
|
+
|
|
61
|
+
const isScopesArray = Array.isArray(SCOPES)
|
|
62
|
+
const scopesFromConfig = isScopesArray ? SCOPES : Object.keys(SCOPES)
|
|
63
|
+
const baseScopes = Array.isArray(scopeEnum)
|
|
64
|
+
? scopeEnum.filter((s) => !s.includes(' / '))
|
|
65
|
+
: scopesFromConfig
|
|
66
|
+
const scopeList = baseScopes.length > 0 ? baseScopes : scopesFromConfig
|
|
67
|
+
|
|
68
|
+
const messages = {
|
|
69
|
+
type: questions.type?.description ?? 'Select the type of change',
|
|
70
|
+
scope: questions.scope?.description ?? 'What is the scope of this change',
|
|
71
|
+
subject: questions.subject?.description ?? 'Write a short description',
|
|
72
|
+
}
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const answers = await inquirer.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: 'list',
|
|
77
|
+
name: 'type',
|
|
78
|
+
message: messages.type,
|
|
79
|
+
choices: typeChoices,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'list',
|
|
83
|
+
name: 'scope',
|
|
84
|
+
message: messages.scope,
|
|
85
|
+
choices: scopeList.map((value) => ({ name: value, value: value })),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: 'list',
|
|
89
|
+
name: 'subScope',
|
|
90
|
+
message: SUB_SCOPE_MESSAGE,
|
|
91
|
+
choices: function (answers) {
|
|
92
|
+
const subs = isScopesArray ? [] : SCOPES[answers.scope] || []
|
|
93
|
+
return [
|
|
94
|
+
...subs.map((value) => ({ name: value, value: value })),
|
|
95
|
+
new inquirer.Separator(),
|
|
96
|
+
{ name: 'none', value: '' },
|
|
97
|
+
]
|
|
78
98
|
},
|
|
79
|
-
{
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
choices: toChoices(scopeList),
|
|
99
|
+
when: function (answers) {
|
|
100
|
+
if (isScopesArray) return false
|
|
101
|
+
const subs = SCOPES[answers.scope]
|
|
102
|
+
return answers.scope && subs?.length > 0
|
|
84
103
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
validate: (input) => (input?.trim() ? true : SUBJECT_REQUIRED),
|
|
108
|
-
},
|
|
109
|
-
])
|
|
110
|
-
|
|
111
|
-
const scope = buildScope(answers.scope, answers.subScope)
|
|
112
|
-
const header = scope
|
|
113
|
-
? `${answers.type}(${scope}): ${answers.subject.trim()}`
|
|
114
|
-
: `${answers.type}: ${answers.subject.trim()}`
|
|
115
|
-
commit(header)
|
|
116
|
-
} catch (err) {
|
|
117
|
-
console.error(err)
|
|
118
|
-
process.exit(1)
|
|
119
|
-
}
|
|
120
|
-
})()
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
type: 'input',
|
|
107
|
+
name: 'subject',
|
|
108
|
+
message: messages.subject,
|
|
109
|
+
validate: (input) => (input?.trim() ? true : SUBJECT_REQUIRED),
|
|
110
|
+
},
|
|
111
|
+
])
|
|
112
|
+
|
|
113
|
+
const scope = answers.scope
|
|
114
|
+
? answers.subScope
|
|
115
|
+
? `${answers.scope} / ${answers.subScope}`
|
|
116
|
+
: answers.scope
|
|
117
|
+
: ''
|
|
118
|
+
const header = scope
|
|
119
|
+
? `${answers.type}(${scope}): ${answers.subject.trim()}`
|
|
120
|
+
: `${answers.type}: ${answers.subject.trim()}`
|
|
121
|
+
commit(header)
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.error(err)
|
|
124
|
+
process.exit(1)
|
|
125
|
+
}
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
export { prompter }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itcase/config",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.49",
|
|
4
4
|
"author": "ITCase",
|
|
5
5
|
"description": "ITCase Config",
|
|
6
6
|
"engines": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org/"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@lerna-lite/cli": "^4.11.
|
|
35
|
-
"@lerna-lite/exec": "^4.11.
|
|
36
|
-
"@lerna-lite/list": "^4.11.
|
|
37
|
-
"@lerna-lite/run": "^4.11.
|
|
38
|
-
"@lerna-lite/watch": "^4.11.
|
|
34
|
+
"@lerna-lite/cli": "^4.11.2",
|
|
35
|
+
"@lerna-lite/exec": "^4.11.2",
|
|
36
|
+
"@lerna-lite/list": "^4.11.2",
|
|
37
|
+
"@lerna-lite/run": "^4.11.2",
|
|
38
|
+
"@lerna-lite/watch": "^4.11.2",
|
|
39
39
|
"semantic-release-lerna": "^2.17.0",
|
|
40
40
|
"chokidar-cli": "^3.0.0",
|
|
41
41
|
"@commitlint/cli": "^20.4.1",
|
|
@@ -95,12 +95,12 @@
|
|
|
95
95
|
"rollup-plugin-dts": "^6.3.0",
|
|
96
96
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
97
97
|
"rollup-preserve-directives": "^1.1.3",
|
|
98
|
-
"semantic-release": "^25.0.
|
|
98
|
+
"semantic-release": "^25.0.3",
|
|
99
99
|
"postcss-urlrewrite": "^0.3.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"@itcase/lint": "^1.1.
|
|
103
|
-
"eslint": "^
|
|
102
|
+
"@itcase/lint": "^1.1.96",
|
|
103
|
+
"eslint": "^10.0.0",
|
|
104
104
|
"husky": "^9.1.7",
|
|
105
105
|
"inquirer": "^13.2.2",
|
|
106
106
|
"lint-staged": "^16.2.7",
|