@@ -12,7 +12,7 @@ import log from 'git-log-parser'
1212import streamToArray from 'stream-to-array'
1313import axios from 'axios'
1414import { DateTime } from 'luxon'
15- import { branchConfigs , latestBranch , packages , rootDir } from './config.js'
15+ import { branchConfigs , packages , rootDir } from './config.js'
1616
1717/** @param {string } version */
1818const releaseCommitMsg = ( version ) => `release: v${ version } `
@@ -22,17 +22,8 @@ async function run() {
2222 process . env . BRANCH ?? currentGitBranch ( )
2323 )
2424
25- /** @type {import('./types.js').BranchConfig | undefined } */
26- const branchConfig = branchConfigs [ branchName ]
27-
28- if ( ! branchConfig ) {
29- console . log ( `No publish config found for branch: ${ branchName } ` )
30- console . log ( 'Exiting...' )
31- process . exit ( 0 )
32- }
33-
34- const isLatestBranch = branchName === latestBranch
35- const npmTag = isLatestBranch ? 'latest' : branchName
25+ const isMainBranch = branchName === 'main'
26+ const npmTag = isMainBranch ? 'latest' : branchName
3627
3728 // Get tags
3829 /** @type {string[] } */
@@ -42,11 +33,11 @@ async function run() {
4233 tags = tags
4334 . filter ( ( tag ) => semver . valid ( tag ) )
4435 . filter ( ( tag ) => {
45- if ( isLatestBranch ) {
46- return semver . prerelease ( tag ) == null
36+ if ( semver . prerelease ( tag ) === null ) {
37+ return isMainBranch
38+ } else {
39+ return ! isMainBranch
4740 }
48-
49- return tag . includes ( `-${ branchName } ` )
5041 } )
5142 // sort by latest
5243 . sort ( semver . compare )
@@ -95,6 +86,7 @@ async function run() {
9586 */
9687 const commitsSinceLatestTag = (
9788 await new Promise ( ( resolve , reject ) => {
89+ /** @type {NodeJS.ReadableStream } */
9890 const strm = log . parse ( {
9991 _ : range ,
10092 } )
@@ -126,6 +118,10 @@ async function run() {
126118
127119 /**
128120 * Parses the commit messsages, log them, and determine the type of release needed
121+ * -1 means no release is necessary
122+ * 0 means patch release is necessary
123+ * 1 means minor release is necessary
124+ * 2 means major release is necessary
129125 * @type {number }
130126 */
131127 let recommendedReleaseLevel = commitsSinceLatestTag . reduce (
@@ -304,6 +300,15 @@ async function run() {
304300 recommendedReleaseLevel = 0
305301 }
306302
303+ /** @type {import('./types.js').BranchConfig | undefined } */
304+ const branchConfig = branchConfigs [ branchName ]
305+
306+ if ( ! branchConfig ) {
307+ console . log ( `No publish config found for branch: ${ branchName } ` )
308+ console . log ( 'Exiting...' )
309+ process . exit ( 0 )
310+ }
311+
307312 const releaseType = branchConfig . prerelease
308313 ? 'prerelease'
309314 : /** @type {const } */ ( { 0 : 'patch' , 1 : 'minor' , 2 : 'major' } ) [
@@ -368,17 +373,6 @@ async function run() {
368373 return
369374 }
370375
371- // Tag and commit
372- console . info ( `Creating new git tag v${ version } ` )
373- execSync ( `git tag -a -m "v${ version } " v${ version } ` )
374-
375- const taggedVersion = getTaggedVersion ( )
376- if ( ! taggedVersion ) {
377- throw new Error (
378- 'Missing the tagged release version. Something weird is afoot!' ,
379- )
380- }
381-
382376 console . info ( )
383377 console . info ( `Publishing all packages to npm with tag "${ npmTag } "` )
384378
@@ -396,36 +390,33 @@ async function run() {
396390
397391 console . info ( )
398392
399- console . info ( `Pushing new tags to branch.` )
400- execSync ( `git push --tags` )
401- console . info ( ` Pushed tags to branch.` )
402-
403- if ( branchConfig . ghRelease ) {
404- console . info ( `Creating github release...` )
405- // Stringify the markdown to excape any quotes
406- execSync (
407- `gh release create v${ version } ${
408- ! isLatestBranch ? '--prerelease' : ''
409- } --notes '${ changelogMd . replace ( / ' / g, '"' ) } '`,
410- )
411- console . info ( ` Github release created.` )
412-
413- console . info ( `Committing changes...` )
414- execSync ( `git add -A && git commit -m "${ releaseCommitMsg ( version ) } "` )
415- console . info ( )
416- console . info ( ` Committed Changes.` )
417- console . info ( `Pushing changes...` )
418- execSync ( `git push` )
419- console . info ( )
420- console . info ( ` Changes pushed.` )
421- } else {
422- console . info ( `Skipping github release and change commit.` )
423- }
393+ console . info ( `Committing changes...` )
394+ execSync ( `git add -A && git commit -m "${ releaseCommitMsg ( version ) } "` )
395+ console . info ( )
396+ console . info ( ` Committed Changes.` )
397+
398+ console . info ( `Pushing changes...` )
399+ execSync ( `git push` )
400+ console . info ( )
401+ console . info ( ` Changes pushed.` )
402+
403+ console . info ( `Creating new git tag v${ version } ` )
404+ execSync ( `git tag -a -m "v${ version } " v${ version } ` )
424405
425406 console . info ( `Pushing tags...` )
426407 execSync ( `git push --tags` )
427408 console . info ( )
428409 console . info ( ` Tags pushed.` )
410+
411+ console . info ( `Creating github release...` )
412+ // Stringify the markdown to excape any quotes
413+ execSync (
414+ `gh release create v${ version } ${
415+ ! isMainBranch ? '--prerelease' : ''
416+ } --notes '${ changelogMd . replace ( / ' / g, '"' ) } '`,
417+ )
418+ console . info ( ` Github release created.` )
419+
429420 console . info ( `All done!` )
430421}
431422
@@ -459,11 +450,6 @@ async function updatePackageJson(pathName, transform) {
459450 } )
460451}
461452
462- function getTaggedVersion ( ) {
463- const output = execSync ( 'git tag --list --points-at HEAD' ) . toString ( )
464- return output . replace ( / ^ v | \n + $ / g, '' )
465- }
466-
467453/**
468454 * @template TItem
469455 * @param {((d: TItem) => any)[] } sorters
0 commit comments