From 79a3aa1e50aa0a882e4bec160c005a83595aa7de Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:14:28 -0400 Subject: [PATCH 1/3] Feat/use rich printer for init (#1548) --- cmd/soroban-cli/src/commands/contract/init.rs | 813 ++++++++++-------- cmd/soroban-cli/src/commands/contract/mod.rs | 2 +- cmd/soroban-cli/src/print.rs | 1 + 3 files changed, 446 insertions(+), 370 deletions(-) diff --git a/cmd/soroban-cli/src/commands/contract/init.rs b/cmd/soroban-cli/src/commands/contract/init.rs index e38f27d7e..0d451f6fe 100644 --- a/cmd/soroban-cli/src/commands/contract/init.rs +++ b/cmd/soroban-cli/src/commands/contract/init.rs @@ -14,13 +14,15 @@ use std::{ }, io::{self, Read, Write}, num::NonZeroU32, - path::Path, + path::{Path, PathBuf}, str, sync::atomic::AtomicBool, }; use toml_edit::{Document, TomlError}; use ureq::get; +use crate::{commands::global, print}; + const SOROBAN_EXAMPLES_URL: &str = "https://github.com/stellar/soroban-examples.git"; const GITHUB_URL: &str = "https://github.com"; const WITH_EXAMPLE_LONG_HELP_TEXT: &str = @@ -81,380 +83,415 @@ pub enum Error { impl Cmd { #[allow(clippy::unused_self)] - pub fn run(&self) -> Result<(), Error> { - println!("ℹ️ Initializing project at {}", self.project_path); - let project_path = Path::new(&self.project_path); - - init( - project_path, - &self.frontend_template, - &self.with_example, - self.overwrite, - )?; + pub fn run(&self, global_args: &global::Args) -> Result<(), Error> { + let runner = Runner { + args: self.clone(), + print: print::Print::new(global_args.quiet), + }; - Ok(()) + runner.run() } } #[derive(RustEmbed)] #[folder = "src/utils/contract-init-template"] struct TemplateFiles; +struct Runner { + args: Cmd, + print: print::Print, +} -fn init( - project_path: &Path, - frontend_template: &str, - with_examples: &[String], - overwrite: bool, -) -> Result<(), Error> { - // create a project dir, and copy the contents of the base template (contract-init-template) into it - create_dir_all(project_path).map_err(|e| { - eprintln!("Error creating new project directory: {project_path:?}"); - e - })?; - copy_template_files(project_path, overwrite)?; - - if !check_internet_connection() { - println!("⚠️ It doesn't look like you're connected to the internet. We're still able to initialize a new project, but additional examples and the frontend template will not be included."); - return Ok(()); - } - - if !frontend_template.is_empty() { - // create a temp dir for the template repo - let fe_template_dir = tempfile::tempdir().map_err(|e| { - eprintln!("Error creating temp dir for frontend template"); - e - })?; - - // clone the template repo into the temp dir - clone_repo(frontend_template, fe_template_dir.path())?; - - // copy the frontend template files into the project - copy_frontend_files(fe_template_dir.path(), project_path, overwrite)?; - } +impl Runner { + fn run(&self) -> Result<(), Error> { + let project_path = PathBuf::from(&self.args.project_path); + self.print + .infoln(format!("Initializing project at {project_path:?}")); - // if there are --with-example flags, include the example contracts - if include_example_contracts(with_examples) { - // create an examples temp dir - let examples_dir = tempfile::tempdir().map_err(|e| { - eprintln!("Error creating temp dir for soroban-examples"); + // create a project dir, and copy the contents of the base template (contract-init-template) into it + create_dir_all(&project_path).map_err(|e| { + self.print + .errorln("Error creating new project directory: {project_path:?}"); e })?; + self.copy_template_files()?; - // clone the soroban-examples repo into the temp dir - clone_repo(SOROBAN_EXAMPLES_URL, examples_dir.path())?; + if !Self::check_internet_connection() { + self.print.warnln("It doesn't look like you're connected to the internet. We're still able to initialize a new project, but additional examples and the frontend template will not be included."); + return Ok(()); + } - // copy the example contracts into the project - copy_example_contracts(examples_dir.path(), project_path, with_examples, overwrite)?; - } + if !self.args.frontend_template.is_empty() { + // create a temp dir for the template repo + let fe_template_dir = tempfile::tempdir().map_err(|e| { + self.print + .errorln("Error creating temp dir for frontend template"); + e + })?; - Ok(()) -} + // clone the template repo into the temp dir + self.clone_repo(&self.args.frontend_template, fe_template_dir.path())?; -fn copy_template_files(project_path: &Path, overwrite: bool) -> Result<(), Error> { - for item in TemplateFiles::iter() { - let mut to = project_path.join(item.as_ref()); - let exists = file_exists(&to); - if exists && !overwrite { - println!( - "ℹ️ Skipped creating {} as it already exists", - &to.to_string_lossy() - ); - continue; + // copy the frontend template files into the project + self.copy_frontend_files(fe_template_dir.path(), &project_path)?; } - create_dir_all(to.parent().unwrap()).map_err(|e| { - eprintln!("Error creating directory path for: {to:?}"); - e - })?; - let Some(file) = TemplateFiles::get(item.as_ref()) else { - println!("⚠️ Failed to read file: {}", item.as_ref()); - continue; - }; + // if there are --with-example flags, include the example contracts + if self.include_example_contracts() { + // create an examples temp dir + let examples_dir = tempfile::tempdir().map_err(|e| { + self.print + .errorln("Error creating temp dir for soroban-examples"); + e + })?; - let file_contents = std::str::from_utf8(file.data.as_ref()).map_err(|e| { - eprintln!( - "Error converting file contents in {:?} to string", - item.as_ref() - ); - e - })?; + // clone the soroban-examples repo into the temp dir + self.clone_repo(SOROBAN_EXAMPLES_URL, examples_dir.path())?; - // We need to include the Cargo.toml file as Cargo.toml.removeextension in the template so that it will be included the package. This is making sure that the Cargo file is written as Cargo.toml in the new project. This is a workaround for this issue: https://github.com/rust-lang/cargo/issues/8597. - let item_path = Path::new(item.as_ref()); - if item_path.file_name().unwrap() == "Cargo.toml.removeextension" { - let item_parent_path = item_path.parent().unwrap(); - to = project_path.join(item_parent_path).join("Cargo.toml"); + // copy the example contracts into the project + self.copy_example_contracts( + examples_dir.path(), + &project_path, + &self.args.with_example, + )?; } - if exists { - println!("🔄 Overwriting {}", &to.to_string_lossy()); - } else { - println!("➕ Writing {}", &to.to_string_lossy()); - } - write(&to, file_contents).map_err(|e| { - eprintln!("Error writing file: {to:?}"); - e - })?; + Ok(()) } - Ok(()) -} -fn copy_contents(from: &Path, to: &Path, overwrite: bool) -> Result<(), Error> { - let contents_to_exclude_from_copy = [ - ".git", - ".github", - "Makefile", - ".vscode", - "target", - "Cargo.lock", - ]; - for entry in read_dir(from).map_err(|e| { - eprintln!("Error reading directory: {from:?}"); - e - })? { - let entry = entry.map_err(|e| { - eprintln!("Error reading entry in directory: {from:?}"); - e - })?; - let path = entry.path(); - let entry_name = entry.file_name().to_string_lossy().to_string(); - let new_path = to.join(&entry_name); + fn copy_template_files(&self) -> Result<(), Error> { + let project_path = Path::new(&self.args.project_path); + for item in TemplateFiles::iter() { + let mut to = project_path.join(item.as_ref()); + let exists = Self::file_exists(&to); + if exists && !self.args.overwrite { + self.print + .infoln(format!("Skipped creating {to:?} as it already exists")); + continue; + } - if contents_to_exclude_from_copy.contains(&entry_name.as_str()) { - continue; - } + create_dir_all(to.parent().unwrap()).map_err(|e| { + self.print + .errorln(format!("Error creating directory path for: {to:?}")); + e + })?; - if path.is_dir() { - create_dir_all(&new_path).map_err(|e| { - eprintln!("Error creating directory: {new_path:?}"); + let Some(file) = TemplateFiles::get(item.as_ref()) else { + self.print + .warnln(format!("Failed to read file: {}", item.as_ref())); + continue; + }; + + let file_contents = std::str::from_utf8(file.data.as_ref()).map_err(|e| { + self.print.errorln(format!( + "Error converting file contents in {:?} to string", + item.as_ref() + )); e })?; - copy_contents(&path, &new_path, overwrite)?; - } else { - let exists = file_exists(&new_path); - let new_path_str = new_path.to_string_lossy(); - if exists { - let append = - new_path_str.contains(".gitignore") || new_path_str.contains("README.md"); - if append { - append_contents(&path, &new_path)?; - } - if overwrite && !append { - println!("🔄 Overwriting {new_path_str}"); - } else { - println!("ℹ️ Skipped creating {new_path_str} as it already exists"); - continue; - } + // We need to include the Cargo.toml file as Cargo.toml.removeextension in the template so that it will be included the package. This is making sure that the Cargo file is written as Cargo.toml in the new project. This is a workaround for this issue: https://github.com/rust-lang/cargo/issues/8597. + let item_path = Path::new(item.as_ref()); + if item_path.file_name().unwrap() == "Cargo.toml.removeextension" { + let item_parent_path = item_path.parent().unwrap(); + to = project_path.join(item_parent_path).join("Cargo.toml"); + } + + if exists { + self.print + .plusln(format!("Writing {to:?} (overwriting existing file)")); } else { - println!("➕ Writing {new_path_str}"); + self.print.plusln(format!("Writing {to:?}")); } - copy(&path, &new_path).map_err(|e| { - eprintln!( - "Error copying from {:?} to {:?}", - path.to_string_lossy(), - new_path - ); + write(&to, file_contents).map_err(|e| { + self.print.errorln(format!("Error writing file: {to:?}")); e })?; } + Ok(()) } - Ok(()) -} - -fn file_exists(file_path: &Path) -> bool { - metadata(file_path) - .as_ref() - .map(Metadata::is_file) - .unwrap_or(false) -} + fn copy_contents(&self, from: &Path, to: &Path) -> Result<(), Error> { + let contents_to_exclude_from_copy = [ + ".git", + ".github", + "Makefile", + ".vscode", + "target", + "Cargo.lock", + ]; + for entry in read_dir(from).map_err(|e| { + self.print + .errorln(format!("Error reading directory: {from:?}")); + e + })? { + let entry = entry.map_err(|e| { + self.print + .errorln(format!("Error reading entry in directory: {from:?}")); + e + })?; + let path = entry.path(); + let entry_name = entry.file_name().to_string_lossy().to_string(); + let new_path = to.join(&entry_name); -fn include_example_contracts(contracts: &[String]) -> bool { - !contracts.is_empty() -} + if contents_to_exclude_from_copy.contains(&entry_name.as_str()) { + continue; + } -fn clone_repo(from_url: &str, to_path: &Path) -> Result<(), Error> { - let mut prepare = clone::PrepareFetch::new( - from_url, - to_path, - create::Kind::WithWorktree, - create::Options { - destination_must_be_empty: false, - fs_capabilities: None, - }, - open::Options::isolated(), - ) - .map_err(|e| { - eprintln!("Error preparing fetch for {from_url:?}"); - Box::new(e) - })? - .with_shallow(remote::fetch::Shallow::DepthAtRemote( - NonZeroU32::new(1).unwrap(), - )); - - let (mut checkout, _outcome) = prepare - .fetch_then_checkout(progress::Discard, &AtomicBool::new(false)) - .map_err(|e| { - eprintln!("Error calling fetch_then_checkout with {from_url:?}"); - Box::new(e) - })?; + if path.is_dir() { + create_dir_all(&new_path).map_err(|e| { + self.print + .errorln(format!("Error creating directory: {new_path:?}")); + e + })?; + self.copy_contents(&path, &new_path)?; + } else { + let exists = Self::file_exists(&new_path); + let new_path_str = new_path.to_string_lossy(); + if exists { + let append = + new_path_str.contains(".gitignore") || new_path_str.contains("README.md"); + if append { + self.append_contents(&path, &new_path)?; + } + + if self.args.overwrite && !append { + self.print.plusln(format!( + "Writing {new_path_str} (overwriting existing file)" + )); + } else { + self.print.infoln(format!( + "Skipped creating {new_path_str} as it already exists" + )); + continue; + } + } else { + self.print.plus(format!("Writing {new_path_str}")); + } + copy(&path, &new_path).map_err(|e| { + self.print.errorln(format!( + "Error copying from {:?} to {:?}", + path.to_string_lossy(), + new_path + )); + e + })?; + } + } - let (_repo, _outcome) = checkout - .main_worktree(progress::Discard, &AtomicBool::new(false)) - .map_err(|e| { - eprintln!("Error calling main_worktree for {from_url:?}"); - e - })?; + Ok(()) + } - Ok(()) -} + fn file_exists(file_path: &Path) -> bool { + metadata(file_path) + .as_ref() + .map(Metadata::is_file) + .unwrap_or(false) + } -fn copy_example_contracts( - from: &Path, - to: &Path, - contracts: &[String], - overwrite: bool, -) -> Result<(), Error> { - let project_contracts_path = to.join("contracts"); - for contract in contracts { - println!("ℹ️ Initializing example contract: {contract}"); - let contract_as_string = contract.to_string(); - let contract_path = Path::new(&contract_as_string); - let from_contract_path = from.join(contract_path); - let to_contract_path = project_contracts_path.join(contract_path); - create_dir_all(&to_contract_path).map_err(|e| { - eprintln!("Error creating directory: {contract_path:?}"); - e - })?; + fn check_internet_connection() -> bool { + if let Ok(_req) = get(GITHUB_URL).call() { + return true; + } - copy_contents(&from_contract_path, &to_contract_path, overwrite)?; - edit_contract_cargo_file(&to_contract_path)?; + false } - Ok(()) -} + fn include_example_contracts(&self) -> bool { + !self.args.with_example.is_empty() + } -fn edit_contract_cargo_file(contract_path: &Path) -> Result<(), Error> { - let cargo_path = contract_path.join("Cargo.toml"); - let cargo_toml_str = read_to_string(&cargo_path).map_err(|e| { - eprint!("Error reading Cargo.toml file in: {contract_path:?}"); - e - })?; - - let cargo_toml_str = regex::Regex::new(r#"soroban-sdk = "[^\"]+""#) - .unwrap() - .replace_all( - cargo_toml_str.as_str(), - "soroban-sdk = { workspace = true }", - ); + fn clone_repo(&self, from_url: &str, to_path: &Path) -> Result<(), Error> { + let mut prepare = clone::PrepareFetch::new( + from_url, + to_path, + create::Kind::WithWorktree, + create::Options { + destination_must_be_empty: false, + fs_capabilities: None, + }, + open::Options::isolated(), + ) + .map_err(|e| { + self.print + .errorln(format!("Error preparing fetch for {from_url:?}")); + Box::new(e) + })? + .with_shallow(remote::fetch::Shallow::DepthAtRemote( + NonZeroU32::new(1).unwrap(), + )); + + let (mut checkout, _outcome) = prepare + .fetch_then_checkout(progress::Discard, &AtomicBool::new(false)) + .map_err(|e| { + self.print.errorln(format!( + "Error calling fetch_then_checkout with {from_url:?}" + )); + Box::new(e) + })?; - let cargo_toml_str = regex::Regex::new(r#"soroban-sdk = \{(.*) version = "[^"]+"(.+)}"#) - .unwrap() - .replace_all(&cargo_toml_str, "soroban-sdk = {$1 workspace = true$2}"); + let (_repo, _outcome) = checkout + .main_worktree(progress::Discard, &AtomicBool::new(false)) + .map_err(|e| { + self.print + .errorln(format!("Error calling main_worktree for {from_url:?}")); + e + })?; - let mut doc = cargo_toml_str.parse::().map_err(|e| { - eprintln!("Error parsing Cargo.toml file in: {contract_path:?}"); - e - })?; - doc.remove("profile"); + Ok(()) + } - write(&cargo_path, doc.to_string()).map_err(|e| { - eprintln!("Error writing to Cargo.toml file in: {contract_path:?}"); - e - })?; + fn copy_example_contracts( + &self, + from: &Path, + to: &Path, + contracts: &[String], + ) -> Result<(), Error> { + let project_contracts_path = to.join("contracts"); + for contract in contracts { + self.print + .infoln(format!("Initializing example contract: {contract}")); + let contract_as_string = contract.to_string(); + let contract_path = Path::new(&contract_as_string); + let from_contract_path = from.join(contract_path); + let to_contract_path = project_contracts_path.join(contract_path); + create_dir_all(&to_contract_path).map_err(|e| { + self.print + .errorln(format!("Error creating directory: {contract_path:?}")); + e + })?; - Ok(()) -} + self.copy_contents(&from_contract_path, &to_contract_path)?; + self.edit_contract_cargo_file(&to_contract_path)?; + } -fn copy_frontend_files(from: &Path, to: &Path, overwrite: bool) -> Result<(), Error> { - println!("ℹ️ Initializing with frontend template"); - copy_contents(from, to, overwrite)?; - edit_package_json_files(to) -} + Ok(()) + } -fn edit_package_json_files(project_path: &Path) -> Result<(), Error> { - let package_name = if let Some(name) = project_path.file_name() { - name.to_owned() - } else { - let current_dir = env::current_dir()?; - let file_name = current_dir - .file_name() - .unwrap_or(OsStr::new("soroban-astro-template")) - .to_os_string(); - file_name - }; + fn edit_contract_cargo_file(&self, contract_path: &Path) -> Result<(), Error> { + let cargo_path = contract_path.join("Cargo.toml"); + let cargo_toml_str = read_to_string(&cargo_path).map_err(|e| { + self.print.errorln(format!( + "Error reading Cargo.toml file in: {contract_path:?}" + )); + e + })?; - edit_package_name(project_path, &package_name, "package.json").map_err(|e| { - eprintln!("Error editing package.json file in: {project_path:?}"); - e - })?; - edit_package_name(project_path, &package_name, "package-lock.json") -} + let cargo_toml_str = regex::Regex::new(r#"soroban-sdk = "[^\"]+""#) + .unwrap() + .replace_all( + cargo_toml_str.as_str(), + "soroban-sdk = { workspace = true }", + ); -fn edit_package_name( - project_path: &Path, - package_name: &OsStr, - file_name: &str, -) -> Result<(), Error> { - let file_path = project_path.join(file_name); - let file_contents = read_to_string(&file_path)?; + let cargo_toml_str = regex::Regex::new(r#"soroban-sdk = \{(.*) version = "[^"]+"(.+)}"#) + .unwrap() + .replace_all(&cargo_toml_str, "soroban-sdk = {$1 workspace = true$2}"); - let mut doc: JsonValue = from_str(&file_contents).map_err(|e| { - eprintln!("Error parsing package.json file in: {project_path:?}"); - e - })?; + let mut doc = cargo_toml_str.parse::().map_err(|e| { + self.print.errorln(format!( + "Error parsing Cargo.toml file in: {contract_path:?}" + )); + e + })?; + doc.remove("profile"); - doc["name"] = json!(package_name.to_string_lossy()); + write(&cargo_path, doc.to_string()).map_err(|e| { + self.print.errorln(format!( + "Error writing to Cargo.toml file in: {contract_path:?}" + )); + e + })?; - let formatted_json = to_string_pretty(&doc)?; + Ok(()) + } - write(&file_path, formatted_json)?; + fn copy_frontend_files(&self, from: &Path, to: &Path) -> Result<(), Error> { + self.print.infoln("ℹ️ Initializing with frontend template"); + self.copy_contents(from, to)?; + self.edit_package_json_files(to) + } - Ok(()) -} + fn edit_package_json_files(&self, project_path: &Path) -> Result<(), Error> { + let package_name = if let Some(name) = project_path.file_name() { + name.to_owned() + } else { + let current_dir = env::current_dir()?; + let file_name = current_dir + .file_name() + .unwrap_or(OsStr::new("soroban-astro-template")) + .to_os_string(); + file_name + }; -fn check_internet_connection() -> bool { - if let Ok(_req) = get(GITHUB_URL).call() { - return true; + self.edit_package_name(project_path, &package_name, "package.json") + .map_err(|e| { + self.print.errorln(format!( + "Error editing package.json file in: {project_path:?}" + )); + e + })?; + self.edit_package_name(project_path, &package_name, "package-lock.json") } - false -} + fn edit_package_name( + &self, + project_path: &Path, + package_name: &OsStr, + file_name: &str, + ) -> Result<(), Error> { + let file_path = project_path.join(file_name); + let file_contents = read_to_string(&file_path)?; + + let mut doc: JsonValue = from_str(&file_contents).map_err(|e| { + self.print.errorln(format!( + "Error parsing {file_name} file in: {project_path:?}" + )); + e + })?; + + doc["name"] = json!(package_name.to_string_lossy()); -// Appends the contents of a file to another file, separated by a delimiter -fn append_contents(from: &Path, to: &Path) -> Result<(), Error> { - let mut from_file = File::open(from)?; - let mut from_content = String::new(); - from_file.read_to_string(&mut from_content)?; + let formatted_json = to_string_pretty(&doc)?; - let mut to_file = OpenOptions::new().read(true).append(true).open(to)?; - let mut to_content = String::new(); - to_file.read_to_string(&mut to_content)?; + write(&file_path, formatted_json)?; - let delimiter = get_merged_file_delimiter(to); - // if the to file already contains the delimiter, we don't need to append the contents again - if to_content.contains(&delimiter) { - return Ok(()); + Ok(()) } - to_file.write_all(delimiter.as_bytes())?; - to_file.write_all(from_content.as_bytes())?; + // Appends the contents of a file to another file, separated by a delimiter + fn append_contents(&self, from: &Path, to: &Path) -> Result<(), Error> { + let mut from_file = File::open(from)?; + let mut from_content = String::new(); + from_file.read_to_string(&mut from_content)?; - println!("ℹ️ Merging {} contents", &to.to_string_lossy()); - Ok(()) -} + let mut to_file = OpenOptions::new().read(true).append(true).open(to)?; + let mut to_content = String::new(); + to_file.read_to_string(&mut to_content)?; -fn get_merged_file_delimiter(file_path: &Path) -> String { - let comment = if file_path.to_string_lossy().contains("README.md") { - "---\n".to_string() - } else if file_path.to_string_lossy().contains("gitignore") { - "# The following is from the Frontend Template's .gitignore".to_string() - } else { - String::new() - }; + let delimiter = Self::get_merged_file_delimiter(to); + // if the to file already contains the delimiter, we don't need to append the contents again + if to_content.contains(&delimiter) { + return Ok(()); + } + + to_file.write_all(delimiter.as_bytes())?; + to_file.write_all(from_content.as_bytes())?; + + self.print.infoln(format!("Merging {to:?} contents")); + Ok(()) + } + + fn get_merged_file_delimiter(file_path: &Path) -> String { + let comment = if file_path.to_string_lossy().contains("README.md") { + "---\n".to_string() + } else if file_path.to_string_lossy().contains("gitignore") { + "# The following is from the Frontend Template's .gitignore".to_string() + } else { + String::new() + }; - format!("\n\n{comment}\n\n").to_string() + format!("\n\n{comment}\n\n").to_string() + } } #[cfg(test)] @@ -476,9 +513,16 @@ mod tests { fn test_init() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join(TEST_PROJECT_NAME); - let with_examples = vec![]; - let overwrite = false; - init(project_dir.as_path(), "", &with_examples, overwrite).unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: String::new(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); assert_base_template_files_exist(&project_dir); assert_default_hello_world_contract_files_exist(&project_dir); @@ -495,9 +539,16 @@ mod tests { fn test_init_including_example_contract() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join(TEST_PROJECT_NAME); - let with_examples = ["alloc".to_owned()]; - let overwrite = false; - init(project_dir.as_path(), "", &with_examples, overwrite).unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: ["alloc".to_owned()].to_vec(), + frontend_template: String::new(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); assert_base_template_files_exist(&project_dir); assert_default_hello_world_contract_files_exist(&project_dir); @@ -519,9 +570,16 @@ mod tests { fn test_init_including_multiple_example_contracts() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join("project"); - let with_examples = ["account".to_owned(), "atomic_swap".to_owned()]; - let overwrite = false; - init(project_dir.as_path(), "", &with_examples, overwrite).unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: ["account".to_owned(), "atomic_swap".to_owned()].to_vec(), + frontend_template: String::new(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); assert_base_template_files_exist(&project_dir); assert_default_hello_world_contract_files_exist(&project_dir); @@ -544,9 +602,16 @@ mod tests { fn test_init_with_invalid_example_contract() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join("project"); - let with_examples = ["invalid_example".to_owned(), "atomic_swap".to_owned()]; - let overwrite = false; - assert!(init(project_dir.as_path(), "", &with_examples, overwrite).is_err()); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: ["invalid_example".to_owned(), "atomic_swap".to_owned()].to_vec(), + frontend_template: String::new(), + overwrite: false, + }, + print: print::Print::new(false), + }; + assert!(runner.run().is_err()); temp_dir.close().unwrap(); } @@ -555,15 +620,16 @@ mod tests { fn test_init_with_frontend_template() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join(TEST_PROJECT_NAME); - let with_examples = vec![]; - let overwrite = false; - init( - project_dir.as_path(), - "https://github.com/stellar/soroban-astro-template", - &with_examples, - overwrite, - ) - .unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: "https://github.com/stellar/soroban-astro-template".to_owned(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); assert_base_template_files_exist(&project_dir); assert_default_hello_world_contract_files_exist(&project_dir); @@ -585,28 +651,33 @@ mod tests { fn test_init_with_overwrite() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join(TEST_PROJECT_NAME); - let with_examples = vec![]; // First initialization - init( - project_dir.as_path(), - "https://github.com/stellar/soroban-astro-template", - &with_examples, - false, - ) - .unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: "https://github.com/stellar/soroban-astro-template".to_owned(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); // Get initial modification times let initial_mod_times = get_mod_times(&project_dir); // Second initialization with overwrite - init( - project_dir.as_path(), - "https://github.com/stellar/soroban-astro-template", - &with_examples, - true, // overwrite = true - ) - .unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: "https://github.com/stellar/soroban-astro-template".to_owned(), + overwrite: true, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); // Get new modification times let new_mod_times = get_mod_times(&project_dir); @@ -641,15 +712,16 @@ mod tests { fn test_init_from_within_an_existing_project() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join("./"); - let with_examples = vec![]; - let overwrite = false; - init( - project_dir.as_path(), - "https://github.com/stellar/soroban-astro-template", - &with_examples, - overwrite, - ) - .unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: "https://github.com/stellar/soroban-astro-template".to_owned(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); assert_base_template_files_exist(&project_dir); assert_default_hello_world_contract_files_exist(&project_dir); @@ -673,24 +745,28 @@ mod tests { fn test_init_does_not_duplicate_frontend_readme_contents_when_run_more_than_once() { let temp_dir = tempfile::tempdir().unwrap(); let project_dir = temp_dir.path().join(TEST_PROJECT_NAME); - let with_examples = vec![]; - let overwrite = false; - init( - project_dir.as_path(), - "https://github.com/stellar/soroban-astro-template", - &with_examples, - overwrite, - ) - .unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: "https://github.com/stellar/soroban-astro-template".to_owned(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); // call init again to make sure the README.md's contents are not duplicated - init( - project_dir.as_path(), - "https://github.com/stellar/soroban-astro-template", - &with_examples, - overwrite, - ) - .unwrap(); + let runner = Runner { + args: Cmd { + project_path: project_dir.to_string_lossy().to_string(), + with_example: vec![], + frontend_template: "https://github.com/stellar/soroban-astro-template".to_owned(), + overwrite: false, + }, + print: print::Print::new(false), + }; + runner.run().unwrap(); assert_base_template_files_exist(&project_dir); assert_default_hello_world_contract_files_exist(&project_dir); @@ -737,7 +813,6 @@ mod tests { let cargo_toml_path = contract_dir.as_path().join("Cargo.toml"); let cargo_toml_str = read_to_string(cargo_toml_path.clone()).unwrap(); let doc = cargo_toml_str.parse::().unwrap(); - println!("{cargo_toml_path:?} contents:\n{cargo_toml_str}"); assert!( doc.get("dependencies") .unwrap() diff --git a/cmd/soroban-cli/src/commands/contract/mod.rs b/cmd/soroban-cli/src/commands/contract/mod.rs index 9d574335c..761784de9 100644 --- a/cmd/soroban-cli/src/commands/contract/mod.rs +++ b/cmd/soroban-cli/src/commands/contract/mod.rs @@ -146,7 +146,7 @@ impl Cmd { Cmd::Deploy(deploy) => deploy.run(global_args).await?, Cmd::Id(id) => id.run()?, Cmd::Info(info) => info.run().await?, - Cmd::Init(init) => init.run()?, + Cmd::Init(init) => init.run(global_args)?, Cmd::Inspect(inspect) => inspect.run()?, Cmd::Install(install) => install.run(global_args).await?, Cmd::Invoke(invoke) => invoke.run(global_args).await?, diff --git a/cmd/soroban-cli/src/print.rs b/cmd/soroban-cli/src/print.rs index ca95f652c..2afa5ec03 100644 --- a/cmd/soroban-cli/src/print.rs +++ b/cmd/soroban-cli/src/print.rs @@ -86,6 +86,7 @@ create_print_functions!(error, errorln, "❌"); create_print_functions!(globe, globeln, "🌎"); create_print_functions!(info, infoln, "ℹ️"); create_print_functions!(link, linkln, "🔗"); +create_print_functions!(plus, plusln, "➕"); create_print_functions!(save, saveln, "💾"); create_print_functions!(search, searchln, "🔎"); create_print_functions!(warn, warnln, "⚠️"); From 6e64987461558c66fb9304ef3aac62ff9910d8b9 Mon Sep 17 00:00:00 2001 From: Chad Ostrowski <221614+chadoh@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:30:06 -0400 Subject: [PATCH 2/3] fix: update snapshot fixtures (#1580) --- .../test_custom_types/dist/index.d.ts | 9 +- .../fixtures/test_custom_types/dist/index.js | 5 +- .../test_custom_types/package-lock.json | 87 +++++++------------ .../fixtures/test_custom_types/src/index.ts | 11 ++- 4 files changed, 47 insertions(+), 65 deletions(-) diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.d.ts b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.d.ts index 0b661d2c3..cd888cc04 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.d.ts +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.d.ts @@ -51,6 +51,9 @@ export type ComplexEnum = { values: void; }; export declare const Errors: { + /** + * Please provide an odd number + */ 1: { message: string; }; @@ -186,7 +189,7 @@ export interface Client { simulate?: boolean; }) => Promise>; /** - * Construct and simulate a strukt_hel transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * + * Construct and simulate a strukt_hel transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * Example contract method which takes a struct */ strukt_hel: ({ strukt }: { @@ -358,7 +361,7 @@ export interface Client { simulate?: boolean; }) => Promise>; /** - * Construct and simulate a not transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * + * Construct and simulate a not transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * Negates a boolean value */ not: ({ boolean }: { @@ -493,7 +496,7 @@ export interface Client { simulate?: boolean; }) => Promise>; /** - * Construct and simulate a option transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * + * Construct and simulate a option transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * Example of an optional argument */ option: ({ option }: { diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js index 5b9e067c9..4286b2a68 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js @@ -20,7 +20,10 @@ export var RoyalCard; RoyalCard[RoyalCard["King"] = 13] = "King"; })(RoyalCard || (RoyalCard = {})); export const Errors = { - 1: { message: "Please provide an odd number" } + /** + * Please provide an odd number + */ + 1: { message: "NumberMustBeOdd" } }; export class Client extends ContractClient { options; diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json index 11ad043be..dd6bb8673 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json @@ -17,13 +17,11 @@ }, "node_modules/@stellar/js-xdr": { "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@stellar/js-xdr/-/js-xdr-3.1.1.tgz", - "integrity": "sha512-3gnPjAz78htgqsNEDkEsKHKosV2BF2iZkoHCNxpmZwUxiPsw+2VaXMed8RRMe0rGk3d5GZe7RrSba8zV80J3Ag==" + "license": "Apache-2.0" }, "node_modules/@stellar/stellar-base": { "version": "12.0.1", - "resolved": "https://registry.npmjs.org/@stellar/stellar-base/-/stellar-base-12.0.1.tgz", - "integrity": "sha512-g6c27MNsDgEdUmoNQJn7zCWoCY50WHt0OIIOq3PhWaJRtUaT++qs1Jpb8+1bny2GmhtfRGOfPUFSyQBuHT9Mvg==", + "license": "Apache-2.0", "dependencies": { "@stellar/js-xdr": "^3.1.1", "base32.js": "^0.1.0", @@ -38,8 +36,7 @@ }, "node_modules/@stellar/stellar-sdk": { "version": "12.1.0", - "resolved": "https://registry.npmjs.org/@stellar/stellar-sdk/-/stellar-sdk-12.1.0.tgz", - "integrity": "sha512-Va0hu9SaPezmMbO5eMwL5D15Wrx1AGWRtxayUDRWV2Fr3ynY58mvCZS1vsgNQ4kE8MZe3nBVKv6T9Kzqwgx1PQ==", + "license": "Apache-2.0", "dependencies": { "@stellar/stellar-base": "^12.0.1", "axios": "^1.7.2", @@ -52,13 +49,11 @@ }, "node_modules/asynckit": { "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "license": "MIT" }, "node_modules/axios": { "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -67,16 +62,13 @@ }, "node_modules/base32.js": { "version": "0.1.0", - "resolved": "https://registry.npmjs.org/base32.js/-/base32.js-0.1.0.tgz", - "integrity": "sha512-n3TkB02ixgBOhTvANakDb4xaMXnYUVkNoRFJjQflcqMQhyEKxEHdj3E6N8t8sUQ0mjH/3/JxzlXuz3ul/J90pQ==", + "license": "MIT", "engines": { "node": ">=0.12.0" } }, "node_modules/base64-js": { "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "funding": [ { "type": "github", @@ -90,20 +82,18 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/bignumber.js": { "version": "9.1.2", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", - "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", + "license": "MIT", "engines": { "node": "*" } }, "node_modules/buffer": { "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", "funding": [ { "type": "github", @@ -118,6 +108,7 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" @@ -125,8 +116,7 @@ }, "node_modules/combined-stream": { "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" }, @@ -136,30 +126,27 @@ }, "node_modules/delayed-stream": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", "engines": { "node": ">=0.4.0" } }, "node_modules/eventsource": { "version": "2.0.2", - "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-2.0.2.tgz", - "integrity": "sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==", + "license": "MIT", "engines": { "node": ">=12.0.0" } }, "node_modules/follow-redirects": { "version": "1.15.6", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", - "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", "url": "https://github.com/sponsors/RubenVerborgh" } ], + "license": "MIT", "engines": { "node": ">=4.0" }, @@ -171,8 +158,7 @@ }, "node_modules/form-data": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -184,8 +170,6 @@ }, "node_modules/ieee754": { "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", "funding": [ { "type": "github", @@ -199,25 +183,23 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "BSD-3-Clause" }, "node_modules/inherits": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "license": "ISC" }, "node_modules/mime-db": { "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", "engines": { "node": ">= 0.6" } }, "node_modules/mime-types": { "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", "dependencies": { "mime-db": "1.52.0" }, @@ -227,8 +209,7 @@ }, "node_modules/node-gyp-build": { "version": "4.8.1", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", - "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", + "license": "MIT", "optional": true, "bin": { "node-gyp-build": "bin.js", @@ -238,21 +219,17 @@ }, "node_modules/proxy-from-env": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + "license": "MIT" }, "node_modules/randombytes": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", - "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "license": "MIT", "dependencies": { "safe-buffer": "^5.1.0" } }, "node_modules/safe-buffer": { "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "funding": [ { "type": "github", @@ -266,12 +243,12 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/sha.js": { "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", - "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "license": "(MIT AND BSD-3-Clause)", "dependencies": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -282,9 +259,8 @@ }, "node_modules/sodium-native": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-4.1.1.tgz", - "integrity": "sha512-LXkAfRd4FHtkQS4X6g+nRcVaN7mWVNepV06phIsC6+IZFvGh1voW5TNQiQp2twVaMf05gZqQjuS+uWLM6gHhNQ==", "hasInstallScript": true, + "license": "MIT", "optional": true, "dependencies": { "node-gyp-build": "^4.8.0" @@ -292,13 +268,11 @@ }, "node_modules/toml": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", - "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==" + "license": "MIT" }, "node_modules/tweetnacl": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "license": "Unlicense" }, "node_modules/typescript": { "version": "5.3.3", @@ -315,8 +289,7 @@ }, "node_modules/urijs": { "version": "1.19.11", - "resolved": "https://registry.npmjs.org/urijs/-/urijs-1.19.11.tgz", - "integrity": "sha512-HXgFDgDommxn5/bIv0cnQZsPhHDA90NPHD6+c/v21U5+Sx5hoP8+dP9IZXBU1gIfvdRfhG8cel9QNPeionfcCQ==" + "license": "MIT" } } } diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/src/index.ts b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/src/index.ts index b6ee3dbbc..7f2d5b000 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/src/index.ts +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/src/index.ts @@ -59,7 +59,10 @@ export type TupleStruct = readonly [Test, SimpleEnum]; export type ComplexEnum = {tag: "Struct", values: readonly [Test]} | {tag: "Tuple", values: readonly [TupleStruct]} | {tag: "Enum", values: readonly [SimpleEnum]} | {tag: "Asset", values: readonly [string, i128]} | {tag: "Void", values: void}; export const Errors = { - 1: {message:"Please provide an odd number"} + /** + * Please provide an odd number + */ + 1: {message:"NumberMustBeOdd"} } export interface Client { @@ -204,7 +207,7 @@ export interface Client { }) => Promise> /** - * Construct and simulate a strukt_hel transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * + * Construct and simulate a strukt_hel transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * Example contract method which takes a struct */ strukt_hel: ({strukt}: {strukt: Test}, options?: { @@ -385,7 +388,7 @@ export interface Client { }) => Promise> /** - * Construct and simulate a not transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * + * Construct and simulate a not transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * Negates a boolean value */ not: ({boolean}: {boolean: boolean}, options?: { @@ -526,7 +529,7 @@ export interface Client { }) => Promise> /** - * Construct and simulate a option transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * + * Construct and simulate a option transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. * Example of an optional argument */ option: ({option}: {option: Option}, options?: { From a0be0f7e82c806a6c4dd09d49fb8cdb4f8fbd29a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:01:16 -0400 Subject: [PATCH 3/3] build(deps): bump the npm_and_yarn group across 2 directories with 2 updates (#1581) --- .../test_custom_types/package-lock.json | 5 +++-- .../ts-tests/package-lock.json | 20 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json index dd6bb8673..f45484ffb 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json @@ -52,8 +52,9 @@ "license": "MIT" }, "node_modules/axios": { - "version": "1.7.2", - "license": "MIT", + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz", + "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json b/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json index 8e620a1a3..deee8f09d 100644 --- a/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json +++ b/cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json @@ -700,9 +700,9 @@ } }, "node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.5.tgz", + "integrity": "sha512-fZu86yCo+svH3uqJ/yTdQ0QHpQu5oL+/QE+QPSv6BZSkDAoky9vytxp7u5qk83OJFS3kEBcesWni9WTZAv3tSw==", "dev": true, "dependencies": { "follow-redirects": "^1.15.6", @@ -782,12 +782,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -1610,9 +1610,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1"