Skip to content

Commit 3795c6a

Browse files
committed
feat(changelog): emojis
1 parent 6c7f253 commit 3795c6a

5 files changed

Lines changed: 43 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"dev": "yarn build && node .",
3434
"dev:force": "rimraf ./.git && rimraf ./generi.json && yarn dev",
3535
"build": "tsup src/index.ts --minify --clean",
36+
"build:watch": "tsup src/index.ts --minify --clean --watch",
3637
"test": "vitest run --coverage",
3738
"format": "prettier --write src/ tests/"
3839
},

src/changelog.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import { success } from './console';
22
import { commits, isTagCommit, setCommit, getTagCommit } from './git';
3-
import { Commit } from './types';
3+
import { Commit, GeneriEmoticon } from './types';
44
import { setChangelog } from './utils';
55
import { getGeneriConfig } from './generi';
66
import conventional from './defines/conventional-commits.json';
77

8+
const getEmoji = (str: string): string => {
9+
const emojis: GeneriEmoticon[] = [
10+
['feat', '🎉 '],
11+
['fix', '🔧 '],
12+
['build', '📐 '],
13+
['chore', '🚧 '],
14+
['ci', '🗿 '],
15+
['style', '🎨 '],
16+
['refactor', '🚩 '],
17+
['perf', '📈 '],
18+
['docs', '📝 '],
19+
['test', '🔧 '],
20+
];
21+
22+
const target = emojis.find(([key]) => str.includes(key));
23+
24+
return target ? target[1] : ' ';
25+
};
26+
827
const getChangelogHeader = () => {
928
return `# Changelog (${new Date().toLocaleDateString()})\n\nChangelog was created by [Generi](https://github.com/Novout/generi). Any questions, consult the documentation.\n`;
1029
};
@@ -39,7 +58,13 @@ const setBasic = (commit: Commit) => {
3958
if (!result[0] || !result[1]) return '';
4059

4160
return (
42-
'* **' + result[0].trim() + ':** ' + result[1].trim() + ` [${commit.sha}]` + '\n'
61+
'* **' +
62+
getEmoji(result[0]) +
63+
result[0].trim() +
64+
':** ' +
65+
result[1].trim() +
66+
` [${commit.sha}]` +
67+
'\n'
4368
);
4469
}
4570

src/commands/log.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import {
1010
pushCommits,
1111
} from '../git';
1212
import { success, error, getHeader } from '../console';
13-
import { isChangesForCommit, existsConfig, getFile, getLernaRoot } from '../utils';
13+
import { existsConfig, getFile, getLernaRoot } from '../utils';
1414
import { getGeneriConfig } from '../generi';
15-
import { isGit } from '../git';
1615
import { publish } from '../npm';
1716

1817
const validateLog = (tag: GitNewTag) => {

src/git.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { success, error, info } from './console';
22
import { Commit, GitNewTagOptions, GitNewTag } from './types';
3-
import {
4-
getRoot,
5-
setFile,
6-
getFile,
7-
getPackageRoot,
8-
getLernaRoot,
9-
getConfigRoot,
10-
} from './utils';
3+
import { getRoot, setFile, getFile, getPackageRoot, getLernaRoot } from './utils';
114
import fs from 'fs';
125
import path from 'path';
136
import execa from 'execa';

src/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ export interface GeneriOptions {
4343
/* publish in npm */
4444
publish: boolean;
4545
}
46+
47+
export type GeneriConventionalCommits =
48+
| 'feat'
49+
| 'fix'
50+
| 'build'
51+
| 'chore'
52+
| 'ci'
53+
| 'docs'
54+
| 'style'
55+
| 'refactor'
56+
| 'perf'
57+
| 'test';
58+
export type GeneriEmoticon = [GeneriConventionalCommits, string];

0 commit comments

Comments
 (0)