22 * Semantic Release Config
33 */
44
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' ;
713
814// Get env vars
915const ref = process . env . GITHUB_REF ;
@@ -24,29 +30,30 @@ const templates = {
2430async function config ( ) {
2531
2632 // Get branch
27- const branch = ref . split ( '/' ) . pop ( ) ;
33+ const branch = ref ? .split ( '/' ) ? .pop ( ) ?. split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
2834 console . log ( `Running on branch: ${ branch } ` ) ;
2935
3036 // Set changelog file
31- const changelogFile = `./changelogs/CHANGELOG_${ branch } .md` ;
37+ //const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
38+ const changelogFile = `./CHANGELOG.md` ;
3239 console . log ( `Changelog file output to: ${ changelogFile } ` ) ;
3340
3441 // Load template file contents
3542 await loadTemplates ( ) ;
3643
3744 const config = {
3845 branches : [
46+ 'main' ,
47+ 'master' ,
3948 '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' ,
4352 // 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' },
5057 ] ,
5158 dryRun : false ,
5259 debug : true ,
@@ -60,13 +67,13 @@ async function config() {
6067 { scope : 'no-release' , release : false } ,
6168 ] ,
6269 parserOpts : {
63- noteKeywords : [ 'BREAKING CHANGE' , 'BREAKING CHANGES' , 'BREAKING' ] ,
70+ noteKeywords : [ 'BREAKING CHANGE' ] ,
6471 } ,
6572 } ] ,
6673 [ '@semantic-release/release-notes-generator' , {
6774 preset : 'angular' ,
6875 parserOpts : {
69- noteKeywords : [ 'BREAKING CHANGE' ]
76+ noteKeywords : [ 'BREAKING CHANGE' ]
7077 } ,
7178 writerOpts : {
7279 commitsSort : [ 'subject' , 'scope' ] ,
@@ -83,23 +90,13 @@ async function config() {
8390 'npmPublish' : true ,
8491 } ] ,
8592 [ '@semantic-release/git' , {
86- assets : [ changelogFile , 'package.json' , 'package-lock.json' , 'npm-shrinkwrap.json' ] ,
93+ assets : [ changelogFile , 'package.json' , 'package-lock.json' ] ,
8794 } ] ,
88- [ " @semantic-release/github" , {
95+ [ ' @semantic-release/github' , {
8996 successComment : getReleaseComment ( ) ,
9097 labels : [ 'type:ci' ] ,
9198 releasedLabels : [ 'state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>' ]
9299 } ] ,
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- // ],
103100 ] ,
104101 } ;
105102
@@ -108,19 +105,24 @@ async function config() {
108105
109106async function loadTemplates ( ) {
110107 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' ) ;
112114 templates [ template ] . text = text ;
113115 }
114116}
115117
116- async function readFile ( filePath ) {
117- return await fs . readFile ( filePath , 'utf-8' ) ;
118- }
119-
120118function getReleaseComment ( ) {
121119 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 + ')' ;
123121 return comment ;
124122}
125123
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