Skip to content

Commit

Permalink
Do not run npm commands but output instructions instead
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Nov 18, 2024
1 parent a8fdd5a commit dd6ae86
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use soroban_spec_tools::contract as contract_spec;
use soroban_spec_typescript::{self as typescript, boilerplate::Project};
use stellar_strkey::DecodeError;

use crate::print::Print;
use crate::wasm;
use crate::{
commands::{contract::fetch, global, NetworkRunnable},
Expand All @@ -13,6 +14,7 @@ use crate::{
network::{self, Network},
},
get_spec::{self, get_remote_contract_spec},
xdr::{Hash, ScAddress},
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -83,7 +85,9 @@ impl NetworkRunnable for Cmd {
global_args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<(), Error> {
let print = Print::new(global_args.is_some_and(|a| a.quiet));
let spec = if let Some(wasm) = &self.wasm {
print.infoln("Loading contract spec from file...");
let wasm: wasm::Args = wasm.into();
wasm.parse()?.spec
} else {
Expand All @@ -97,6 +101,8 @@ impl NetworkRunnable for Cmd {
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?
.0;

let contract_address = ScAddress::Contract(Hash(contract_id));
print.globeln(format!("Downloading contract spec: {contract_address}"));
get_remote_contract_spec(
&contract_id,
&self.locator,
Expand Down Expand Up @@ -129,31 +135,26 @@ impl NetworkRunnable for Cmd {
.expect("why did we remove the default futurenet network?")
.into()
});
print.infoln(format!("Network: {network_passphrase}"));
let absolute_path = self.output_dir.canonicalize()?;
let file_name = absolute_path
.file_name()
.ok_or_else(|| Error::FailedToGetFileName(absolute_path.clone()))?;
let contract_name = &file_name
.to_str()
.ok_or_else(|| Error::NotUtf8(file_name.to_os_string()))?;
print.infoln(format!("Embedding contract address: {}", self.contract_id));
p.init(
contract_name,
&self.contract_id,
&rpc_url,
&network_passphrase,
&spec,
)?;
std::process::Command::new("npm")
.arg("install")
.current_dir(&self.output_dir)
.spawn()?
.wait()?;
std::process::Command::new("npm")
.arg("run")
.arg("build")
.current_dir(&self.output_dir)
.spawn()?
.wait()?;
print.infoln(format!(
"Run \"npm install && npm run build\" in {:?} to build the JavaScript NPM package.",
self.output_dir
));
Ok(())
}
}
Expand Down

0 comments on commit dd6ae86

Please sign in to comment.