-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-release-template.js
42 lines (35 loc) · 1.22 KB
/
gen-release-template.js
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
const fs = require('fs');
const gitmojisObj = JSON.parse(fs.readFileSync('./build/dist/gitmojis.json', 'utf8'));
const header = `# {{releaseTypeEmoji nextRelease.type}}v{{nextRelease.version}} ({{datetime "UTC:yyyy-mm-dd"}})
**{{releaseTypeText nextRelease.type}}** ({{nextRelease.type}} version up) - [\`v{{lastRelease.version}}\`...\`v{{nextRelease.version}}\`]({{compareUrl}})
`
function run() {
let res = header
let semverObj = {
major: [],
minor: [],
patch: [],
ignore: [],
none: [],
}
for (const gitmojiObj of gitmojisObj.gitmojis) {
semverObj[gitmojiObj.semver].push(gitmojiObj)
}
for (const key of Object.keys(semverObj)) {
if (key === 'ignore') {
continue
}
res += `\n{{${key}Header commits}}\n`
res += `{{#with commits}}`
for (const gitmojiObj of semverObj[key]) {
res += buildTemplate(gitmojiObj)
}
res += "{{/with}}\n"
}
fs.writeFileSync('./build/dist/release-template.hbs', res);
}
function buildTemplate(gitmojiObj) {
return `{{#if ${gitmojiObj.name.replace(/-/g, '_')}}} {{#each ${gitmojiObj.name.replace(/-/g, '_')}}}- {{> commitTemplate}}
{{/each}}{{/if}}`
}
run()