@@ -38,22 +38,38 @@ async function main() {
3838 ...args
3939 ] ;
4040 await exec ( cmd . join ( ' ' ) ) ;
41- await duplicateChangeFiles ( ) ;
41+ await duplicateChangeFile ( ) ;
4242}
4343
44- async function duplicateChangeFiles ( ) {
44+ async function duplicateChangeFile ( ) {
4545 const gitLogStdout = await exec_output ( `git log -1 --name-status` ) ;
46- const newChangeFiles = parseNewChangeFiles ( gitLogStdout ) ;
47- if ( newChangeFiles . length === 0 ) {
46+ const newChangeFilesFilenames = parseNewChangeFiles ( gitLogStdout ) ;
47+ if ( newChangeFilesFilenames . length === 0 ) {
48+ console . log ( 'No new change files detected. Nothing to duplicate.' ) ;
4849 return ;
50+ } else if ( newChangeFilesFilenames . length > 1 ) {
51+ throw new Error ( `Expected only one change file, but found ${ newChangeFilesFilenames . length } change files` ) ;
4952 }
5053
51- console . log ( `Duplicating ${ newChangeFiles . length } change files into ${ CHANGE_DIR_BETA } ` ) ;
52- for ( const file of newChangeFiles ) {
53- fs . copyFileSync ( path . join ( CHANGE_DIR , file ) , path . join ( CHANGE_DIR_BETA , file ) ) ;
54+ const changeFilename = newChangeFilesFilenames [ 0 ] ;
55+ const filepath = path . join ( CHANGE_DIR , changeFilename ) ;
56+ const changeFile = JSON . parse ( fs . readFileSync ( filepath , 'utf-8' ) ) ;
57+
58+ // if type is none, we don't need to duplicate the change file.
59+ if ( changeFile . type !== "none" ) {
60+ console . log ( `Duplicating ${ filepath } change files into ${ CHANGE_DIR_BETA } ` ) ;
61+ fs . copyFileSync ( filepath , path . join ( CHANGE_DIR_BETA , changeFilename ) ) ;
62+ await exec ( `git add ${ CHANGE_DIR_BETA } ` ) ;
63+ await exec ( `git commit -m 'Duplicate change files for beta release'` ) ;
64+ }
65+
66+ // if the type is prerelease, we can delete the stable changefile that was created.
67+ if ( changeFile . type === "prerelease" ) {
68+ console . log ( `Deleting stable change file ${ filepath } ` ) ;
69+ fs . unlinkSync ( filepath ) ;
70+ await exec ( `git add ${ CHANGE_DIR } ` ) ;
71+ await exec ( `git commit -m 'Remove unecessary stable change file'` ) ;
5472 }
55- await exec ( `git add ${ CHANGE_DIR_BETA } ` ) ;
56- await exec ( `git commit -m 'Duplicate change files for beta release'` ) ;
5773}
5874
5975await main ( ) ;
0 commit comments