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,29 +30,30 @@ 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
- const changelogFile = `./changelogs/CHANGELOG_${ branch } .md` ;
37
+ //const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
38
+ const changelogFile = `./CHANGELOG.md` ;
32
39
console . log ( `Changelog file output to: ${ changelogFile } ` ) ;
33
40
34
41
// Load template file contents
35
42
await loadTemplates ( ) ;
36
43
37
44
const config = {
38
45
branches : [
46
+ 'main' ,
47
+ 'master' ,
39
48
'release' ,
40
- // { name: 'alpha', prerelease: true },
41
- // { name: 'beta', prerelease: true },
42
- // 'next-major',
49
+ { name : 'alpha' , prerelease : true } ,
50
+ { name : 'beta' , prerelease : true } ,
51
+ 'next-major' ,
43
52
// Long-Term-Support branches
44
- // { name: '1.x.x', range: '1.x.x', channel: '1.x.x' },
45
- // { name: '2.x.x', range: '2.x.x', channel: '2.x.x' },
46
- // { name: '3.x.x', range: '3.x.x', channel: '3.x.x' },
47
- // { name: '4.x.x', range: '4.x.x', channel: '4.x.x' },
48
- // { name: '5.x.x', range: '5.x.x', channel: '5.x.x' },
49
- // { name: '6.x.x', range: '6.x.x', channel: '6.x.x' },
53
+ // { name: 'release-1', range: '1.x.x', channel: '1.x' },
54
+ // { name: 'release-2', range: '2.x.x', channel: '2.x' },
55
+ // { name: 'release-3', range: '3.x.x', channel: '3.x' },
56
+ // { name: 'release-4', range: '4.x.x', channel: '4.x' },
50
57
] ,
51
58
dryRun : false ,
52
59
debug : true ,
@@ -60,13 +67,13 @@ async function config() {
60
67
{ scope : 'no-release' , release : false } ,
61
68
] ,
62
69
parserOpts : {
63
- noteKeywords : [ 'BREAKING CHANGE' , 'BREAKING CHANGES' , 'BREAKING' ] ,
70
+ noteKeywords : [ 'BREAKING CHANGE' ] ,
64
71
} ,
65
72
} ] ,
66
73
[ '@semantic-release/release-notes-generator' , {
67
74
preset : 'angular' ,
68
75
parserOpts : {
69
- noteKeywords : [ 'BREAKING CHANGE' ]
76
+ noteKeywords : [ 'BREAKING CHANGE' ]
70
77
} ,
71
78
writerOpts : {
72
79
commitsSort : [ 'subject' , 'scope' ] ,
@@ -83,23 +90,13 @@ async function config() {
83
90
'npmPublish' : true ,
84
91
} ] ,
85
92
[ '@semantic-release/git' , {
86
- assets : [ changelogFile , 'package.json' , 'package-lock.json' , 'npm-shrinkwrap.json' ] ,
93
+ assets : [ changelogFile , 'package.json' , 'package-lock.json' ] ,
87
94
} ] ,
88
- [ " @semantic-release/github" , {
95
+ [ ' @semantic-release/github' , {
89
96
successComment : getReleaseComment ( ) ,
90
97
labels : [ 'type:ci' ] ,
91
98
releasedLabels : [ 'state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>' ]
92
99
} ] ,
93
- // Back-merge module runs last because if it fails it should not impede the release process
94
- // [
95
- // "@saithodev/semantic-release-backmerge",
96
- // {
97
- // "branches": [
98
- // { from: "beta", to: "alpha" },
99
- // { from: "release", to: "beta" },
100
- // ]
101
- // }
102
- // ],
103
100
] ,
104
101
} ;
105
102
@@ -108,19 +105,24 @@ async function config() {
108
105
109
106
async function loadTemplates ( ) {
110
107
for ( const template of Object . keys ( templates ) ) {
111
- 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' ) ;
112
114
templates [ template ] . text = text ;
113
115
}
114
116
}
115
117
116
- async function readFile ( filePath ) {
117
- return await fs . readFile ( filePath , 'utf-8' ) ;
118
- }
119
-
120
118
function getReleaseComment ( ) {
121
119
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
122
- const comment = '🎉 This pull request has been released in version [${nextRelease.version}](' + url + ')' ;
120
+ const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
123
121
return comment ;
124
122
}
125
123
126
- module . exports = config ( ) ;
124
+ // For CommonJS use:
125
+ // module.exports = config();
126
+
127
+ // For ES6 modules use:
128
+ export default config ( ) ;
0 commit comments