make scripts optional

This commit is contained in:
Keagan McClelland
2022-05-16 15:37:15 -06:00
parent 7e4c0d660a
commit a253e95b5a
2 changed files with 16 additions and 10 deletions

View File

@@ -29,7 +29,7 @@ pub struct S9pkPacker<
icon: RIcon,
docker_images: RDockerImages,
assets: RAssets,
scripts: RScripts,
scripts: Option<RScripts>,
}
impl<
'a,
@@ -118,14 +118,16 @@ impl<
};
position = new_pos;
// scripts
std::io::copy(&mut self.scripts, &mut writer)
.with_ctx(|_| (crate::ErrorKind::Filesystem, "Copying Scripts"))?;
let new_pos = writer.inner_mut().stream_position()?;
header.table_of_contents.scripts = Some(FileSection {
position,
length: new_pos - position,
});
position = new_pos;
if let Some(mut scripts) = self.scripts {
std::io::copy(&mut scripts, &mut writer)
.with_ctx(|_| (crate::ErrorKind::Filesystem, "Copying Scripts"))?;
let new_pos = writer.inner_mut().stream_position()?;
header.table_of_contents.scripts = Some(FileSection {
position,
length: new_pos - position,
});
position = new_pos;
}
// header
let (hash, _) = writer.finish();

View File

@@ -107,7 +107,11 @@ pub fn pack(#[context] ctx: SdkContext, #[arg] path: Option<PathBuf>) -> Result<
})
.scripts({
let script_path = path.join(manifest.assets.scripts_path()).join("embassy.js");
File::open(script_path)?
if script_path.exists() {
Some(File::open(script_path)?)
} else {
None
}
})
.build()
.pack(&ctx.developer_key()?)?;