@w5s/commitlint-config 1.0.7 → 1.0.8

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/lib/index.js CHANGED
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const types_1 = require("@commitlint/types");
7
- const index_js_1 = __importDefault(require("./conventional-changelog/index.js"));
7
+ const conventional_changelog_1 = __importDefault(require("@w5s/conventional-changelog"));
8
8
  const plugin_js_1 = require("./plugin.js");
9
9
  const { Error, Warning, Disabled } = types_1.RuleConfigSeverity;
10
10
  const parserPreset = {
11
- parserOpts: index_js_1.default.parserOpts,
11
+ parserOpts: conventional_changelog_1.default.parserOpts,
12
12
  };
13
13
  const rules = {
14
14
  'body-leading-blank': [Warning, 'always'],
package/lib/plugin.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gitmojiPlugin = exports.typeValidGitmoji = exports.typeGitmojiStyle = void 0;
4
- const gitmoji_1 = require("./conventional-changelog/gitmoji");
4
+ const gitmoji_js_1 = require("@w5s/conventional-changelog/lib/gitmoji.js");
5
5
  const $if = (when = 'always') => (cond) => when === 'always' ? cond : !cond;
6
6
  const typeGitmojiStyle = (parsed, when = 'always', value = 'unicode') => {
7
- const isUnicode = parsed.type != null && gitmoji_1.Emoji.isUnicode(parsed.type);
8
- const isEmoji = parsed.type != null && gitmoji_1.Emoji.isText(parsed.type);
7
+ const isUnicode = parsed.type != null && gitmoji_js_1.Emoji.isUnicode(parsed.type);
8
+ const isEmoji = parsed.type != null && gitmoji_js_1.Emoji.isText(parsed.type);
9
9
  return value === 'unicode'
10
10
  ? $if(when)(isUnicode)
11
11
  ? [true]
@@ -16,7 +16,7 @@ const typeGitmojiStyle = (parsed, when = 'always', value = 'unicode') => {
16
16
  };
17
17
  exports.typeGitmojiStyle = typeGitmojiStyle;
18
18
  const typeValidGitmoji = (parsed, when = 'always') => {
19
- const isValidGitmoji = parsed.type != null && gitmoji_1.GitmojiCode.isValid(parsed.type);
19
+ const isValidGitmoji = parsed.type != null && gitmoji_js_1.GitmojiCode.isValid(parsed.type);
20
20
  return $if(when)(isValidGitmoji)
21
21
  ? [true]
22
22
  : [false, `Type should ${when} be an valid gitmoji (see https://gitmoji.dev)`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/commitlint-config",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Commitlint configuration presets",
5
5
  "keywords": [
6
6
  "commitlint",
@@ -65,14 +65,11 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@commitlint/types": "^17.0.0",
68
- "emoji-regex": "^10.2.1",
69
- "gitmojis": "^3.13.4"
68
+ "@w5s/conventional-changelog": "^1.0.0-alpha.1"
70
69
  },
71
70
  "devDependencies": {
72
71
  "@commitlint/lint": "17.4.2",
73
- "@jest/globals": "29.3.1",
74
- "@types/conventional-changelog-writer": "4.0.2",
75
- "@types/conventional-commits-parser": "3.0.3"
72
+ "@jest/globals": "29.4.1"
76
73
  },
77
74
  "peerDependencies": {
78
75
  "@commitlint/cli": "^16.0.0 || ^17.0.0"
@@ -88,5 +85,5 @@
88
85
  "publishConfig": {
89
86
  "access": "public"
90
87
  },
91
- "gitHead": "6fd7a3c49dc5e10d71a4b79d38194e2791d268eb"
88
+ "gitHead": "dd093c2907cf8e136f4adec9a14b176e0851de17"
92
89
  }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { RuleConfigSeverity, type QualifiedRules, type LintOptions } from '@commitlint/types';
2
- import conventionalChangelog from './conventional-changelog/index.js';
1
+ import { RuleConfigSeverity, type QualifiedRules, type LintOptions, ParserOptions } from '@commitlint/types';
2
+ import conventionalChangelog from '@w5s/conventional-changelog';
3
3
  import { gitmojiPlugin } from './plugin.js';
4
4
 
5
5
  const { Error, Warning, Disabled } = RuleConfigSeverity;
6
6
 
7
7
  const parserPreset: LintOptions = {
8
- parserOpts: conventionalChangelog.parserOpts,
8
+ parserOpts: conventionalChangelog.parserOpts as ParserOptions,
9
9
  };
10
10
 
11
11
  const rules: QualifiedRules = {
package/src/plugin.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Plugin, Rule, RuleConfigCondition } from '@commitlint/types';
2
- import { Emoji, GitmojiCode } from './conventional-changelog/gitmoji';
2
+ import { Emoji, GitmojiCode } from '@w5s/conventional-changelog/lib/gitmoji.js';
3
3
 
4
4
  const $if =
5
5
  (when: RuleConfigCondition | undefined = 'always') =>
@@ -1,27 +0,0 @@
1
- import type { Commit as CommitDefault } from 'conventional-commits-parser';
2
- export type Commit = CommitDefault<never> & {
3
- hash?: string;
4
- };
5
- export type CommitConventionalType = 'build' | 'ci' | 'docs' | 'feat' | 'fix' | 'perf' | 'refactor' | 'revert' | 'style' | 'test' | 'wip' | 'chore';
6
- export declare const CommitConventionalType: {
7
- hasInstance: (anyValue: unknown) => anyValue is CommitConventionalType;
8
- getData: (commitType: CommitConventionalType) => CommitConventionalTypeData;
9
- values: () => readonly CommitConventionalType[];
10
- parse: (anyValue: string) => CommitConventionalType | undefined;
11
- Build: "build";
12
- CI: "ci";
13
- Docs: "docs";
14
- Feat: "feat";
15
- Fix: "fix";
16
- Perf: "perf";
17
- Refactor: "refactor";
18
- Revert: "revert";
19
- Style: "style";
20
- Test: "test";
21
- WIP: "wip";
22
- Chore: "chore";
23
- };
24
- export interface CommitConventionalTypeData {
25
- emoji: string;
26
- 'en-US': string;
27
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommitConventionalType = void 0;
4
- exports.CommitConventionalType = (() => {
5
- const enumObject = Object.freeze({
6
- Build: 'build',
7
- CI: 'ci',
8
- Docs: 'docs',
9
- Feat: 'feat',
10
- Fix: 'fix',
11
- Perf: 'perf',
12
- Refactor: 'refactor',
13
- Revert: 'revert',
14
- Style: 'style',
15
- Test: 'test',
16
- WIP: 'wip',
17
- Chore: 'chore',
18
- });
19
- const enumValues = Object.freeze(Object.values(enumObject).sort());
20
- const enumValuesSet = new Set(enumValues);
21
- const typeData = {
22
- feat: {
23
- emoji: '✨',
24
- 'en-US': 'Features',
25
- },
26
- fix: {
27
- emoji: '🐛',
28
- 'en-US': 'Bug Fixes',
29
- },
30
- build: {
31
- emoji: '👷',
32
- 'en-US': 'Build System',
33
- },
34
- chore: {
35
- emoji: '🎫',
36
- 'en-US': 'Chores',
37
- },
38
- ci: {
39
- emoji: '🔧',
40
- 'en-US': 'Continuous Integration',
41
- },
42
- docs: {
43
- emoji: '📝',
44
- 'en-US': 'Documentation',
45
- },
46
- test: {
47
- emoji: '✅',
48
- 'en-US': 'Tests',
49
- },
50
- perf: {
51
- emoji: '⚡',
52
- 'en-US': 'Performance Improvements',
53
- },
54
- refactor: {
55
- emoji: '♻',
56
- 'en-US': 'Code Refactoring',
57
- },
58
- revert: {
59
- emoji: '⏪',
60
- 'en-US': 'Reverts',
61
- },
62
- style: {
63
- emoji: '💄',
64
- 'en-US': 'Styles',
65
- },
66
- wip: {
67
- emoji: '🚧',
68
- 'en-US': 'Work in progress',
69
- },
70
- };
71
- function hasInstance(anyValue) {
72
- return typeof anyValue === 'string' && enumValuesSet.has(anyValue);
73
- }
74
- function getData(commitType) {
75
- return typeData[commitType];
76
- }
77
- function parse(anyValue) {
78
- return hasInstance(anyValue) ? anyValue : undefined;
79
- }
80
- function values() {
81
- return enumValues;
82
- }
83
- return { ...enumObject, hasInstance, getData, values, parse };
84
- })();
@@ -1,28 +0,0 @@
1
- import type { CommitConventionalType } from './data';
2
- export type Emoji = Emoji.Unicode | Emoji.Text;
3
- export declare namespace Emoji {
4
- const reEmojiUnicode: RegExp;
5
- const reEmojiText: RegExp;
6
- type Unicode = string & {
7
- '@@EmojiStyle': 'unicode';
8
- };
9
- type Text = string & {
10
- '@@EmojiStyle': 'text';
11
- };
12
- function isUnicode(anyValue: string): anyValue is Unicode;
13
- function isText(anyValue: string): anyValue is Text;
14
- function hasInstance(anyValue: string): anyValue is Emoji;
15
- }
16
- export type GitmojiCode = Emoji & {
17
- '@@Gitmoji': true;
18
- };
19
- export declare namespace GitmojiCode {
20
- type Unicode = Emoji.Unicode & {
21
- '@@Gitmoji': true;
22
- };
23
- type Emoji = Emoji.Text & {
24
- '@@Gitmoji': true;
25
- };
26
- function isValid(anyValue: string): anyValue is GitmojiCode;
27
- function toConventionalCommitType(gitmoji: GitmojiCode): CommitConventionalType;
28
- }
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.GitmojiCode = exports.Emoji = void 0;
7
- const emoji_regex_1 = __importDefault(require("emoji-regex"));
8
- const gitmojis_1 = require("gitmojis");
9
- var Emoji;
10
- (function (Emoji) {
11
- Emoji.reEmojiUnicode = (0, emoji_regex_1.default)();
12
- Emoji.reEmojiText = /:(\w+):/;
13
- const reMatchOnly = (input) => new RegExp(`^${input.source}$`, input.flags);
14
- const _reEmojiUnicode = reMatchOnly(Emoji.reEmojiUnicode);
15
- const _reEmojiText = reMatchOnly(Emoji.reEmojiText);
16
- function isUnicode(anyValue) {
17
- return anyValue.match(_reEmojiUnicode) != null;
18
- }
19
- Emoji.isUnicode = isUnicode;
20
- function isText(anyValue) {
21
- return anyValue.match(_reEmojiText) != null;
22
- }
23
- Emoji.isText = isText;
24
- function hasInstance(anyValue) {
25
- return isText(anyValue) || isUnicode(anyValue);
26
- }
27
- Emoji.hasInstance = hasInstance;
28
- })(Emoji = exports.Emoji || (exports.Emoji = {}));
29
- var GitmojiCode;
30
- (function (GitmojiCode) {
31
- // export const reEmoji = emojiRegexp();
32
- const allGitmojiCodes = new Set(gitmojis_1.gitmojis
33
- .map((gitmoji) => gitmoji.code)
34
- .concat(gitmojis_1.gitmojis.map((gitmoji) => gitmoji.emoji)));
35
- const index = {
36
- // code: createIndex(gitmojis, 'code'),
37
- emoji: createIndex(gitmojis_1.gitmojis, 'emoji'),
38
- };
39
- function createIndex(list, key) {
40
- return new Map(list.map((gitmoji) => [gitmoji[key], gitmoji]));
41
- }
42
- function isValid(anyValue) {
43
- return allGitmojiCodes.has(anyValue);
44
- }
45
- GitmojiCode.isValid = isValid;
46
- const defaultType = 'chore';
47
- const conversionMap = (() => {
48
- const data = {
49
- feat: ['✨', '♿️', '🚸'],
50
- fix: ['🐛'],
51
- docs: ['📝'],
52
- style: ['🎨', '🚨'],
53
- refactor: ['♻️', '🏗️'],
54
- test: ['✅'],
55
- perf: ['⚡️'],
56
- revert: ['⏪️'],
57
- ci: ['👷', '💚'],
58
- wip: ['🚧'],
59
- build: [],
60
- chore: [],
61
- };
62
- const entries = Array.from(
63
- // @ts-ignore
64
- Object.entries(data));
65
- return new Map(entries.reduce((acc, [commitType, gitmojiUnicodeArray]) => acc
66
- .concat(gitmojiUnicodeArray.map((gitmojiUnicode) => [gitmojiUnicode, commitType]))
67
- .concat(gitmojiUnicodeArray.map((gitmojiUnicode) => [
68
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
- index.emoji.get(gitmojiUnicode)?.code,
70
- commitType,
71
- ])), []));
72
- })();
73
- function toConventionalCommitType(gitmoji) {
74
- return conversionMap.get(gitmoji) ?? defaultType;
75
- }
76
- GitmojiCode.toConventionalCommitType = toConventionalCommitType;
77
- })(GitmojiCode = exports.GitmojiCode || (exports.GitmojiCode = {}));
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- parserOpts: import("@commitlint/types").ParserOptions;
3
- };
4
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const parser_opts_1 = __importDefault(require("./parser-opts"));
7
- exports.default = {
8
- parserOpts: parser_opts_1.default,
9
- };
@@ -1,3 +0,0 @@
1
- import type { ParserOptions } from '@commitlint/types';
2
- declare const parserOpts: ParserOptions;
3
- export default parserOpts;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const gitmoji_1 = require("./gitmoji");
4
- const parserOpts = {
5
- headerPattern: new RegExp(`^(:\\w*:|${gitmoji_1.Emoji.reEmojiUnicode.source}) (?:\\((.*)\\):? )?(.*)$`),
6
- headerCorrespondence: ['type', 'scope', 'subject'],
7
- revertPattern: /^(?:revert|revert:)\s"?([\S\s]+?)"?\s*this reverts commit (\w*)\./i,
8
- noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
9
- // revertPattern: /revert:\s([\S\s]*?)\s*this reverts commit (\w*)\./i,
10
- revertCorrespondence: [`header`, `hash`],
11
- };
12
- exports.default = parserOpts;
@@ -1,20 +0,0 @@
1
- import type { Options as WriterOptions } from 'conventional-changelog-writer';
2
- import { CommitConventionalType } from './data.js';
3
- export type Language = 'en-US';
4
- export interface TransformConfig {
5
- scopeDisplayName?: Record<string, string>;
6
- displayTypes?: CommitConventionalType[];
7
- displayScopes?: string[];
8
- showAuthor?: boolean;
9
- withEmoji?: boolean;
10
- language?: Language;
11
- }
12
- export declare function displayScope(scope: string | null | undefined, scopeDisplayNameMap: Record<string, string>): string | undefined;
13
- export declare function displayType(type: CommitConventionalType, options?: displayType.Options): string;
14
- export declare namespace displayType {
15
- interface Options {
16
- readonly withEmoji?: boolean;
17
- readonly language?: Language;
18
- }
19
- }
20
- export declare function createTransform(config: TransformConfig): WriterOptions.Transform.Function;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTransform = exports.displayType = exports.displayScope = void 0;
4
- const data_js_1 = require("./data.js");
5
- const gitmoji_js_1 = require("./gitmoji.js");
6
- function displayScope(scope, scopeDisplayNameMap) {
7
- return scope == null || scope.length === 0
8
- ? scopeDisplayNameMap['*']
9
- : scopeDisplayNameMap[scope] == null
10
- ? scope
11
- : scopeDisplayNameMap[scope];
12
- }
13
- exports.displayScope = displayScope;
14
- function displayType(type, options = {}) {
15
- const { withEmoji = true, language = 'en-US' } = options;
16
- if (data_js_1.CommitConventionalType.hasInstance(type)) {
17
- const { emoji, [language]: title } = data_js_1.CommitConventionalType.getData(type);
18
- return `${withEmoji ? `${emoji} ` : ''}${title}`;
19
- }
20
- return type;
21
- }
22
- exports.displayType = displayType;
23
- function createTransform(config) {
24
- const displayTypes = new Set(config.displayTypes == null ? data_js_1.CommitConventionalType.values() : config.displayTypes);
25
- const ignoreType = (type) => type == null || !displayTypes.has(type);
26
- const ignoreScope = (scope) => config.displayScopes == null ? false : scope != null && !config.displayScopes.includes(scope);
27
- const transform = (commit, { repository, host, owner, repoUrl }) => {
28
- const discard = commit.notes.length === 0;
29
- const issues = new Set();
30
- const notes = commit.notes.map((note) => ({
31
- ...note,
32
- title: `${config.withEmoji === false ? '' : '💥 '}BREAKING CHANGES`,
33
- }));
34
- const conventionalType = commit.type == null
35
- ? undefined
36
- : data_js_1.CommitConventionalType.parse(commit.type) ??
37
- (gitmoji_js_1.GitmojiCode.isValid(commit.type) ? gitmoji_js_1.GitmojiCode.toConventionalCommitType(commit.type) : undefined);
38
- if (ignoreType(conventionalType) && discard)
39
- return false;
40
- const type = conventionalType == null
41
- ? conventionalType
42
- : displayType(conventionalType, {
43
- withEmoji: config.withEmoji,
44
- });
45
- if (ignoreScope(commit.scope))
46
- return false;
47
- const scopeIntermediate = commit.scope === '*' ? '' : commit.scope;
48
- const scope = config.scopeDisplayName == null ? scopeIntermediate : displayScope(scopeIntermediate, config.scopeDisplayName);
49
- const hash = typeof commit.hash === 'string' ? commit.hash.slice(0, 7) : commit.hash;
50
- const subject = typeof commit.subject === 'string'
51
- ? (() => {
52
- let returnValue = commit.subject;
53
- const url = repository == null ? repoUrl : [host, owner, repository].filter(Boolean).join('/');
54
- if (url != null) {
55
- const issueURL = `${url}/issues/`;
56
- // Issue URLs.
57
- returnValue = returnValue.replace(/#(\d+)/g, (_, issue) => {
58
- issues.add(issue);
59
- return `[#${issue}](${issueURL}${issue})`;
60
- });
61
- }
62
- if (host != null) {
63
- // User URLs.
64
- // eslint-disable-next-line unicorn/no-unsafe-regex
65
- returnValue = returnValue.replace(/\B@([\da-z](?:-?[\d/a-z]){0,38})/g, (_, username) => username.includes('/') ? `@${username}` : `[@${username}](${host}/${username})`);
66
- }
67
- return returnValue;
68
- })()
69
- : commit.subject;
70
- // Remove references that already appear in the subject
71
- const references = commit.references.filter((reference) => !issues.has(reference.issue));
72
- return {
73
- ...commit,
74
- type,
75
- hash,
76
- scope,
77
- subject,
78
- references,
79
- header: commit.header,
80
- body: commit.body,
81
- footer: commit.footer,
82
- merge: commit.merge,
83
- revert: commit.revert,
84
- notes,
85
- mentions: commit.mentions,
86
- };
87
- };
88
- return transform;
89
- }
90
- exports.createTransform = createTransform;
@@ -1,3 +0,0 @@
1
- import type { Options } from 'conventional-changelog-writer';
2
- declare const writerOpts: Options;
3
- export default writerOpts;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_fs_1 = require("node:fs");
4
- const node_path_1 = require("node:path");
5
- const transform_js_1 = require("./transform.js");
6
- const basePath = (0, node_path_1.resolve)(__dirname, './templates');
7
- const template = (0, node_fs_1.readFileSync)(`${basePath}/template.hbs`, 'utf8');
8
- const header = (0, node_fs_1.readFileSync)(`${basePath}/header.hbs`, 'utf8');
9
- const commit = (0, node_fs_1.readFileSync)(`${basePath}/commit.hbs`, 'utf8');
10
- const footer = (0, node_fs_1.readFileSync)(`${basePath}/footer.hbs`, 'utf8');
11
- const author = (0, node_fs_1.readFileSync)(`${basePath}/author.hbs`, 'utf8');
12
- const writerOpts = {
13
- transform: (0, transform_js_1.createTransform)({}),
14
- groupBy: 'type',
15
- commitGroupsSort: 'title',
16
- commitsSort: ['scope', 'subject'],
17
- noteGroupsSort: 'title',
18
- mainTemplate: template,
19
- headerPartial: header,
20
- commitPartial: commit.replace(/{{gitUserInfo}}/g, author),
21
- footerPartial: footer,
22
- };
23
- exports.default = writerOpts;
@@ -1,112 +0,0 @@
1
- import type { Commit as CommitDefault } from 'conventional-commits-parser';
2
-
3
- export type Commit = CommitDefault<never> & {
4
- hash?: string;
5
- };
6
-
7
- export type CommitConventionalType =
8
- | 'build'
9
- | 'ci'
10
- | 'docs'
11
- | 'feat'
12
- | 'fix'
13
- | 'perf'
14
- | 'refactor'
15
- | 'revert'
16
- | 'style'
17
- | 'test'
18
- | 'wip'
19
- | 'chore';
20
-
21
- export const CommitConventionalType = (() => {
22
- const enumObject = Object.freeze({
23
- Build: 'build',
24
- CI: 'ci',
25
- Docs: 'docs',
26
- Feat: 'feat',
27
- Fix: 'fix',
28
- Perf: 'perf',
29
- Refactor: 'refactor',
30
- Revert: 'revert',
31
- Style: 'style',
32
- Test: 'test',
33
- WIP: 'wip',
34
- Chore: 'chore',
35
- });
36
- const enumValues: readonly CommitConventionalType[] = Object.freeze(Object.values(enumObject).sort());
37
- const enumValuesSet = new Set(enumValues);
38
-
39
- const typeData: Record<CommitConventionalType, CommitConventionalTypeData> = {
40
- feat: {
41
- emoji: '✨',
42
- 'en-US': 'Features',
43
- },
44
- fix: {
45
- emoji: '🐛',
46
- 'en-US': 'Bug Fixes',
47
- },
48
- build: {
49
- emoji: '👷',
50
- 'en-US': 'Build System',
51
- },
52
- chore: {
53
- emoji: '🎫',
54
- 'en-US': 'Chores',
55
- },
56
- ci: {
57
- emoji: '🔧',
58
- 'en-US': 'Continuous Integration',
59
- },
60
- docs: {
61
- emoji: '📝',
62
- 'en-US': 'Documentation',
63
- },
64
- test: {
65
- emoji: '✅',
66
- 'en-US': 'Tests',
67
- },
68
- perf: {
69
- emoji: '⚡',
70
- 'en-US': 'Performance Improvements',
71
- },
72
- refactor: {
73
- emoji: '♻',
74
- 'en-US': 'Code Refactoring',
75
- },
76
- revert: {
77
- emoji: '⏪',
78
- 'en-US': 'Reverts',
79
- },
80
- style: {
81
- emoji: '💄',
82
- 'en-US': 'Styles',
83
- },
84
- wip: {
85
- emoji: '🚧',
86
- 'en-US': 'Work in progress',
87
- },
88
- };
89
-
90
- function hasInstance(anyValue: unknown): anyValue is CommitConventionalType {
91
- return typeof anyValue === 'string' && enumValuesSet.has(anyValue as unknown as CommitConventionalType);
92
- }
93
-
94
- function getData(commitType: CommitConventionalType): CommitConventionalTypeData {
95
- return typeData[commitType];
96
- }
97
-
98
- function parse(anyValue: string): CommitConventionalType | undefined {
99
- return hasInstance(anyValue) ? anyValue : undefined;
100
- }
101
-
102
- function values() {
103
- return enumValues;
104
- }
105
-
106
- return { ...enumObject, hasInstance, getData, values, parse };
107
- })();
108
-
109
- export interface CommitConventionalTypeData {
110
- emoji: string;
111
- 'en-US': string;
112
- }
@@ -1,98 +0,0 @@
1
- import emojiRegexp from 'emoji-regex';
2
- import { Gitmoji, gitmojis } from 'gitmojis';
3
- import type { CommitConventionalType } from './data';
4
-
5
- export type Emoji = Emoji.Unicode | Emoji.Text;
6
- export namespace Emoji {
7
- export const reEmojiUnicode = emojiRegexp();
8
-
9
- export const reEmojiText = /:(\w+):/;
10
-
11
- const reMatchOnly = (input: RegExp) => new RegExp(`^${input.source}$`, input.flags);
12
- const _reEmojiUnicode = reMatchOnly(reEmojiUnicode);
13
- const _reEmojiText = reMatchOnly(reEmojiText);
14
-
15
- export type Unicode = string & { '@@EmojiStyle': 'unicode' };
16
- export type Text = string & { '@@EmojiStyle': 'text' };
17
-
18
- export function isUnicode(anyValue: string): anyValue is Unicode {
19
- return anyValue.match(_reEmojiUnicode) != null;
20
- }
21
-
22
- export function isText(anyValue: string): anyValue is Text {
23
- return anyValue.match(_reEmojiText) != null;
24
- }
25
-
26
- export function hasInstance(anyValue: string): anyValue is Emoji {
27
- return isText(anyValue) || isUnicode(anyValue);
28
- }
29
- }
30
-
31
- export type GitmojiCode = Emoji & { '@@Gitmoji': true };
32
- export namespace GitmojiCode {
33
- export type Unicode = Emoji.Unicode & { '@@Gitmoji': true };
34
- export type Emoji = Emoji.Text & { '@@Gitmoji': true };
35
-
36
- // export const reEmoji = emojiRegexp();
37
-
38
- const allGitmojiCodes = new Set(
39
- gitmojis
40
- .map((gitmoji) => gitmoji.code as GitmojiCode)
41
- .concat(gitmojis.map((gitmoji) => gitmoji.emoji as GitmojiCode))
42
- );
43
- const index = {
44
- // code: createIndex(gitmojis, 'code'),
45
- emoji: createIndex(gitmojis, 'emoji'),
46
- };
47
-
48
- function createIndex<K extends keyof Gitmoji>(list: readonly Gitmoji[], key: K): ReadonlyMap<Gitmoji[K], Gitmoji> {
49
- return new Map(list.map((gitmoji) => [gitmoji[key], gitmoji]));
50
- }
51
-
52
- export function isValid(anyValue: string): anyValue is GitmojiCode {
53
- return allGitmojiCodes.has(anyValue as GitmojiCode);
54
- }
55
-
56
- const defaultType = 'chore';
57
- const conversionMap: ReadonlyMap<GitmojiCode, CommitConventionalType> = (() => {
58
- const data: Record<CommitConventionalType, GitmojiCode.Unicode[]> = {
59
- feat: ['✨', '♿️', '🚸'] as GitmojiCode.Unicode[],
60
- fix: ['🐛'] as GitmojiCode.Unicode[],
61
- docs: ['📝'] as GitmojiCode.Unicode[],
62
- style: ['🎨', '🚨'] as GitmojiCode.Unicode[],
63
- refactor: ['♻️', '🏗️'] as GitmojiCode.Unicode[],
64
- test: ['✅'] as GitmojiCode.Unicode[],
65
- perf: ['⚡️'] as GitmojiCode.Unicode[],
66
- revert: ['⏪️'] as GitmojiCode.Unicode[],
67
- ci: ['👷', '💚'] as GitmojiCode.Unicode[],
68
- wip: ['🚧'] as GitmojiCode.Unicode[],
69
- build: [] as GitmojiCode.Unicode[],
70
- chore: [] as GitmojiCode.Unicode[],
71
- };
72
-
73
- const entries = Array.from<[CommitConventionalType, GitmojiCode.Unicode[]]>(
74
- // @ts-ignore
75
- Object.entries(data)
76
- );
77
- return new Map(
78
- entries.reduce<Array<[GitmojiCode, CommitConventionalType]>>(
79
- (acc, [commitType, gitmojiUnicodeArray]) =>
80
- acc
81
- .concat(gitmojiUnicodeArray.map((gitmojiUnicode) => [gitmojiUnicode, commitType]))
82
-
83
- .concat(
84
- gitmojiUnicodeArray.map((gitmojiUnicode) => [
85
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
86
- index.emoji.get(gitmojiUnicode)?.code! as GitmojiCode,
87
- commitType,
88
- ])
89
- ),
90
- []
91
- )
92
- );
93
- })();
94
-
95
- export function toConventionalCommitType(gitmoji: GitmojiCode): CommitConventionalType {
96
- return conversionMap.get(gitmoji) ?? defaultType;
97
- }
98
- }
@@ -1,5 +0,0 @@
1
- import parserOpts from './parser-opts';
2
-
3
- export default {
4
- parserOpts,
5
- };
@@ -1,12 +0,0 @@
1
- import type { ParserOptions } from '@commitlint/types';
2
- import { Emoji } from './gitmoji';
3
-
4
- const parserOpts: ParserOptions = {
5
- headerPattern: new RegExp(`^(:\\w*:|${Emoji.reEmojiUnicode.source}) (?:\\((.*)\\):? )?(.*)$`),
6
- headerCorrespondence: ['type', 'scope', 'subject'],
7
- revertPattern: /^(?:revert|revert:)\s"?([\S\s]+?)"?\s*this reverts commit (\w*)\./i,
8
- noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
9
- // revertPattern: /revert:\s([\S\s]*?)\s*this reverts commit (\w*)\./i,
10
- revertCorrespondence: [`header`, `hash`],
11
- };
12
- export default parserOpts;
@@ -1,122 +0,0 @@
1
- import type { Context, Options as WriterOptions } from 'conventional-changelog-writer';
2
- import { CommitConventionalType, Commit } from './data.js';
3
- import { GitmojiCode } from './gitmoji.js';
4
-
5
- export type Language = 'en-US';
6
-
7
- export interface TransformConfig {
8
- scopeDisplayName?: Record<string, string>;
9
- displayTypes?: CommitConventionalType[];
10
- displayScopes?: string[];
11
- showAuthor?: boolean;
12
- withEmoji?: boolean;
13
- language?: Language;
14
- }
15
-
16
- export function displayScope(scope: string | null | undefined, scopeDisplayNameMap: Record<string, string>) {
17
- return scope == null || scope.length === 0
18
- ? scopeDisplayNameMap['*']
19
- : scopeDisplayNameMap[scope] == null
20
- ? scope
21
- : scopeDisplayNameMap[scope];
22
- }
23
-
24
- export function displayType(type: CommitConventionalType, options: displayType.Options = {}): string {
25
- const { withEmoji = true, language = 'en-US' } = options;
26
-
27
- if (CommitConventionalType.hasInstance(type)) {
28
- const { emoji, [language]: title } = CommitConventionalType.getData(type);
29
- return `${withEmoji ? `${emoji} ` : ''}${title}`;
30
- }
31
-
32
- return type;
33
- }
34
- export namespace displayType {
35
- export interface Options {
36
- readonly withEmoji?: boolean;
37
- readonly language?: Language;
38
- }
39
- }
40
-
41
- export function createTransform(config: TransformConfig): WriterOptions.Transform.Function {
42
- const displayTypes = new Set(config.displayTypes == null ? CommitConventionalType.values() : config.displayTypes);
43
- const ignoreType = (type: string | undefined) => type == null || !displayTypes.has(type as CommitConventionalType);
44
- const ignoreScope = (scope: string | undefined | null) =>
45
- config.displayScopes == null ? false : scope != null && !config.displayScopes.includes(scope);
46
-
47
- const transform = (commit: Commit, { repository, host, owner, repoUrl }: Context): Commit | false => {
48
- const discard = commit.notes.length === 0;
49
- const issues = new Set<string>();
50
- const notes = commit.notes.map((note) => ({
51
- ...note,
52
- title: `${config.withEmoji === false ? '' : '💥 '}BREAKING CHANGES`,
53
- }));
54
- const conventionalType =
55
- commit.type == null
56
- ? undefined
57
- : CommitConventionalType.parse(commit.type) ??
58
- (GitmojiCode.isValid(commit.type) ? GitmojiCode.toConventionalCommitType(commit.type) : undefined);
59
-
60
- if (ignoreType(conventionalType) && discard) return false;
61
-
62
- const type =
63
- conventionalType == null
64
- ? conventionalType
65
- : displayType(conventionalType, {
66
- withEmoji: config.withEmoji,
67
- });
68
-
69
- if (ignoreScope(commit.scope)) return false;
70
-
71
- const scopeIntermediate = commit.scope === '*' ? '' : commit.scope;
72
- const scope =
73
- config.scopeDisplayName == null ? scopeIntermediate : displayScope(scopeIntermediate, config.scopeDisplayName);
74
- const hash = typeof commit.hash === 'string' ? commit.hash.slice(0, 7) : commit.hash;
75
-
76
- const subject =
77
- typeof commit.subject === 'string'
78
- ? (() => {
79
- let returnValue = commit.subject;
80
- const url = repository == null ? repoUrl : [host, owner, repository].filter(Boolean).join('/');
81
- if (url != null) {
82
- const issueURL = `${url}/issues/`;
83
- // Issue URLs.
84
- returnValue = returnValue.replace(/#(\d+)/g, (_, issue: string) => {
85
- issues.add(issue);
86
-
87
- return `[#${issue}](${issueURL}${issue})`;
88
- });
89
- }
90
- if (host != null) {
91
- // User URLs.
92
- // eslint-disable-next-line unicorn/no-unsafe-regex
93
- returnValue = returnValue.replace(/\B@([\da-z](?:-?[\d/a-z]){0,38})/g, (_, username: string) =>
94
- username.includes('/') ? `@${username}` : `[@${username}](${host}/${username})`
95
- );
96
- }
97
- return returnValue;
98
- })()
99
- : commit.subject;
100
-
101
- // Remove references that already appear in the subject
102
- const references = commit.references.filter((reference) => !issues.has(reference.issue));
103
-
104
- return {
105
- ...commit,
106
- type,
107
- hash,
108
- scope,
109
- subject,
110
- references,
111
- header: commit.header,
112
- body: commit.body,
113
- footer: commit.footer,
114
- merge: commit.merge,
115
- revert: commit.revert,
116
- notes,
117
- mentions: commit.mentions,
118
- };
119
- };
120
-
121
- return transform as unknown as WriterOptions.Transform.Function;
122
- }
@@ -1,26 +0,0 @@
1
- import type { Options } from 'conventional-changelog-writer';
2
- import { readFileSync } from 'node:fs';
3
- import { resolve } from 'node:path';
4
- import { createTransform } from './transform.js';
5
-
6
- const basePath = resolve(__dirname, './templates');
7
-
8
- const template = readFileSync(`${basePath}/template.hbs`, 'utf8');
9
- const header = readFileSync(`${basePath}/header.hbs`, 'utf8');
10
- const commit = readFileSync(`${basePath}/commit.hbs`, 'utf8');
11
- const footer = readFileSync(`${basePath}/footer.hbs`, 'utf8');
12
- const author = readFileSync(`${basePath}/author.hbs`, 'utf8');
13
-
14
- const writerOpts: Options = {
15
- transform: createTransform({}),
16
- groupBy: 'type',
17
- commitGroupsSort: 'title',
18
- commitsSort: ['scope', 'subject'],
19
- noteGroupsSort: 'title',
20
- mainTemplate: template,
21
- headerPartial: header,
22
- commitPartial: commit.replace(/{{gitUserInfo}}/g, author),
23
- footerPartial: footer,
24
- };
25
-
26
- export default writerOpts;