diff --git a/.gitignore b/.gitignore index 9a2038ec..e6004fe2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,11 @@ **/node_modules/ /src/x.rs +debug +**/debug/ + .DS_Store # IDEs .idea -.vscode \ No newline at end of file +.vscode diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 14bcbb7c..d988dbcf 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -4,8 +4,8 @@ use anyhow::anyhow; use clap::Args; use cliclack::{clear_screen, intro, log, outro, outro_cancel}; use pop_contracts::{ - dry_run_gas_estimate_instantiate, instantiate_smart_contract, parse_hex_bytes, - set_up_deployment, UpOpts, + build_smart_contract, dry_run_gas_estimate_instantiate, instantiate_smart_contract, + parse_hex_bytes, set_up_deployment, UpOpts, }; use sp_core::Bytes; use sp_weights::Weight; @@ -54,6 +54,21 @@ pub struct UpContractCommand { impl UpContractCommand { pub(crate) async fn execute(&self) -> anyhow::Result<()> { clear_screen()?; + + // Check if build exists in the specified "Contract build folder" + let build_path = PathBuf::from( + self.path.clone().unwrap_or("/.".into()).to_string_lossy().to_string() + "/target/ink", + ); + + if !build_path.as_path().exists() { + log::warning(format!("NOTE: contract has not yet been built."))?; + intro(format!("{}: Building a contract", style(" Pop CLI ").black().on_magenta()))?; + // Directory exists, proceed with the rest of the code + let result = build_smart_contract(&self.path)?; + log::success(result.to_string())?; + } + + // if build exists then proceed intro(format!("{}: Deploy a smart contract", style(" Pop CLI ").black().on_magenta()))?; let instantiate_exec = set_up_deployment(UpOpts {