Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/require script consistency #1451

Merged
merged 5 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
require script is present during pack step iff any pkg procs are type…
… script
  • Loading branch information
ProofOfKeags committed May 27, 2022
commit b74031324a6cca46c24a365e21617461106ad497
6 changes: 6 additions & 0 deletions backend/src/procedure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions backend/src/s9pk/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,29 @@ pub struct Manifest {
pub dependencies: Dependencies,
}

impl Manifest {
pub fn package_procedures(&self) -> impl Iterator<Item = &PackageProcedure> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 I don't like the looks of this but there are no working solutions. I think that a generator syntax would work better.

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 {
Expand Down
10 changes: 7 additions & 3 deletions backend/src/s9pk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down