@@ -108,27 +108,64 @@ const updatedCargoTomlContent = cargoTomlContent.replace(
108108 `version = "${ newVersion } "` ,
109109) ;
110110
111- // 4. Write files
112- try {
113- fs . writeFileSync ( rootPackageJsonPath , updatedRootJsonContent , "utf8" ) ;
114- } catch ( err ) {
115- console . error ( `Error writing to root package.json: ${ err . message } ` ) ;
116- process . exit ( 1 ) ;
117- }
118-
119- try {
120- fs . writeFileSync ( frontendPackageJsonPath , updatedFrontendJsonContent , "utf8" ) ;
121- } catch ( err ) {
122- console . error ( `Error writing to frontend package.json: ${ err . message } ` ) ;
123- process . exit ( 1 ) ;
111+ // 4. Write files with rollback capability
112+ const writes = [
113+ {
114+ path : rootPackageJsonPath ,
115+ content : updatedRootJsonContent ,
116+ original : rootPackageJsonContent ,
117+ label : "root package.json" ,
118+ } ,
119+ {
120+ path : frontendPackageJsonPath ,
121+ content : updatedFrontendJsonContent ,
122+ original : frontendPackageJsonContent ,
123+ label : "frontend/package.json" ,
124+ } ,
125+ {
126+ path : cargoTomlPath ,
127+ content : updatedCargoTomlContent ,
128+ original : cargoTomlContent ,
129+ label : "frontend/src-tauri/Cargo.toml" ,
130+ } ,
131+ ] ;
132+
133+ const completed = [ ] ;
134+ for ( const write of writes ) {
135+ try {
136+ fs . writeFileSync ( write . path , write . content , "utf8" ) ;
137+ completed . push ( write ) ;
138+ } catch ( err ) {
139+ console . error ( `\nError writing to ${ write . label } : ${ err . message } ` ) ;
140+ console . error ( "Initiating rollback..." ) ;
141+
142+ const rollbackFailures = [ ] ;
143+ for ( const completedWrite of completed ) {
144+ try {
145+ fs . writeFileSync ( completedWrite . path , completedWrite . original , "utf8" ) ;
146+ console . log ( `Rolled back changes in ${ completedWrite . label } ` ) ;
147+ } catch ( rollbackErr ) {
148+ console . error (
149+ `Critical Error: Failed to rollback ${ completedWrite . label } : ${ rollbackErr . message } ` ,
150+ ) ;
151+ rollbackFailures . push ( completedWrite ) ;
152+ }
153+ }
154+
155+ if ( rollbackFailures . length > 0 ) {
156+ console . error (
157+ "\nWARNING: Manual inspection is required. Some files could not be restored to their original state:" ,
158+ ) ;
159+ for ( const failed of rollbackFailures ) {
160+ console . error ( `- ${ failed . label } (${ failed . path } )` ) ;
161+ }
162+ } else {
163+ console . log ( "All completed writes successfully rolled back." ) ;
164+ }
165+ process . exit ( 1 ) ;
166+ }
124167}
125168
126- try {
127- fs . writeFileSync ( cargoTomlPath , updatedCargoTomlContent , "utf8" ) ;
128- } catch ( err ) {
129- console . error ( `Error writing to Cargo.toml: ${ err . message } ` ) ;
130- process . exit ( 1 ) ;
131- }
132169
133170// 5. Print summary
134171console . log ( "\nVersion bump successful!" ) ;
0 commit comments