2
2
* Semantic Release Config
3
3
*/
4
4
5
- const fs = require ( 'fs' ) . promises ;
6
- const path = require ( 'path' ) ;
5
+ const { readFile } = require ( 'fs' ) . promises ;
6
+ const { resolve } = require ( 'path' ) ;
7
+
8
+ // For ES6 modules use:
9
+ // import { readFile } from 'fs/promises';
10
+ // import { resolve, dirname } from 'path';
11
+ // import { fileURLToPath } from 'url';
7
12
8
13
// Get env vars
9
14
const ref = process . env . GITHUB_REF ;
@@ -24,7 +29,7 @@ const templates = {
24
29
async function config ( ) {
25
30
26
31
// Get branch
27
- const branch = ref . split ( '/' ) . pop ( ) . split ( '-' ) [ 0 ] ;
32
+ const branch = ref ? .split ( '/' ) ? .pop ( ) ? .split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
28
33
console . log ( `Running on branch: ${ branch } ` ) ;
29
34
30
35
// Set changelog file
@@ -89,7 +94,7 @@ async function config() {
89
94
[
90
95
"@saithodev/semantic-release-backmerge" ,
91
96
{
92
- "branches " : [
97
+ "backmergeBranches " : [
93
98
{ from : "beta" , to : "alpha" } ,
94
99
{ from : "release" , to : "beta" } ,
95
100
]
@@ -103,15 +108,17 @@ async function config() {
103
108
104
109
async function loadTemplates ( ) {
105
110
for ( const template of Object . keys ( templates ) ) {
106
- const text = await readFile ( path . resolve ( __dirname , resourcePath , templates [ template ] . file ) ) ;
111
+
112
+ // For ES6 modules use:
113
+ // const fileUrl = import.meta.url;
114
+ // const __dirname = dirname(fileURLToPath(fileUrl));
115
+
116
+ const filePath = resolve ( __dirname , resourcePath , templates [ template ] . file ) ;
117
+ const text = await readFile ( filePath , 'utf-8' ) ;
107
118
templates [ template ] . text = text ;
108
119
}
109
120
}
110
121
111
- async function readFile ( filePath ) {
112
- return await fs . readFile ( filePath , 'utf-8' ) ;
113
- }
114
-
115
122
function getReleaseComment ( ) {
116
123
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
117
124
const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments