11#!/usr/bin/env bun
22
3- import { $ } from "bun"
3+ import { $ } from "bun" ;
44
55// Get bump type from environment
6- const bump = process . env . BUMP
7- if ( ! bump || ! [ 'patch' , 'minor' , 'major' ] . includes ( bump ) ) {
8- console . error ( "Invalid or missing BUMP environment variable. Must be patch, minor, or major." )
9- process . exit ( 1 )
6+ const bump = process . env . BUMP ;
7+ if ( ! bump || ! [ "patch" , "minor" , "major" ] . includes ( bump ) ) {
8+ console . error (
9+ "Invalid or missing BUMP environment variable. Must be patch, minor, or major." ,
10+ ) ;
11+ process . exit ( 1 ) ;
1012}
1113
1214// Get current version
13- const pkg = await Bun . file ( ' package.json' ) . json ( )
14- const currentVersion = pkg . version
15- console . log ( `Current version: ${ currentVersion } ` )
15+ const pkg = await Bun . file ( " package.json" ) . json ( ) ;
16+ const currentVersion = pkg . version ;
17+ console . log ( `Current version: ${ currentVersion } ` ) ;
1618
1719// Calculate new version
18- const [ major , minor , patch ] = currentVersion . split ( '.' ) . map ( Number )
20+ const [ major , minor , patch ] = currentVersion . split ( "." ) . map ( Number ) ;
1921const newVersion : string = ( ( ) => {
2022 switch ( bump ) {
21- case ' patch' :
22- return `${ major } .${ minor } .${ patch + 1 } `
23- case ' minor' :
24- return `${ major } .${ minor + 1 } .0`
25- case ' major' :
26- return `${ major + 1 } .0.0`
23+ case " patch" :
24+ return `${ major } .${ minor } .${ patch + 1 } ` ;
25+ case " minor" :
26+ return `${ major } .${ minor + 1 } .0` ;
27+ case " major" :
28+ return `${ major + 1 } .0.0` ;
2729 default :
28- throw new Error ( `Invalid bump type: ${ bump } ` )
30+ throw new Error ( `Invalid bump type: ${ bump } ` ) ;
2931 }
30- } ) ( )
32+ } ) ( ) ;
3133
32- console . log ( `New version: ${ newVersion } ` )
34+ console . log ( `New version: ${ newVersion } ` ) ;
3335
3436// Update package.json
35- pkg . version = newVersion
36- await Bun . file ( ' package.json' ) . write ( JSON . stringify ( pkg , null , 2 ) + '\n' )
37- console . log ( "Updated package.json" )
37+ pkg . version = newVersion ;
38+ await Bun . file ( " package.json" ) . write ( ` ${ JSON . stringify ( pkg , null , 2 ) } \n` ) ;
39+ console . log ( "Updated package.json" ) ;
3840
3941// Build the project
40- console . log ( "Building project..." )
41- await $ `bun run build`
42- console . log ( "Build completed" )
42+ console . log ( "Building project..." ) ;
43+ await $ `bun run build` ;
44+ console . log ( "Build completed" ) ;
4345
4446// Publish to npm
45- console . log ( "Publishing to npm..." )
46- await $ `npm publish --access public`
47- console . log ( "Published to npm" )
47+ console . log ( "Publishing to npm..." ) ;
48+ await $ `npm publish --access public` ;
49+ console . log ( "Published to npm" ) ;
4850
4951// Git operations
50- console . log ( "Committing changes..." )
51- await $ `git add package.json`
52- await $ `git commit -m "release: v${ newVersion } "`
53- await $ `git tag v${ newVersion } `
54- await $ `git push origin main --tags`
55- console . log ( "Git operations completed" )
52+ console . log ( "Committing changes..." ) ;
53+ await $ `git add package.json` ;
54+ await $ `git commit -m "release: v${ newVersion } "` ;
55+ await $ `git tag v${ newVersion } ` ;
56+ await $ `git push origin main --tags` ;
57+ console . log ( "Git operations completed" ) ;
5658
5759// Generate release notes
58- console . log ( "Generating release notes..." )
60+ console . log ( "Generating release notes..." ) ;
5961
6062// Get latest tag for comparison
61- let latestTag = ' HEAD~1'
63+ let latestTag = " HEAD~1" ;
6264try {
63- const result = await $ `git describe --tags --abbrev=0 HEAD~1` . text ( )
64- latestTag = result . trim ( )
65- } catch ( e ) {
65+ const result = await $ `git describe --tags --abbrev=0 HEAD~1` . text ( ) ;
66+ latestTag = result . trim ( ) ;
67+ } catch ( _e ) {
6668 // No previous tags, use first commit
67- latestTag = await $ `git rev-list --max-parents=0 HEAD` . text ( ) . then ( t => t . trim ( ) )
69+ latestTag = await $ `git rev-list --max-parents=0 HEAD`
70+ . text ( )
71+ . then ( ( t ) => t . trim ( ) ) ;
6872}
6973
70- console . log ( `Comparing ${ latestTag } ..HEAD` )
74+ console . log ( `Comparing ${ latestTag } ..HEAD` ) ;
7175
7276// Get commits since last tag
73- let commits : string [ ] = [ ]
77+ let commits : string [ ] = [ ] ;
7478try {
75- const result = await $ `git log --oneline --pretty=format:"%h %s" ${ latestTag } ..HEAD`
76- commits = result . text ( ) . split ( '\n' ) . filter ( line => line . trim ( ) )
77- } catch ( e ) {
79+ const result =
80+ await $ `git log --oneline --pretty=format:"%h %s" ${ latestTag } ..HEAD` ;
81+ commits = result
82+ . text ( )
83+ . split ( "\n" )
84+ . filter ( ( line ) => line . trim ( ) ) ;
85+ } catch ( _e ) {
7886 // No commits or error
7987}
8088
81- console . log ( `Found ${ commits . length } commits` )
89+ console . log ( `Found ${ commits . length } commits` ) ;
8290
8391// Get contributors (excluding author "Donald Silveira")
84- const contributors = new Set < string > ( )
92+ const contributors = new Set < string > ( ) ;
8593for ( const commit of commits ) {
8694 try {
87- const hash = commit . split ( ' ' ) [ 0 ]
88- const author = await $ `git show -s --format='%an' ${ hash } ` . text ( ) . trim ( )
89- if ( author !== ' Donald Silveira' ) {
90- contributors . add ( `@${ author . replace ( / \s + / g, '' ) . toLowerCase ( ) } ` )
95+ const hash = commit . split ( " " ) [ 0 ] ;
96+ const author = await $ `git show -s --format='%an' ${ hash } ` . text ( ) . trim ( ) ;
97+ if ( author !== " Donald Silveira" ) {
98+ contributors . add ( `@${ author . replace ( / \s + / g, "" ) . toLowerCase ( ) } ` ) ;
9199 }
92- } catch ( e ) {
100+ } catch ( _e ) {
93101 // Skip if can't get author
94102 }
95103}
96104
97105// Format release notes
98- let notes = `## Changes\n`
106+ let notes = `## Changes\n` ;
99107if ( commits . length === 0 ) {
100- notes += `- Initial release\n`
108+ notes += `- Initial release\n` ;
101109} else {
102- for ( const commit of commits . slice ( 0 , 10 ) ) { // Limit to 10 commits
103- const message = commit . split ( ' ' ) . slice ( 1 ) . join ( ' ' )
104- notes += `- ${ message } \n`
110+ for ( const commit of commits . slice ( 0 , 10 ) ) {
111+ // Limit to 10 commits
112+ const message = commit . split ( " " ) . slice ( 1 ) . join ( " " ) ;
113+ notes += `- ${ message } \n` ;
105114 }
106115 if ( commits . length > 10 ) {
107- notes += `- ... and ${ commits . length - 10 } more changes\n`
116+ notes += `- ... and ${ commits . length - 10 } more changes\n` ;
108117 }
109118}
110119
111120if ( contributors . size > 0 ) {
112- notes += `\n## Contributors\n${ Array . from ( contributors ) . join ( ', ' ) } \n`
121+ notes += `\n## Contributors\n${ Array . from ( contributors ) . join ( ", " ) } \n` ;
113122}
114123
115124// Create GitHub release
116- console . log ( "Creating GitHub release..." )
117- await $ `gh release create v${ newVersion } --title "v${ newVersion } " --notes ${ notes } --draft=false`
118- console . log ( "Release created" )
125+ console . log ( "Creating GitHub release..." ) ;
126+ await $ `gh release create v${ newVersion } --title "v${ newVersion } " --notes ${ notes } --draft=false` ;
127+ console . log ( "Release created" ) ;
119128
120129// Output for GitHub Actions
121- const output = `version=${ newVersion } \ntag=v${ newVersion } \n`
130+ const output = `version=${ newVersion } \ntag=v${ newVersion } \n` ;
122131if ( process . env . GITHUB_OUTPUT ) {
123- await Bun . write ( process . env . GITHUB_OUTPUT , output )
132+ await Bun . write ( process . env . GITHUB_OUTPUT , output ) ;
124133}
125134
126- console . log ( `Successfully released v${ newVersion } !` )
135+ console . log ( `Successfully released v${ newVersion } !` ) ;
0 commit comments