require script is present during pack step iff any pkg procs are type script

This commit is contained in:
Keagan McClelland
2022-05-17 16:46:10 -06:00
parent c8fc9a98bf
commit 6801ff996e
3 changed files with 36 additions and 3 deletions

View File

@@ -77,6 +77,12 @@ pub enum PackageProcedure {
Script(JsProcedure),
}
impl PackageProcedure {
pub fn is_script(&self) -> bool {
match self {
Self::Js(_) => true,
_ => false,
}
}
#[instrument]
pub fn validate(
&self,

View File

@@ -154,6 +154,29 @@ pub struct Manifest {
pub dependencies: Dependencies,
}
impl Manifest {
pub fn package_procedures(&self) -> impl Iterator<Item = &PackageProcedure> {
use std::iter::once;
let main = once(&self.main);
let cfg_get = self.config.as_ref().map(|a| &a.get).into_iter();
let cfg_set = self.config.as_ref().map(|a| &a.set).into_iter();
let props = self.properties.iter();
let backups = vec![&self.backup.create, &self.backup.restore].into_iter();
let migrations = self
.migrations
.to
.values()
.chain(self.migrations.from.values());
let actions = self.actions.0.values().map(|a| &a.implementation);
main.chain(cfg_get)
.chain(cfg_set)
.chain(props)
.chain(backups)
.chain(migrations)
.chain(actions)
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct Assets {

View File

@@ -13,7 +13,7 @@ use crate::s9pk::reader::S9pkReader;
use crate::util::display_none;
use crate::util::serde::IoFormat;
use crate::volume::Volume;
use crate::{Error, ResultExt};
use crate::{Error, ErrorKind, ResultExt};
pub mod builder;
pub mod header;
@@ -123,8 +123,12 @@ pub async fn pack(#[context] ctx: SdkContext, #[arg] path: Option<PathBuf>) -> R
})
.scripts({
let script_path = path.join(manifest.assets.scripts_path()).join("embassy.js");
if script_path.exists() {
Some(File::open(script_path).await?)
if manifest.package_procedures().any(|a| a.is_script()) {
if script_path.exists() {
Some(File::open(script_path).await?)
} else {
return Err(Error::new(eyre!("Script is declared in manifest, but no such script exists at ./scripts/embassy.js"), ErrorKind::Pack).into())
}
} else {
None
}