@icebreakers/commitlint-config 1.0.4 → 1.1.1

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/dist/index.cjs CHANGED
@@ -1,87 +1,211 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
2
-
3
-
4
-
5
-
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts
2
+ var _configconventional = require('@commitlint/config-conventional'); var _configconventional2 = _interopRequireDefault(_configconventional);
6
3
  var _types = require('@commitlint/types');
7
-
8
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
9
- function isPlainObject(value) {
10
- if (value === null || typeof value !== "object") {
11
- return false;
4
+ var DEFAULT_EXTENDS = ["@commitlint/config-conventional"];
5
+ var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
6
+ function asArray(value) {
7
+ if (value === void 0) {
8
+ return [];
12
9
  }
13
- const prototype = Object.getPrototypeOf(value);
14
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
15
- return false;
16
- }
17
- if (Symbol.iterator in value) {
18
- return false;
10
+ return Array.isArray(value) ? value : [value];
11
+ }
12
+ function mergeUnique(values) {
13
+ const seen = /* @__PURE__ */ new Set();
14
+ const result = [];
15
+ for (const value of values) {
16
+ if (value === void 0 || value === null) {
17
+ continue;
18
+ }
19
+ if (!seen.has(value)) {
20
+ seen.add(value);
21
+ result.push(value);
22
+ }
19
23
  }
20
- if (Symbol.toStringTag in value) {
21
- return Object.prototype.toString.call(value) === "[object Module]";
24
+ return result;
25
+ }
26
+ function resolveBaseTypeRule() {
27
+ const rule = _optionalChain([_configconventional2.default, 'access', _ => _.rules, 'optionalAccess', _2 => _2["type-enum"]]);
28
+ if (Array.isArray(rule)) {
29
+ const severity = _nullishCoalesce(rule[0], () => ( _types.RuleConfigSeverity.Error));
30
+ const condition = _nullishCoalesce(rule[1], () => ( "always"));
31
+ const values = _nullishCoalesce(rule[2], () => ( []));
32
+ return {
33
+ severity,
34
+ condition,
35
+ values: [...values]
36
+ };
22
37
  }
23
- return true;
38
+ return {
39
+ severity: _types.RuleConfigSeverity.Error,
40
+ condition: "always",
41
+ values: []
42
+ };
24
43
  }
25
- function _defu(baseObject, defaults, namespace = ".", merger) {
26
- if (!isPlainObject(defaults)) {
27
- return _defu(baseObject, {}, namespace, merger);
44
+ function buildTypesConfig(options) {
45
+ if (!options) {
46
+ return {};
28
47
  }
29
- const object = Object.assign({}, defaults);
30
- for (const key in baseObject) {
31
- if (key === "__proto__" || key === "constructor") {
32
- continue;
48
+ const baseRule = resolveBaseTypeRule();
49
+ const additional = mergeUnique([
50
+ ...baseRule.values,
51
+ ...mergeUnique(_nullishCoalesce(options.add, () => ( []))),
52
+ ...mergeUnique((_nullishCoalesce(options.definitions, () => ( []))).map((definition) => definition.value))
53
+ ]);
54
+ let rule;
55
+ if (additional.length > 0) {
56
+ rule = [
57
+ _nullishCoalesce(options.severity, () => ( baseRule.severity)),
58
+ _nullishCoalesce(options.condition, () => ( baseRule.condition)),
59
+ additional
60
+ ];
61
+ }
62
+ if (!_optionalChain([options, 'access', _3 => _3.definitions, 'optionalAccess', _4 => _4.length])) {
63
+ return { rule };
64
+ }
65
+ const basePromptType = _optionalChain([_configconventional2.default, 'access', _5 => _5.prompt, 'optionalAccess', _6 => _6.questions, 'optionalAccess', _7 => _7.type]);
66
+ const mergedEnum = {
67
+ ..._nullishCoalesce(_optionalChain([basePromptType, 'optionalAccess', _8 => _8.enum]), () => ( {}))
68
+ };
69
+ for (const definition of options.definitions) {
70
+ const { value, title, description, emoji } = definition;
71
+ mergedEnum[value] = {
72
+ ..._nullishCoalesce(mergedEnum[value], () => ( {})),
73
+ title,
74
+ description,
75
+ emoji
76
+ };
77
+ }
78
+ const prompt = {
79
+ ..._nullishCoalesce(_configconventional2.default.prompt, () => ( {})),
80
+ questions: {
81
+ ..._nullishCoalesce(_optionalChain([_configconventional2.default, 'access', _9 => _9.prompt, 'optionalAccess', _10 => _10.questions]), () => ( {})),
82
+ type: {
83
+ ..._nullishCoalesce(basePromptType, () => ( {})),
84
+ enum: mergedEnum
85
+ }
33
86
  }
34
- const value = baseObject[key];
35
- if (value === null || value === void 0) {
36
- continue;
87
+ };
88
+ return { rule, prompt };
89
+ }
90
+ function buildScopeRules(options) {
91
+ if (!options) {
92
+ return {};
93
+ }
94
+ const rules = {};
95
+ const severity = _nullishCoalesce(options.severity, () => ( _types.RuleConfigSeverity.Error));
96
+ const scopeValues = mergeUnique(asArray(options.values));
97
+ if (scopeValues.length > 0) {
98
+ rules["scope-enum"] = [severity, "always", scopeValues];
99
+ }
100
+ if (options.required !== void 0) {
101
+ if (options.required) {
102
+ rules["scope-empty"] = [severity, "never"];
103
+ } else {
104
+ rules["scope-empty"] = [_types.RuleConfigSeverity.Disabled];
37
105
  }
38
- if (merger && merger(object, key, value, namespace)) {
39
- continue;
106
+ }
107
+ const scopeCases = mergeUnique(asArray(options.case));
108
+ if (scopeCases.length > 0) {
109
+ rules["scope-case"] = [severity, "always", scopeCases];
110
+ }
111
+ return rules;
112
+ }
113
+ function buildSubjectRules(options) {
114
+ if (!options) {
115
+ return {};
116
+ }
117
+ const rules = {};
118
+ const forbiddenCases = mergeUnique(asArray(options.forbidden));
119
+ if (forbiddenCases.length > 0) {
120
+ rules["subject-case"] = [
121
+ _nullishCoalesce(options.caseSeverity, () => ( _types.RuleConfigSeverity.Error)),
122
+ _nullishCoalesce(options.caseCondition, () => ( "never")),
123
+ forbiddenCases
124
+ ];
125
+ }
126
+ if (options.allowEmpty !== void 0) {
127
+ if (options.allowEmpty) {
128
+ rules["subject-empty"] = [_types.RuleConfigSeverity.Disabled];
129
+ } else {
130
+ rules["subject-empty"] = [
131
+ _nullishCoalesce(options.allowEmptySeverity, () => ( _types.RuleConfigSeverity.Error)),
132
+ "never"
133
+ ];
40
134
  }
41
- if (Array.isArray(value) && Array.isArray(object[key])) {
42
- object[key] = [...value, ...object[key]];
43
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
44
- object[key] = _defu(
45
- value,
46
- object[key],
47
- (namespace ? `${namespace}.` : "") + key.toString(),
48
- merger
49
- );
135
+ }
136
+ if (options.fullStop !== void 0) {
137
+ if (options.fullStop) {
138
+ rules["subject-full-stop"] = [
139
+ _nullishCoalesce(options.fullStopSeverity, () => ( _types.RuleConfigSeverity.Error)),
140
+ "always",
141
+ _nullishCoalesce(options.fullStopCharacter, () => ( "."))
142
+ ];
50
143
  } else {
51
- object[key] = value;
144
+ rules["subject-full-stop"] = [_types.RuleConfigSeverity.Disabled];
52
145
  }
53
146
  }
54
- return object;
147
+ return rules;
55
148
  }
56
- function createDefu(merger) {
57
- return (...arguments_) => (
58
- // eslint-disable-next-line unicorn/no-array-reduce
59
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
60
- );
149
+ function buildHeaderRules(options) {
150
+ if (!options) {
151
+ return {};
152
+ }
153
+ const rules = {};
154
+ const severity = _nullishCoalesce(options.severity, () => ( _types.RuleConfigSeverity.Error));
155
+ const condition = _nullishCoalesce(options.condition, () => ( "always"));
156
+ if (options.maxLength !== void 0) {
157
+ rules["header-max-length"] = [severity, condition, options.maxLength];
158
+ }
159
+ return rules;
61
160
  }
62
- var defu = createDefu();
63
- var defuFn = createDefu((object, key, currentValue) => {
64
- if (object[key] !== void 0 && typeof currentValue === "function") {
65
- object[key] = currentValue(object[key]);
66
- return true;
67
- }
68
- });
69
- var defuArrayFn = createDefu((object, key, currentValue) => {
70
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
71
- object[key] = currentValue(object[key]);
72
- return true;
73
- }
74
- });
75
-
76
- // src/index.ts
77
- function icebreaker(config) {
78
- return defu(config, {
79
- extends: ["@commitlint/config-conventional"]
80
- });
161
+ function mergePrompts(base, override) {
162
+ if (!base && !override) {
163
+ return void 0;
164
+ }
165
+ if (!base) {
166
+ return override;
167
+ }
168
+ if (!override) {
169
+ return base;
170
+ }
171
+ return {
172
+ ...base,
173
+ ...override,
174
+ questions: {
175
+ ..._nullishCoalesce(base.questions, () => ( {})),
176
+ ..._nullishCoalesce(override.questions, () => ( {}))
177
+ }
178
+ };
179
+ }
180
+ function createIcebreakerCommitlintConfig(options = {}) {
181
+ const { types, scopes, subject, header } = options;
182
+ const extendsList = mergeUnique([
183
+ ...DEFAULT_EXTENDS,
184
+ ...mergeUnique(_nullishCoalesce(options.extends, () => ( [])))
185
+ ]);
186
+ const rules = {
187
+ ...buildScopeRules(scopes),
188
+ ...buildSubjectRules(subject),
189
+ ...buildHeaderRules(header)
190
+ };
191
+ const typesConfig = buildTypesConfig(types);
192
+ if (typesConfig.rule) {
193
+ rules["type-enum"] = typesConfig.rule;
194
+ }
195
+ const mergedRules = {
196
+ ...rules,
197
+ ..._nullishCoalesce(options.rules, () => ( {}))
198
+ };
199
+ const hasRules = Object.keys(mergedRules).length > 0;
200
+ const prompt = mergePrompts(typesConfig.prompt, options.prompt);
201
+ return {
202
+ extends: extendsList,
203
+ parserPreset: DEFAULT_PARSER_PRESET,
204
+ ...hasRules ? { rules: mergedRules } : {},
205
+ ...prompt ? { prompt } : {}
206
+ };
81
207
  }
82
208
 
83
209
 
84
210
 
85
-
86
-
87
- exports.RuleConfigCondition = _types.RuleConfigCondition; exports.RuleConfigSeverity = _types.RuleConfigSeverity; exports.TargetCaseType = _types.TargetCaseType; exports.icebreaker = icebreaker;
211
+ exports.RuleConfigSeverity = _types.RuleConfigSeverity; exports.createIcebreakerCommitlintConfig = createIcebreakerCommitlintConfig;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,48 @@
1
- import { UserConfig } from '@commitlint/types';
2
- export { RuleConfigCondition, RuleConfigSeverity, TargetCaseType, UserConfig } from '@commitlint/types';
1
+ import { RuleConfigCondition, RuleConfigSeverity, TargetCaseType, RulesConfig, UserPromptConfig, UserConfig } from '@commitlint/types';
2
+ export { UserConfig as CommitlintUserConfig, RuleConfigSeverity } from '@commitlint/types';
3
3
 
4
- declare function icebreaker(config?: UserConfig): UserConfig;
4
+ interface CommitTypeDefinition {
5
+ value: string;
6
+ title?: string;
7
+ description?: string;
8
+ emoji?: string;
9
+ }
10
+ interface CommitTypesOptions {
11
+ add?: string[];
12
+ definitions?: CommitTypeDefinition[];
13
+ condition?: RuleConfigCondition;
14
+ severity?: RuleConfigSeverity;
15
+ }
16
+ interface CommitScopeOptions {
17
+ values?: string[];
18
+ required?: boolean;
19
+ case?: TargetCaseType | TargetCaseType[];
20
+ severity?: RuleConfigSeverity;
21
+ }
22
+ interface CommitSubjectOptions {
23
+ forbidden?: TargetCaseType | TargetCaseType[];
24
+ caseCondition?: RuleConfigCondition;
25
+ caseSeverity?: RuleConfigSeverity;
26
+ allowEmpty?: boolean;
27
+ allowEmptySeverity?: RuleConfigSeverity;
28
+ fullStop?: boolean;
29
+ fullStopSeverity?: RuleConfigSeverity;
30
+ fullStopCharacter?: string;
31
+ }
32
+ interface CommitHeaderOptions {
33
+ maxLength?: number;
34
+ condition?: RuleConfigCondition;
35
+ severity?: RuleConfigSeverity;
36
+ }
37
+ interface IcebreakerCommitlintOptions {
38
+ extends?: string[];
39
+ rules?: Partial<RulesConfig>;
40
+ types?: CommitTypesOptions;
41
+ scopes?: CommitScopeOptions;
42
+ subject?: CommitSubjectOptions;
43
+ header?: CommitHeaderOptions;
44
+ prompt?: UserPromptConfig;
45
+ }
46
+ declare function createIcebreakerCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
5
47
 
6
- export { icebreaker };
48
+ export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,48 @@
1
- import { UserConfig } from '@commitlint/types';
2
- export { RuleConfigCondition, RuleConfigSeverity, TargetCaseType, UserConfig } from '@commitlint/types';
1
+ import { RuleConfigCondition, RuleConfigSeverity, TargetCaseType, RulesConfig, UserPromptConfig, UserConfig } from '@commitlint/types';
2
+ export { UserConfig as CommitlintUserConfig, RuleConfigSeverity } from '@commitlint/types';
3
3
 
4
- declare function icebreaker(config?: UserConfig): UserConfig;
4
+ interface CommitTypeDefinition {
5
+ value: string;
6
+ title?: string;
7
+ description?: string;
8
+ emoji?: string;
9
+ }
10
+ interface CommitTypesOptions {
11
+ add?: string[];
12
+ definitions?: CommitTypeDefinition[];
13
+ condition?: RuleConfigCondition;
14
+ severity?: RuleConfigSeverity;
15
+ }
16
+ interface CommitScopeOptions {
17
+ values?: string[];
18
+ required?: boolean;
19
+ case?: TargetCaseType | TargetCaseType[];
20
+ severity?: RuleConfigSeverity;
21
+ }
22
+ interface CommitSubjectOptions {
23
+ forbidden?: TargetCaseType | TargetCaseType[];
24
+ caseCondition?: RuleConfigCondition;
25
+ caseSeverity?: RuleConfigSeverity;
26
+ allowEmpty?: boolean;
27
+ allowEmptySeverity?: RuleConfigSeverity;
28
+ fullStop?: boolean;
29
+ fullStopSeverity?: RuleConfigSeverity;
30
+ fullStopCharacter?: string;
31
+ }
32
+ interface CommitHeaderOptions {
33
+ maxLength?: number;
34
+ condition?: RuleConfigCondition;
35
+ severity?: RuleConfigSeverity;
36
+ }
37
+ interface IcebreakerCommitlintOptions {
38
+ extends?: string[];
39
+ rules?: Partial<RulesConfig>;
40
+ types?: CommitTypesOptions;
41
+ scopes?: CommitScopeOptions;
42
+ subject?: CommitSubjectOptions;
43
+ header?: CommitHeaderOptions;
44
+ prompt?: UserPromptConfig;
45
+ }
46
+ declare function createIcebreakerCommitlintConfig(options?: IcebreakerCommitlintOptions): UserConfig;
5
47
 
6
- export { icebreaker };
48
+ export { type CommitHeaderOptions, type CommitScopeOptions, type CommitSubjectOptions, type CommitTypeDefinition, type CommitTypesOptions, type IcebreakerCommitlintOptions, createIcebreakerCommitlintConfig };
package/dist/index.mjs CHANGED
@@ -1,87 +1,211 @@
1
1
  // src/index.ts
2
- import {
3
- RuleConfigCondition,
4
- RuleConfigSeverity,
5
- TargetCaseType
6
- } from "@commitlint/types";
7
-
8
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
9
- function isPlainObject(value) {
10
- if (value === null || typeof value !== "object") {
11
- return false;
12
- }
13
- const prototype = Object.getPrototypeOf(value);
14
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
15
- return false;
2
+ import conventionalConfig from "@commitlint/config-conventional";
3
+ import { RuleConfigSeverity } from "@commitlint/types";
4
+ var DEFAULT_EXTENDS = ["@commitlint/config-conventional"];
5
+ var DEFAULT_PARSER_PRESET = "conventional-changelog-conventionalcommits";
6
+ function asArray(value) {
7
+ if (value === void 0) {
8
+ return [];
16
9
  }
17
- if (Symbol.iterator in value) {
18
- return false;
10
+ return Array.isArray(value) ? value : [value];
11
+ }
12
+ function mergeUnique(values) {
13
+ const seen = /* @__PURE__ */ new Set();
14
+ const result = [];
15
+ for (const value of values) {
16
+ if (value === void 0 || value === null) {
17
+ continue;
18
+ }
19
+ if (!seen.has(value)) {
20
+ seen.add(value);
21
+ result.push(value);
22
+ }
19
23
  }
20
- if (Symbol.toStringTag in value) {
21
- return Object.prototype.toString.call(value) === "[object Module]";
24
+ return result;
25
+ }
26
+ function resolveBaseTypeRule() {
27
+ const rule = conventionalConfig.rules?.["type-enum"];
28
+ if (Array.isArray(rule)) {
29
+ const severity = rule[0] ?? RuleConfigSeverity.Error;
30
+ const condition = rule[1] ?? "always";
31
+ const values = rule[2] ?? [];
32
+ return {
33
+ severity,
34
+ condition,
35
+ values: [...values]
36
+ };
22
37
  }
23
- return true;
38
+ return {
39
+ severity: RuleConfigSeverity.Error,
40
+ condition: "always",
41
+ values: []
42
+ };
24
43
  }
25
- function _defu(baseObject, defaults, namespace = ".", merger) {
26
- if (!isPlainObject(defaults)) {
27
- return _defu(baseObject, {}, namespace, merger);
44
+ function buildTypesConfig(options) {
45
+ if (!options) {
46
+ return {};
28
47
  }
29
- const object = Object.assign({}, defaults);
30
- for (const key in baseObject) {
31
- if (key === "__proto__" || key === "constructor") {
32
- continue;
48
+ const baseRule = resolveBaseTypeRule();
49
+ const additional = mergeUnique([
50
+ ...baseRule.values,
51
+ ...mergeUnique(options.add ?? []),
52
+ ...mergeUnique((options.definitions ?? []).map((definition) => definition.value))
53
+ ]);
54
+ let rule;
55
+ if (additional.length > 0) {
56
+ rule = [
57
+ options.severity ?? baseRule.severity,
58
+ options.condition ?? baseRule.condition,
59
+ additional
60
+ ];
61
+ }
62
+ if (!options.definitions?.length) {
63
+ return { rule };
64
+ }
65
+ const basePromptType = conventionalConfig.prompt?.questions?.type;
66
+ const mergedEnum = {
67
+ ...basePromptType?.enum ?? {}
68
+ };
69
+ for (const definition of options.definitions) {
70
+ const { value, title, description, emoji } = definition;
71
+ mergedEnum[value] = {
72
+ ...mergedEnum[value] ?? {},
73
+ title,
74
+ description,
75
+ emoji
76
+ };
77
+ }
78
+ const prompt = {
79
+ ...conventionalConfig.prompt ?? {},
80
+ questions: {
81
+ ...conventionalConfig.prompt?.questions ?? {},
82
+ type: {
83
+ ...basePromptType ?? {},
84
+ enum: mergedEnum
85
+ }
33
86
  }
34
- const value = baseObject[key];
35
- if (value === null || value === void 0) {
36
- continue;
87
+ };
88
+ return { rule, prompt };
89
+ }
90
+ function buildScopeRules(options) {
91
+ if (!options) {
92
+ return {};
93
+ }
94
+ const rules = {};
95
+ const severity = options.severity ?? RuleConfigSeverity.Error;
96
+ const scopeValues = mergeUnique(asArray(options.values));
97
+ if (scopeValues.length > 0) {
98
+ rules["scope-enum"] = [severity, "always", scopeValues];
99
+ }
100
+ if (options.required !== void 0) {
101
+ if (options.required) {
102
+ rules["scope-empty"] = [severity, "never"];
103
+ } else {
104
+ rules["scope-empty"] = [RuleConfigSeverity.Disabled];
37
105
  }
38
- if (merger && merger(object, key, value, namespace)) {
39
- continue;
106
+ }
107
+ const scopeCases = mergeUnique(asArray(options.case));
108
+ if (scopeCases.length > 0) {
109
+ rules["scope-case"] = [severity, "always", scopeCases];
110
+ }
111
+ return rules;
112
+ }
113
+ function buildSubjectRules(options) {
114
+ if (!options) {
115
+ return {};
116
+ }
117
+ const rules = {};
118
+ const forbiddenCases = mergeUnique(asArray(options.forbidden));
119
+ if (forbiddenCases.length > 0) {
120
+ rules["subject-case"] = [
121
+ options.caseSeverity ?? RuleConfigSeverity.Error,
122
+ options.caseCondition ?? "never",
123
+ forbiddenCases
124
+ ];
125
+ }
126
+ if (options.allowEmpty !== void 0) {
127
+ if (options.allowEmpty) {
128
+ rules["subject-empty"] = [RuleConfigSeverity.Disabled];
129
+ } else {
130
+ rules["subject-empty"] = [
131
+ options.allowEmptySeverity ?? RuleConfigSeverity.Error,
132
+ "never"
133
+ ];
40
134
  }
41
- if (Array.isArray(value) && Array.isArray(object[key])) {
42
- object[key] = [...value, ...object[key]];
43
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
44
- object[key] = _defu(
45
- value,
46
- object[key],
47
- (namespace ? `${namespace}.` : "") + key.toString(),
48
- merger
49
- );
135
+ }
136
+ if (options.fullStop !== void 0) {
137
+ if (options.fullStop) {
138
+ rules["subject-full-stop"] = [
139
+ options.fullStopSeverity ?? RuleConfigSeverity.Error,
140
+ "always",
141
+ options.fullStopCharacter ?? "."
142
+ ];
50
143
  } else {
51
- object[key] = value;
144
+ rules["subject-full-stop"] = [RuleConfigSeverity.Disabled];
52
145
  }
53
146
  }
54
- return object;
147
+ return rules;
148
+ }
149
+ function buildHeaderRules(options) {
150
+ if (!options) {
151
+ return {};
152
+ }
153
+ const rules = {};
154
+ const severity = options.severity ?? RuleConfigSeverity.Error;
155
+ const condition = options.condition ?? "always";
156
+ if (options.maxLength !== void 0) {
157
+ rules["header-max-length"] = [severity, condition, options.maxLength];
158
+ }
159
+ return rules;
55
160
  }
56
- function createDefu(merger) {
57
- return (...arguments_) => (
58
- // eslint-disable-next-line unicorn/no-array-reduce
59
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
60
- );
161
+ function mergePrompts(base, override) {
162
+ if (!base && !override) {
163
+ return void 0;
164
+ }
165
+ if (!base) {
166
+ return override;
167
+ }
168
+ if (!override) {
169
+ return base;
170
+ }
171
+ return {
172
+ ...base,
173
+ ...override,
174
+ questions: {
175
+ ...base.questions ?? {},
176
+ ...override.questions ?? {}
177
+ }
178
+ };
61
179
  }
62
- var defu = createDefu();
63
- var defuFn = createDefu((object, key, currentValue) => {
64
- if (object[key] !== void 0 && typeof currentValue === "function") {
65
- object[key] = currentValue(object[key]);
66
- return true;
67
- }
68
- });
69
- var defuArrayFn = createDefu((object, key, currentValue) => {
70
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
71
- object[key] = currentValue(object[key]);
72
- return true;
73
- }
74
- });
75
-
76
- // src/index.ts
77
- function icebreaker(config) {
78
- return defu(config, {
79
- extends: ["@commitlint/config-conventional"]
80
- });
180
+ function createIcebreakerCommitlintConfig(options = {}) {
181
+ const { types, scopes, subject, header } = options;
182
+ const extendsList = mergeUnique([
183
+ ...DEFAULT_EXTENDS,
184
+ ...mergeUnique(options.extends ?? [])
185
+ ]);
186
+ const rules = {
187
+ ...buildScopeRules(scopes),
188
+ ...buildSubjectRules(subject),
189
+ ...buildHeaderRules(header)
190
+ };
191
+ const typesConfig = buildTypesConfig(types);
192
+ if (typesConfig.rule) {
193
+ rules["type-enum"] = typesConfig.rule;
194
+ }
195
+ const mergedRules = {
196
+ ...rules,
197
+ ...options.rules ?? {}
198
+ };
199
+ const hasRules = Object.keys(mergedRules).length > 0;
200
+ const prompt = mergePrompts(typesConfig.prompt, options.prompt);
201
+ return {
202
+ extends: extendsList,
203
+ parserPreset: DEFAULT_PARSER_PRESET,
204
+ ...hasRules ? { rules: mergedRules } : {},
205
+ ...prompt ? { prompt } : {}
206
+ };
81
207
  }
82
208
  export {
83
- RuleConfigCondition,
84
209
  RuleConfigSeverity,
85
- TargetCaseType,
86
- icebreaker
210
+ createIcebreakerCommitlintConfig
87
211
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/commitlint-config",
3
3
  "type": "module",
4
- "version": "1.0.4",
4
+ "version": "1.1.1",
5
5
  "description": "icebreaker's commitlint config",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",