1+ // in ".releaserc.js" or "release.config.js"
2+
3+ const fs = require ( 'fs' ) ;
4+ const path = require ( 'path' )
5+ const { promisify} = require ( 'util' )
6+ const dateFormat = require ( 'dateformat' )
7+ const readFileAsync = promisify ( require ( 'fs' ) . readFile )
8+
9+ const templateDir = "./"
10+ const template = readFileAsync ( path . join ( templateDir , 'release-template.hbs' ) )
11+ const commitTemplate = readFileAsync ( path . join ( templateDir , 'commit-template.hbs' ) )
12+ const semverObj = JSON . parse ( fs . readFileSync ( './semver.json' , 'utf8' ) ) ;
13+
14+ const releaseRules = {
15+ major : convert ( semverObj . semver . major ) ,
16+ minor : convert ( semverObj . semver . minor ) ,
17+ patch : convert ( semverObj . semver . patch )
18+ }
19+
20+ function convert ( arr ) {
21+ const res = [ ]
22+ for ( const v of arr ) {
23+ res . push ( `:${ v } :` )
24+ }
25+ return res
26+ }
27+
28+ const releaseNotes = {
29+ template,
30+ partials : { commitTemplate} ,
31+ helpers : {
32+ datetime : function ( format = 'UTC:yyyy-mm-dd' ) {
33+ return dateFormat ( new Date ( ) , format )
34+ } ,
35+ shortDate : function ( date ) {
36+ // See: https://www.npmjs.com/package/dateformat/v/3.0.0
37+ return dateFormat ( date , 'mmm dd' )
38+ } ,
39+ releaseTypeText : function ( type ) {
40+ if ( type === 'major' ) {
41+ return "Breaking Release!"
42+ }
43+ if ( type === 'minor' ) {
44+ return "Feature Release!"
45+ }
46+ if ( type === 'patch' ) {
47+ return "Patch Release"
48+ }
49+ } ,
50+ releaseTypeEmoji : function ( type ) {
51+ if ( type === 'major' ) {
52+ return ":confetti_ball: "
53+ }
54+ if ( type === 'minor' ) {
55+ return ":star2: "
56+ }
57+ if ( type === 'patch' ) {
58+ return ""
59+ }
60+ } ,
61+ } ,
62+ issueResolution : {
63+ template : '{baseUrl}/{owner}/{repo}/issues/{ref}' ,
64+ baseUrl : 'https://github.com' ,
65+ source : 'github.com'
66+ }
67+ }
68+
69+ module . exports = {
70+ branches : semverObj . branches ,
71+ plugins : [
72+ [ 'semantic-release-gitmoji' , { releaseRules, releaseNotes} ] ,
73+ '@semantic-release/github'
74+ ]
75+ }
0 commit comments