Skip to content

Commit d93d42e

Browse files
feat: add bundle export feature (#5)
1 parent c16ea82 commit d93d42e

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ Add the following tasks to your `tasks.json` file (you can open it with the `zed
6767
"label": "update flatpak dependencies",
6868
"command": "flatplay update-dependencies"
6969
},
70+
{
71+
"label": "export flatpak bundle",
72+
"command": "flatplay export-bundle"
73+
},
7074
{
7175
"label": "select flatpak manifest",
7276
"command": "flatplay select-manifest"

src/lib.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ enum Commands {
3535
RuntimeTerminal,
3636
/// Spawn a new terminal inside the current build repository
3737
BuildTerminal,
38+
/// Export .flatpak bundle from the build
39+
ExportBundle,
3840
/// Select or change the active manifest
3941
SelectManifest {
4042
/// Path to the manifest file to select
@@ -154,6 +156,7 @@ fn main() {
154156
Some(Commands::Clean) => handle_command!(flatpak_manager.clean()),
155157
Some(Commands::RuntimeTerminal) => handle_command!(flatpak_manager.runtime_terminal()),
156158
Some(Commands::BuildTerminal) => handle_command!(flatpak_manager.build_terminal()),
159+
Some(Commands::ExportBundle) => handle_command!(flatpak_manager.export_bundle()),
157160
Some(Commands::SelectManifest { path }) => {
158161
handle_command!(flatpak_manager.select_manifest(path.clone()))
159162
}

0 commit comments

Comments
 (0)