-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
handlebars-setup.cjs
50 lines (39 loc) · 1.54 KB
/
handlebars-setup.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @param {string} string
* @returns string | undefined
*/
function formatMessage(string) {
if (!string) {
console.error('No string provided');
return;
}
if (!string.includes(':')) {
return `<span class="text-gray-400 bg-gray-900 px-1">misc</span>: ${string}`;
}
const [commitType, rest] = string.split(':').map(part => part.trim());
if (commitType.startsWith('new') || commitType.startsWith('feat')) {
return `<span class="text-green-400 bg-green-900 px-1">${commitType}</span>: ${rest}`;
}
if (commitType.startsWith('refactor') || commitType.startsWith('deps')) {
return `<span class="text-purple-400 bg-purple-900 px-1">${commitType}</span>: ${rest}`;
}
if (commitType.startsWith('docs')) {
return `<span class="text-blue-400 bg-blue-900 px-1">${commitType}</span>: ${rest}`;
}
if (commitType.startsWith('update')) {
return `<span class="text-pink-400 bg-pink-900 px-1">${commitType}</span>: ${rest}`;
}
if (commitType.startsWith('chore')) {
return `<span class="text-blue-400 bg-blue-900 px-1">${commitType}</span>: ${rest}`;
}
if (commitType.startsWith('fix')) {
return `<span class="text-yellow-400 bg-yellow-900 px-1">${commitType}</span>: ${rest}`;
}
if (commitType.startsWith('ci')) {
return `<span class="text-gray-400 bg-gray-900 px-1">${[commitType]}</span>: ${rest}`;
}
return string;
}
module.exports = function (Handlebars) {
Handlebars.registerHelper('format', formatMessage);
};