Skip to content

Commit

Permalink
fix(bindings-ts): don't delete existing dirs (#733)
Browse files Browse the repository at this point in the history
* fix(bindings-ts): don't delete existing dirs

- Rename `root-dir` to `output-dir` to clarify the intent
- If `output-dir` already exists, use `output-dir/contract-name` instead

* docs: update auto-generated
  • Loading branch information
chadoh authored Jun 30, 2023
1 parent 30270fc commit f622b8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Cmd {

/// where to place generated project
#[arg(long)]
root_dir: PathBuf,
output_dir: PathBuf,

#[arg(long)]
contract_name: String,
Expand Down Expand Up @@ -52,14 +52,16 @@ pub enum Error {
impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let spec = self.wasm.parse().unwrap().spec;
if self.root_dir.is_file() {
return Err(Error::IsFile(self.root_dir.clone()));
if self.output_dir.is_file() {
return Err(Error::IsFile(self.output_dir.clone()));
}
if self.root_dir.exists() {
std::fs::remove_dir_all(&self.root_dir)?;
}
std::fs::create_dir_all(&self.root_dir)?;
let p: Project = self.root_dir.clone().try_into()?;
let output_dir = if self.output_dir.exists() {
self.output_dir.join(&self.contract_name)
} else {
self.output_dir.clone()
};
std::fs::create_dir_all(&output_dir)?;
let p: Project = output_dir.clone().try_into()?;
let Network {
rpc_url,
network_passphrase,
Expand All @@ -76,13 +78,13 @@ impl Cmd {
)?;
std::process::Command::new("npm")
.arg("install")
.current_dir(&self.root_dir)
.current_dir(&output_dir)
.spawn()?
.wait()?;
std::process::Command::new("npm")
.arg("run")
.arg("build")
.current_dir(&self.root_dir)
.current_dir(&output_dir)
.spawn()?
.wait()?;
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ Generate Rust bindings

Generate a TypeScript / JavaScript package

**Usage:** `soroban contract bindings typescript [OPTIONS] --wasm <WASM> --root-dir <ROOT_DIR> --contract-name <CONTRACT_NAME> --contract-id <CONTRACT_ID>`
**Usage:** `soroban contract bindings typescript [OPTIONS] --wasm <WASM> --output-dir <OUTPUT_DIR> --contract-name <CONTRACT_NAME> --contract-id <CONTRACT_ID>`

###### **Options:**

* `--wasm <WASM>` — Path to wasm binary
* `--root-dir <ROOT_DIR>` — where to place generated project
* `--output-dir <OUTPUT_DIR>` — where to place generated project
* `--contract-name <CONTRACT_NAME>`
* `--contract-id <CONTRACT_ID>`
* `--global` — Use global config
Expand Down

0 comments on commit f622b8e

Please sign in to comment.