Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
feat#447: Add 'assets' key to Project
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymichal committed Aug 27, 2019
1 parent 7c27abb commit 261aa4a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/settings/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Project {
pub routes: Option<HashMap<String, String>>,
#[serde(rename = "kv-namespaces")]
pub kv_namespaces: Option<Vec<KvNamespace>>,
pub assets: Option<Assets>,
}

impl Project {
Expand All @@ -47,6 +48,7 @@ impl Project {
routes: None,
kv_namespaces: None,
webpack_config: None,
assets: None,
};

let toml = toml::to_string(&project)?;
Expand Down Expand Up @@ -90,6 +92,7 @@ fn get_project_config(config_path: &Path) -> Result<Project, failure::Error> {
if let Ok(values) = kv_namespaces {
let old_format = values.iter().any(|val| val.clone().into_str().is_ok());

// TODO: remove old format deprecation warnings
if old_format {
message::warn("As of 1.1.0 the kv-namespaces format has been stabilized");
message::info("Please add a section like this in your `wrangler.toml` for each KV Namespace you wish to bind:");
Expand Down Expand Up @@ -125,5 +128,11 @@ id = "0f2ac74b498b48028cb68387c421e279"
}
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Assets {
directory: String,
kv: String,
}

#[cfg(test)]
mod tests;
15 changes: 15 additions & 0 deletions src/settings/project/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ fn it_builds_from_config_with_kv() {
}
}

#[test]
fn it_builds_from_config_with_assets() {
let toml_path = toml_fixture_path("assets");

let project = get_project_config(&toml_path).unwrap();

match project.assets {
Some(assets) => {
assert_eq!(assets.directory, "./");
assert_eq!(assets.kv, "prodKV");
}
None => assert!(false),
}
}

fn toml_fixture_path(fixture: &str) -> PathBuf {
let current_dir = env::current_dir().unwrap();

Expand Down
11 changes: 11 additions & 0 deletions src/settings/project/tests/tomls/assets.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name = "worker"
type = "webpack"
zone_id = ""
private = false
account_id = ""
route = ""
assets = { directory = "./", kv = "prodKV" }

[[kv-namespaces]]
id = "somecrazylongidentifierstring"
binding = "prodKV"

0 comments on commit 261aa4a

Please sign in to comment.