From 313a7896ebbebf7004862f99bc7f5e56c3d5132b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hegyi=20=C3=81ron=20Ferenc?= Date: Fri, 26 Jan 2024 12:24:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20remove!:=20support=20for=20alias?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++----- eemoji.config.ts | 3 ++- src/commands/run.ts | 4 +++- src/config.ts | 12 ++++++------ src/eemoji.ts | 4 ++-- src/presets/default.json | 2 +- src/presets/default.jsonc | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 91380e1..f471f6c 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,6 @@ This is useful for conventional commit scopes, but you can include the subtype a Notes: - the `'.'` is the fallback subtype -- specify multiple aliases for a type by separating them with pipes: `feat|feature` - specify multiple emojis by separating them with commas and a **random** one will be chosen: `๐Ÿ’Ž,๐Ÿ’ฒ,๐Ÿ’ธ,๐Ÿ’ฐ` ```ts @@ -257,20 +256,20 @@ import { defineConfig } from 'eemoji' export default defineConfig({ emojis: { - 'fix': { + fix: { '.': '๐Ÿ”ง', 'typo': 'โœ๏ธ', 'bug': '๐Ÿ›' }, - 'chore': { + chore: { '.': '๐Ÿ—‘๏ธ', 'release': '๐Ÿ”–', 'cleanup': '๐Ÿงน', 'license': '๐Ÿ“œ', 'deps': '๐Ÿ“ฆ' }, - 'feat|feature': 'โœจ', - 'bounty': '๐Ÿ’Ž,๐Ÿ’ฒ,๐Ÿ’ธ,๐Ÿ’ฐ' + feat: 'โœจ', + bounty: '๐Ÿ’Ž,๐Ÿ’ฒ,๐Ÿ’ธ,๐Ÿ’ฐ' } }) ``` diff --git a/eemoji.config.ts b/eemoji.config.ts index 63816a4..94f7ce4 100644 --- a/eemoji.config.ts +++ b/eemoji.config.ts @@ -1,4 +1,5 @@ -import { defineDefaultConfig } from 'eemoji' +/* eslint-disable antfu/no-import-dist */ +import { defineDefaultConfig } from './dist/index.mjs' export default defineDefaultConfig({ emojis: { diff --git a/src/commands/run.ts b/src/commands/run.ts index 3813ce3..60e3885 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -49,8 +49,10 @@ export default defineCommand({ if (ctx.args.test) { let initial = createExampleCommitMessage(config) - if (fs.existsSync(ctx.args.commit_file)) + if (fs.existsSync(ctx.args.commit_file)) { initial = unemojify(fs.readFileSync(ctx.args.commit_file, 'utf-8'), config) + initial = initial.split('\n')[0] ?? '' + } commitMessage = await consola.prompt('Commit message:', { placeholder: 'enter a commit message for testing...', diff --git a/src/config.ts b/src/config.ts index 0f687f2..ce15bfb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,14 +14,13 @@ const entryDir = path.dirname(fileURLToPath( ), )) -type PipePropName = T extends `${infer First}|${infer _}` ? First : T - type StringOrOptionalProp = { [K in keyof T as K extends 'breaking' ? never : - PipePropName]: T[K] | Record + K]: T[K] | Record } type EmojiType = StringOrOptionalProp & { breaking: string } + export type EmojiConfig = Record> type DefineConfig = Partial<{ @@ -119,14 +118,15 @@ export function defineConfig(config: DefineConfig): Config { export function defineDefaultConfig(config: DefineConfig): Config { const defaultConfig = new ConfigObject().defaultConfig - const emojis = mergeEmojis(config.emojis) + const { emojis, ...rest } = config + const mergedEmojis = mergeEmojis(emojis) - return merge({}, defaultConfig, config, { emojis }) + return merge({}, defaultConfig, rest, { emojis: mergedEmojis }) } function mergeEmojis(emojis: DefineConfig['emojis']): EmojiConfig { if (isArray(emojis)) - return emojis.reduce((acc, cur) => merge(acc, cur), {}) + return merge({}, ...emojis) return emojis || {} } diff --git a/src/eemoji.ts b/src/eemoji.ts index 1814f44..adc24c3 100644 --- a/src/eemoji.ts +++ b/src/eemoji.ts @@ -66,7 +66,7 @@ function getEmoji(type: string, text: string, config: Config, DEBUG?: number): s return config.emojis.breaking type = type.toLowerCase().replace(/\(.*\)/, '').trim() - const emojiKey = Object.keys(config.emojis).find(key => key.split('|').includes(type)) + const emojiKey = Object.keys(config.emojis).find(key => key.includes(type)) if (!emojiKey) return undefined @@ -81,7 +81,7 @@ function getEmoji(type: string, text: string, config: Config, DEBUG?: number): s text = text.toLowerCase() for (const [key, value] of entries) { - if (key.split('|').some(k => text.includes(k.toLowerCase()))) + if (text === key.toLowerCase()) return value } diff --git a/src/presets/default.json b/src/presets/default.json index 0933e6d..75b7798 100644 --- a/src/presets/default.json +++ b/src/presets/default.json @@ -39,7 +39,7 @@ "enhance": "๐Ÿ’Ž", "test": "๐Ÿงช", "refactor": "โ™ป๏ธ", - "init|initial": "๐ŸŽ‰", + "init": "๐ŸŽ‰", "perf": "โšก", "breaking": "๐Ÿ’ฅ", "ci": "๐Ÿฆพ", diff --git a/src/presets/default.jsonc b/src/presets/default.jsonc index f568050..077f92f 100644 --- a/src/presets/default.jsonc +++ b/src/presets/default.jsonc @@ -39,7 +39,7 @@ "enhance": "๐Ÿ’Ž", // made something a little better (omit from release notes) "test": "๐Ÿงช", // worked on tests "refactor": "โ™ป๏ธ", // refactored code, achieved the same with less - "init|initial": "๐ŸŽ‰", // started a new project! + "init": "๐ŸŽ‰", // started a new project! "perf": "โšก", // improved performance, achieved the same faster "breaking": "๐Ÿ’ฅ", // *special type:* will be used if the commit contains an exclamation mark (`!`), indicates breaking changes "ci": "๐Ÿฆพ", // changed workflow files, CI stuff