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

View File

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