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

Add Sylvia template #129

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CosmWasm swiss-army knife configured for Osmosis by default, but trivial to make it work for other CosmWasm enabled chain.

Version: 0.1.5
Version: 0.1.8

## Subcommands

Expand Down Expand Up @@ -52,4 +52,4 @@ Arguments:

Managing tasks for the project

[\> `beaker task`'s subcommands](./beaker_task.md)
[\> `beaker task`'s subcommands](./beaker_task.md)
2 changes: 2 additions & 0 deletions docs/commands/beaker_wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Arguments:

* `-v / --version <VERSION>`: Template's version, using main branch if not specified

* `--template <TEMPLATE>`: Template name, prompt for template if not specified

---

### `beaker wasm build`
Expand Down
7 changes: 5 additions & 2 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ target_dir = '.'

[wasm]
contract_dir = 'contracts'
template_repo = 'https://github.com/osmosis-labs/cw-minimal-template'
optimizer_version = '0.12.8'
optimizer_version = '0.14.0'

[wasm.template_repos]
classic = 'https://github.com/osmosis-labs/cw-minimal-template'
sylvia = 'https://github.com/osmosis-labs/cw-sylvia-template'


# console
Expand Down
15 changes: 9 additions & 6 deletions docs/config/wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@



* **`template_repo`** : String
* **`optimizer_version`** : String

>
> Reference to contract template repository
> Version of rust-optimizer
>



* **`optimizer_version`** : String
* **`template_repos`** : HashMap < String, String >

>
> Version of rust-optimizer
> Reference to contract template repository
>


Expand All @@ -35,6 +35,9 @@
```toml
[wasm]
contract_dir = 'contracts'
template_repo = 'https://github.com/osmosis-labs/cw-minimal-template'
optimizer_version = '0.12.8'
optimizer_version = '0.14.0'

[wasm.template_repos]
sylvia = 'https://github.com/osmosis-labs/cw-sylvia-template'
classic = 'https://github.com/osmosis-labs/cw-minimal-template'
```
2 changes: 1 addition & 1 deletion packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "CosmWasm swiss-army knife configured for Osmosis by default, but
edition = "2021"
license = "MIT OR Apache-2.0"
name = "beaker"
version = "0.1.7"
version = "0.1.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ contract_dir = "whatever""#;
contract_name: "counter".to_string(),
target_dir: None,
version: None,
template: Some("classic".into()),
},
})
.unwrap();
Expand Down
24 changes: 19 additions & 5 deletions packages/cli/src/modules/wasm/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use data_doc_derive::GetDataDocs;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -7,19 +9,31 @@ pub struct WasmConfig {
/// Directory for storing contracts
pub contract_dir: String,

/// Reference to contract template repository
pub template_repo: String,

/// Version of rust-optimizer
pub optimizer_version: String,

/// Reference to contract template repository
pub template_repos: HashMap<String, String>,
}

impl Default for WasmConfig {
fn default() -> Self {
let mut template_repo = HashMap::new();

template_repo.insert(
"classic".to_string(),
"https://github.com/osmosis-labs/cw-minimal-template".to_string(),
);

template_repo.insert(
"sylvia".to_string(),
"https://github.com/osmosis-labs/cw-sylvia-template".to_string(),
);

Self {
contract_dir: "contracts".to_string(),
template_repo: "https://github.com/osmosis-labs/cw-minimal-template".to_string(),
optimizer_version: "0.12.8".to_string(),
template_repos: template_repo,
optimizer_version: "0.14.0".to_string(),
}
}
}
32 changes: 29 additions & 3 deletions packages/cli/src/modules/wasm/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub enum WasmCmd {
/// Template's version, using main branch if not specified
#[clap(short, long)]
version: Option<String>,

/// Template name, prompt for template if not specified
#[clap(long)]
template: Option<String>,
},
/// Build .wasm for storing contract code on the blockchain
Build {
Expand Down Expand Up @@ -367,7 +371,14 @@ impl<'a> Module<'a, WasmConfig, WasmCmd, anyhow::Error> for WasmModule {
contract_name: name,
target_dir, // TODO: Rremove this
version,
} => ops::new(&ctx, name, version.to_owned(), target_dir.to_owned()),
template,
} => ops::new(
&ctx,
name,
version.to_owned(),
target_dir.to_owned(),
template.to_owned(),
),
cmd @ WasmCmd::Build { .. } => build(ctx, cmd),
cmd @ WasmCmd::StoreCode { .. } => store_code(ctx, cmd).map(|_| ()),
cmd @ WasmCmd::UpdateAdmin { .. } => update_admin(ctx, cmd).map(|_| ()),
Expand Down Expand Up @@ -816,7 +827,7 @@ pub(crate) fn execute<'a>(

#[cfg(test)]
mod tests {
use std::{env, fs, path::Path};
use std::{collections::HashMap, env, fs, path::Path};

use assert_fs::{prelude::*, TempDir};
use cargo_toml::{Dependency, DependencyDetail, Manifest};
Expand Down Expand Up @@ -845,6 +856,7 @@ mod tests {
contract_name: "counter-1".to_string(),
version: None,
target_dir: None,
template: Some("classic".into()),
},
)
.unwrap();
Expand All @@ -860,6 +872,7 @@ mod tests {
contract_name: "counter-2".to_string(),
target_dir: None,
version: None,
template: Some("classic".into()),
},
)
.unwrap();
Expand All @@ -886,6 +899,7 @@ mod tests {
contract_name: "counter-1".to_string(),
target_dir: None,
version: None,
template: Some("classic".into()),
},
)
.unwrap();
Expand All @@ -898,6 +912,7 @@ mod tests {
contract_name: "counter-2".to_string(),
target_dir: None,
version: None,
template: Some("classic".into()),
},
)
.unwrap();
Expand All @@ -921,8 +936,15 @@ mod tests {
struct WasmContext {}
impl<'a> Context<'a, WasmConfig> for WasmContext {
fn config(&self) -> Result<WasmConfig> {
let mut template_repos = HashMap::new();

template_repos.insert(
"classic".to_string(),
"https://github.com/CosmWasm/cw-template.git".to_string(),
);

Ok(WasmConfig {
template_repo: "https://github.com/CosmWasm/cw-template.git".to_string(),
template_repos,
..Default::default()
})
}
Expand All @@ -934,6 +956,7 @@ mod tests {
contract_name: "counter-1".to_string(),
target_dir: None,
version: Some("0.16".into()),
template: Some("classic".into()),
},
)
.unwrap();
Expand All @@ -947,6 +970,7 @@ mod tests {
contract_name: "counter-2".to_string(),
target_dir: None,
version: Some("0.16".into()),
template: Some("classic".into()),
},
)
.unwrap();
Expand Down Expand Up @@ -975,6 +999,7 @@ mod tests {
contract_name: "counter-1".to_string(),
target_dir: Some("custom-path".into()),
version: None,
template: Some("classic".into()),
},
)
.unwrap();
Expand All @@ -987,6 +1012,7 @@ mod tests {
contract_name: "counter-2".to_string(),
target_dir: Some("custom-path".into()),
version: None,
template: Some("classic".into()),
},
)
.unwrap();
Expand Down
38 changes: 35 additions & 3 deletions packages/cli/src/modules/wasm/ops/new.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
use crate::framework::Context;
use crate::modules::wasm::config::WasmConfig;
use crate::support::template::Template;
use anyhow::Result;
use anyhow::{Context as _, Result};
use console::{style, Emoji};
use dialoguer::{theme::ColorfulTheme, Select};
use std::path::PathBuf;

pub static SHRUG: Emoji<'_, '_> = Emoji("🤷 ", "");

pub fn new<'a, Ctx: Context<'a, WasmConfig>>(
ctx: &Ctx,
name: &str,
version: Option<String>,
target_dir: Option<PathBuf>,
template: Option<String>,
) -> Result<()> {
let cfg = ctx.config()?;
let repo = &cfg.template_repo;
let templates = cfg.template_repos.keys().collect::<Vec<_>>();
let version = version.unwrap_or_else(|| "main".to_string());
let target_dir =
target_dir.unwrap_or(ctx.root()?.join(PathBuf::from(cfg.contract_dir.as_str())));

let cw_template = Template::new(name.to_string(), repo.to_owned(), version, None, target_dir);
let repo = if let Some(template) = template {
cfg.template_repos
.get(&template)
.ok_or_else(|| anyhow::anyhow!("Unable to get template repository"))?
} else {
let template_idx = Select::with_theme(&ColorfulTheme::default())
.with_prompt(format!(
"{} {}",
SHRUG,
style("Which template would you like to use?").bold()
))
.items(&templates)
.default(0)
.interact()
.with_context(|| "Canceled")?;

cfg.template_repos
.get(templates[template_idx].as_str())
.ok_or_else(|| anyhow::anyhow!("Unable to get template repository"))?
};

let cw_template = Template::new(
name.to_string(),
repo.to_string(),
version,
None,
target_dir,
);
cw_template.generate()
}
4 changes: 2 additions & 2 deletions ts/beaker-console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "beaker-console",
"version": "0.1.6",
"version": "0.1.8",
"description": "",
"cdn": "dist/index.umd.js",
"main": "dist/index.js",
Expand Down Expand Up @@ -77,4 +77,4 @@
"overrides": {
"emphasize": "4.2.0"
}
}
}
Loading