@@ -10,6 +10,8 @@ const {
1010 runok,
1111} = require ( 'runok' )
1212const contributors = require ( 'contributor-faces' )
13+ const { execSync } = require ( 'node:child_process' )
14+ const semver = require ( 'semver' )
1315
1416const helperMarkDownFile = function ( name ) {
1517 return `docs/helpers/${ name } .md`
@@ -478,6 +480,47 @@ ${changelog}`
478480 )
479481 fs . writeFileSync ( './README.md' , readmeContent )
480482 } ,
483+
484+ getCurrentBetaVersion ( ) {
485+ try {
486+ const output = execSync ( 'npm view codeceptjs versions --json' ) . toString ( )
487+ const versions = JSON . parse ( output )
488+ const betaVersions = versions . filter ( ( version ) => version . includes ( 'beta' ) )
489+ const latestBeta = betaVersions . length ? betaVersions [ betaVersions . length - 1 ] : null
490+ console . log ( `Current beta version: ${ latestBeta } ` )
491+ return latestBeta
492+ } catch ( error ) {
493+ console . error ( 'Error fetching package versions:' , error )
494+ process . exit ( 1 )
495+ }
496+ } ,
497+
498+ publishNextBetaVersion ( ) {
499+ const currentBetaVersion = this . getCurrentBetaVersion ( )
500+ if ( ! currentBetaVersion ) {
501+ console . error ( 'No beta version found.' )
502+ process . exit ( 1 )
503+ }
504+
505+ const nextBetaVersion = semver . inc ( currentBetaVersion , 'prerelease' , 'beta' )
506+ console . log ( `Publishing version: ${ nextBetaVersion } ` )
507+
508+ try {
509+ // Save original version
510+ const packageJson = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) )
511+ const originalVersion = packageJson . version
512+ execSync ( `npm version ${ nextBetaVersion } --no-git-tag-version` )
513+ execSync ( 'npm publish --tag beta' )
514+ console . log ( `Successfully published ${ nextBetaVersion } ` )
515+
516+ // Revert to original version
517+ execSync ( `npm version ${ originalVersion } --no-git-tag-version` )
518+ console . log ( `Reverted back to original version: ${ originalVersion } ` )
519+ } catch ( error ) {
520+ console . error ( 'Error publishing package:' , error )
521+ process . exit ( 1 )
522+ }
523+ } ,
481524}
482525
483526async function processChangelog ( ) {
0 commit comments