@@ -415,6 +415,82 @@ impl<'a> FlatpakManager<'a> {
415415 run_command ( "flatpak" , & args_str, Some ( self . state . base_dir . as_path ( ) ) )
416416 }
417417
418+ pub fn export_bundle ( & self ) -> Result < ( ) > {
419+ if !self . state . application_built {
420+ println ! (
421+ "{}" ,
422+ "Application not built. Please run `build` first." . yellow( )
423+ ) ;
424+ return Ok ( ( ) ) ;
425+ }
426+
427+ // Check if build is initialized
428+ if !self . is_build_initialized ( ) ? {
429+ println ! (
430+ "{}" ,
431+ "Build not initialized. Please run `build` first." . yellow( )
432+ ) ;
433+ return Ok ( ( ) ) ;
434+ }
435+
436+ let manifest = self . manifest . as_ref ( ) . unwrap ( ) ;
437+ let repo_dir = self . build_dir ( ) . join ( "repo" ) ;
438+ let finalized_repo_dir = self . build_dir ( ) . join ( "finalized-repo" ) ;
439+ let ostree_dir = self . build_dir ( ) . join ( "ostree" ) ;
440+
441+ // Remove finalized repo
442+ if finalized_repo_dir. is_dir ( ) {
443+ fs:: remove_dir_all ( & finalized_repo_dir) ?;
444+ }
445+
446+ // Copy repo
447+ run_command (
448+ "cp" ,
449+ & [
450+ "-r" ,
451+ repo_dir. to_str ( ) . unwrap ( ) ,
452+ finalized_repo_dir. to_str ( ) . unwrap ( ) ,
453+ ] ,
454+ Some ( self . state . base_dir . as_path ( ) ) ,
455+ ) ?;
456+
457+ // Finalize build
458+ let mut args = vec ! [ "build-finish" . to_string( ) ] ;
459+
460+ for arg in & manifest. finish_args {
461+ args. push ( arg. clone ( ) ) ;
462+ }
463+ args. push ( format ! ( "--command={}" , manifest. command. clone( ) ) ) ;
464+ args. push ( finalized_repo_dir. to_str ( ) . unwrap ( ) . to_string ( ) ) ;
465+
466+ let args_str: Vec < & str > = args. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
467+
468+ run_command ( "flatpak" , & args_str, Some ( self . state . base_dir . as_path ( ) ) ) ?;
469+
470+ // Export build
471+ run_command (
472+ "flatpak" ,
473+ & [
474+ "build-export" ,
475+ ostree_dir. to_str ( ) . unwrap ( ) ,
476+ finalized_repo_dir. to_str ( ) . unwrap ( ) ,
477+ ] ,
478+ Some ( self . state . base_dir . as_path ( ) ) ,
479+ ) ?;
480+
481+ // Bundle build
482+ run_command (
483+ "flatpak" ,
484+ & [
485+ "build-bundle" ,
486+ ostree_dir. to_str ( ) . unwrap ( ) ,
487+ format ! ( "{}.flatpak" , manifest. id. clone( ) ) . as_str ( ) ,
488+ manifest. id . clone ( ) . as_str ( ) ,
489+ ] ,
490+ Some ( self . state . base_dir . as_path ( ) ) ,
491+ )
492+ }
493+
418494 pub fn clean ( & mut self ) -> Result < ( ) > {
419495 let build_dir = self . build_dir ( ) ;
420496 if fs:: metadata ( & build_dir) . is_ok ( ) {
0 commit comments