@@ -14,15 +14,23 @@ const TARGETS = {
1414 tauriConf : 'packages/helper/src-tauri/tauri.conf.json' ,
1515 pkgJson : 'packages/helper/package.json' ,
1616 } ,
17+ sbot : {
18+ tagPrefix : 'sbot-v' ,
19+ pkgJson : 'packages/sbot/package.json' ,
20+ releaseNotes : {
21+ en : 'packages/sbot/ReleaseNote.md' ,
22+ zh : 'packages/sbot/ReleaseNote.zh.md' ,
23+ } ,
24+ } ,
1725} ;
1826
1927const SEMVER_RE = / ^ \d + \. \d + \. \d + $ / ;
2028const BUMP_TYPES = [ 'patch' , 'minor' , 'major' ] ;
2129
2230function usage ( msg ) {
2331 if ( msg ) console . error ( `error: ${ msg } \n` ) ;
24- console . error ( ' Usage: node scripts/release.js <app|helper > [<version>|patch|minor|major]' ) ;
25- console . error ( ' no arg : use current version in tauri.conf.json, just tag & push' ) ;
32+ console . error ( ` Usage: node scripts/release.js <${ Object . keys ( TARGETS ) . join ( '|' ) } > [<version>|patch|minor|major]` ) ;
33+ console . error ( ' no arg : use current version, sync release notes (sbot), tag & push' ) ;
2634 console . error ( ' patch|minor|major: bump version, commit, tag & push' ) ;
2735 console . error ( ' X.Y.Z : set version, commit, tag & push' ) ;
2836 process . exit ( 1 ) ;
@@ -70,42 +78,63 @@ function main() {
7078
7179 const cfg = TARGETS [ target ] ;
7280 const root = path . resolve ( __dirname , '..' ) ;
73- const confPath = path . join ( root , cfg . tauriConf ) ;
81+ const confPath = cfg . tauriConf ? path . join ( root , cfg . tauriConf ) : null ;
7482 const pkgPath = path . join ( root , cfg . pkgJson ) ;
7583
76- const conf = readJson ( confPath ) ;
84+ const conf = confPath ? readJson ( confPath ) : null ;
7785 const pkg = fs . existsSync ( pkgPath ) ? readJson ( pkgPath ) : null ;
7886
7987 // tauri.conf.json's version may be the literal "../package.json" — treat package.json as source of truth
80- const confUsesPkgJson = conf . version === '../package.json' ;
81- const currentVersion = ( pkg && pkg . version ) || ( confUsesPkgJson ? null : conf . version ) ;
88+ const confUsesPkgJson = conf ? conf . version === '../package.json' : true ;
89+ const currentVersion = ( pkg && pkg . version ) || ( conf && ! confUsesPkgJson ? conf . version : null ) ;
8290
8391 if ( ! currentVersion || ! SEMVER_RE . test ( currentVersion ) ) {
84- console . error ( `error: cannot resolve current version from ${ cfg . pkgJson } or ${ cfg . tauriConf } ` ) ;
92+ const sources = [ cfg . pkgJson , cfg . tauriConf ] . filter ( Boolean ) . join ( ' or ' ) ;
93+ console . error ( `error: cannot resolve current version from ${ sources } ` ) ;
8594 process . exit ( 1 ) ;
8695 }
8796
8897 let nextVersion = currentVersion ;
89- let mutate = false ;
98+ let versionChanged = false ;
9099
91100 if ( arg ) {
92101 if ( BUMP_TYPES . includes ( arg ) ) {
93102 nextVersion = bumpVersion ( currentVersion , arg ) ;
94- mutate = true ;
103+ versionChanged = true ;
95104 } else if ( SEMVER_RE . test ( arg ) ) {
96105 nextVersion = arg ;
97- mutate = nextVersion !== currentVersion ;
106+ versionChanged = nextVersion !== currentVersion ;
98107 } else {
99108 usage ( `invalid version/bump "${ arg } "` ) ;
100109 }
101110 }
102111
112+ // resolve release notes from .md files — sync into pkg even when version is unchanged,
113+ // since the source of truth is the .md files and the workflow reads the pkg.json fields
114+ const releaseNotes = { } ;
115+ if ( cfg . releaseNotes ) {
116+ for ( const [ lang , rel ] of Object . entries ( cfg . releaseNotes ) ) {
117+ const p = path . join ( root , rel ) ;
118+ if ( fs . existsSync ( p ) ) {
119+ releaseNotes [ lang ] = fs . readFileSync ( p , 'utf8' ) . trim ( ) ;
120+ } else {
121+ console . warn ( `warning: ${ rel } not found, skipping releasenote.${ lang } ` ) ;
122+ }
123+ }
124+ }
125+ const notesChanged = pkg && (
126+ ( releaseNotes . en !== undefined && pkg . releasenoteEn !== releaseNotes . en ) ||
127+ ( releaseNotes . zh !== undefined && pkg . releasenoteZh !== releaseNotes . zh )
128+ ) ;
129+
130+ const mutate = versionChanged || notesChanged ;
103131 const tag = `${ cfg . tagPrefix } ${ nextVersion } ` ;
104132
105133 console . log ( `target : ${ target } ` ) ;
106134 console . log ( `current : ${ currentVersion } ` ) ;
107135 console . log ( `next : ${ nextVersion } ` ) ;
108136 console . log ( `tag : ${ tag } ` ) ;
137+ if ( notesChanged ) console . log ( 'notes : updated from ReleaseNote files' ) ;
109138 console . log ( '' ) ;
110139
111140 if ( tagExists ( tag ) ) {
@@ -115,35 +144,42 @@ function main() {
115144
116145 if ( mutate ) {
117146 if ( ! isWorkingTreeClean ( ) ) {
118- console . error ( 'error: working tree not clean — commit or stash before bumping version ' ) ;
147+ console . error ( 'error: working tree not clean — commit or stash before releasing ' ) ;
119148 process . exit ( 1 ) ;
120149 }
121150
122151 const filesToAdd = [ ] ;
123152
124153 if ( pkg && pkg . version !== undefined ) {
125154 pkg . version = nextVersion ;
155+ if ( releaseNotes . en !== undefined ) pkg . releasenoteEn = releaseNotes . en ;
156+ if ( releaseNotes . zh !== undefined ) pkg . releasenoteZh = releaseNotes . zh ;
126157 writeJson ( pkgPath , pkg ) ;
127158 filesToAdd . push ( cfg . pkgJson ) ;
128159 }
129160
130161 // only write tauri.conf.json if it carries a literal version (not "../package.json")
131- if ( ! confUsesPkgJson ) {
162+ if ( conf && ! confUsesPkgJson && versionChanged ) {
132163 conf . version = nextVersion ;
133164 writeJson ( confPath , conf ) ;
134165 filesToAdd . push ( cfg . tauriConf ) ;
135166 }
136167
168+ const commitMsg = versionChanged
169+ ? `chore(${ target } ): release v${ nextVersion } `
170+ : `chore(${ target } ): sync release notes for v${ nextVersion } ` ;
171+
137172 run ( `git add ${ filesToAdd . map ( ( f ) => `"${ f } "` ) . join ( ' ' ) } ` ) ;
138- run ( `git commit -m "chore( ${ target } ): release v ${ nextVersion } "` ) ;
173+ run ( `git commit -m "${ commitMsg } "` ) ;
139174 }
140175
141176 run ( `git tag -a "${ tag } " -m "${ target } v${ nextVersion } "` ) ;
142177 run ( 'git push' ) ;
143178 run ( `git push origin "${ tag } "` ) ;
144179
180+ const workflowName = { app : 'Release App' , helper : 'Release Helper' , sbot : 'Release sbot' } [ target ] || `Release ${ target } ` ;
145181 console . log ( '' ) ;
146- console . log ( `✓ pushed tag ${ tag } — workflow "Release ${ target === 'app' ? 'App' : 'Helper' } " triggered` ) ;
182+ console . log ( `✓ pushed tag ${ tag } — workflow "${ workflowName } " triggered` ) ;
147183}
148184
149185main ( ) ;
0 commit comments