11#!/usr/bin/env zx
22import 'zx/globals' ;
3- import { cliArguments , getCargo , workingDirectory } from './utils.mjs' ;
3+ import { getCargo , workingDirectory } from './utils.mjs' ;
44
5+ class Publisher {
6+ libType ;
7+
8+ constructor ( ) {
9+ const lib = process . argv [ 3 ] ;
10+ if ( ! lib ) {
11+ throw new Error ( 'A library type must be provided.' ) ;
12+ }
13+ if ( lib !== 'client' && lib !== 'program' ) {
14+ throw new Error ( 'Invalid library type. Allowed values are "client" or "program".' ) ;
15+ }
16+ this . libType = lib ;
17+ }
18+
19+ path ( ) {
20+ if ( this . libType === 'client' ) {
21+ return 'clients/rust' ;
22+ } else {
23+ return 'program' ;
24+ }
25+ }
26+
27+ message ( ) {
28+ if ( this . libType === 'client' ) {
29+ return 'Rust client' ;
30+ } else {
31+ return 'Program' ;
32+ }
33+ }
34+
35+ tagPrefix ( ) {
36+ if ( this . libType === 'client' ) {
37+ return 'rust' ;
38+ } else {
39+ return 'program' ;
40+ }
41+ }
42+ }
43+
44+ const publisher = new Publisher ( ) ;
545const dryRun = argv [ 'dry-run' ] ?? false ;
6- const [ level ] = cliArguments ( ) ;
46+ const [ level ] = process . argv . slice ( 4 ) ;
747if ( ! level ) {
848 throw new Error ( 'A version level — e.g. "path" — must be provided.' ) ;
949}
1050
11- // Go to the client directory and install the dependencies.
12- cd ( path . join ( workingDirectory , 'clients' , 'rust' ) ) ;
51+ // Go to the directory and install the dependencies.
52+ cd ( path . join ( workingDirectory , publisher . path ( ) ) ) ;
1353
1454// Publish the new version.
1555const releaseArgs = dryRun
@@ -23,7 +63,7 @@ if (dryRun) {
2363}
2464
2565// Get the new version.
26- const newVersion = getCargo ( path . join ( 'clients' , 'rust' ) ) . package . version ;
66+ const newVersion = getCargo ( publisher . path ( ) ) . package . version ;
2767
2868// Expose the new version to CI if needed.
2969if ( process . env . CI ) {
@@ -34,7 +74,7 @@ if (process.env.CI) {
3474await $ `git reset --soft HEAD~1` ;
3575
3676// Commit the new version.
37- await $ `git commit -am "Publish Rust client v${ newVersion } "` ;
77+ await $ `git commit -am "Publish ${ publisher . message ( ) } v${ newVersion } "` ;
3878
3979// Tag the new version.
40- await $ `git tag -a rust @v${ newVersion } -m "Rust client v${ newVersion } "` ;
80+ await $ `git tag -a ${ publisher . tagPrefix ( ) } @v${ newVersion } -m "${ publisher . message ( ) } v${ newVersion } "` ;
0 commit comments