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> = T extends `${infer First}|${infer _}` ? First : T - type StringOrOptionalProp<T> = { [K in keyof T as K extends 'breaking' ? never : - PipePropName<K>]: T[K] | Record<string, string> + K]: T[K] | Record<string, string> } type EmojiType = StringOrOptionalProp<typeof emojis> & { breaking: string } + export type EmojiConfig = Record<string, string | Record<string, string>> 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