2
2
* Semantic Release Config
3
3
*/
4
4
5
- const fs = require ( 'fs' ) . promises ;
6
- const path = require ( 'path' ) ;
5
+ // For CommonJS use:
6
+ const { readFile } = require ( 'fs' ) . promises ;
7
+ const { resolve } = require ( 'path' ) ;
8
+
9
+ // For ES6 modules use:
10
+ // import { readFile } from 'fs/promises';
11
+ // import { resolve, dirname } from 'path';
12
+ // import { fileURLToPath } from 'url';
7
13
8
14
// Get env vars
9
15
const ref = process . env . GITHUB_REF ;
@@ -24,9 +30,9 @@ const templates = {
24
30
async function config ( ) {
25
31
26
32
// Get branch
27
- const branch = ref . split ( '/' ) . pop ( ) ;
33
+ const branch = ref ? .split ( '/' ) ? .pop ( ) ?. split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
28
34
console . log ( `Running on branch: ${ branch } ` ) ;
29
-
35
+
30
36
// Set changelog file
31
37
//const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
32
38
const changelogFile = `./CHANGELOG.md` ;
@@ -38,9 +44,11 @@ async function config() {
38
44
const config = {
39
45
branches : [
40
46
'main' ,
41
- // { name: 'alpha', prerelease: true },
42
- // { name: 'beta', prerelease: true },
43
- // 'next-major',
47
+ 'master' ,
48
+ 'release' ,
49
+ { name : 'alpha' , prerelease : true } ,
50
+ { name : 'beta' , prerelease : true } ,
51
+ 'next-major' ,
44
52
// Long-Term-Support branches
45
53
// { name: 'release-1', range: '1.x.x', channel: '1.x' },
46
54
// { name: 'release-2', range: '2.x.x', channel: '2.x' },
@@ -59,13 +67,13 @@ async function config() {
59
67
{ scope : 'no-release' , release : false } ,
60
68
] ,
61
69
parserOpts : {
62
- noteKeywords : [ 'BREAKING CHANGE' , 'BREAKING CHANGES' , 'BREAKING' ] ,
70
+ noteKeywords : [ 'BREAKING CHANGE' ] ,
63
71
} ,
64
72
} ] ,
65
73
[ '@semantic-release/release-notes-generator' , {
66
74
preset : 'angular' ,
67
75
parserOpts : {
68
- noteKeywords : [ 'BREAKING CHANGE' , 'BREAKING CHANGES' , 'BREAKING' ]
76
+ noteKeywords : [ 'BREAKING CHANGE' ]
69
77
} ,
70
78
writerOpts : {
71
79
commitsSort : [ 'subject' , 'scope' ] ,
@@ -87,7 +95,7 @@ async function config() {
87
95
[ '@semantic-release/github' , {
88
96
successComment : getReleaseComment ( ) ,
89
97
labels : [ 'type:ci' ] ,
90
- releasedLabels : [ 'state:released<%= nextRelease.channel ? `-${nextRelease.channel}` : "" %>' ]
98
+ releasedLabels : [ 'state:released<%= nextRelease.channel ? `-\ ${nextRelease.channel}` : "" %>' ]
91
99
} ] ,
92
100
] ,
93
101
} ;
@@ -97,19 +105,24 @@ async function config() {
97
105
98
106
async function loadTemplates ( ) {
99
107
for ( const template of Object . keys ( templates ) ) {
100
- const text = await readFile ( path . resolve ( __dirname , resourcePath , templates [ template ] . file ) ) ;
108
+ // For ES6 modules use:
109
+ // const fileUrl = import.meta.url;
110
+ // const __dirname = dirname(fileURLToPath(fileUrl));
111
+
112
+ const filePath = resolve ( __dirname , resourcePath , templates [ template ] . file ) ;
113
+ const text = await readFile ( filePath , 'utf-8' ) ;
101
114
templates [ template ] . text = text ;
102
115
}
103
116
}
104
117
105
- async function readFile ( filePath ) {
106
- return await fs . readFile ( filePath , 'utf-8' ) ;
107
- }
108
-
109
118
function getReleaseComment ( ) {
110
119
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
111
120
let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
112
121
return comment ;
113
122
}
114
123
124
+ // For CommonJS use:
115
125
module . exports = config ( ) ;
126
+
127
+ // For ES6 modules use:
128
+ // export default config();
0 commit comments