Skip to content

Commit

Permalink
feat: add ts-rs mapping package
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 29, 2024
1 parent 0062fcc commit 002cac7
Show file tree
Hide file tree
Showing 334 changed files with 3,130 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"endOfLine": "lf"
"endOfLine": "auto"
}
35 changes: 35 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ tower = "0.4"
tower-http = { version = "0.3.5", default-features = false }
tower-layer = "0.3"
tracing = "0.1.40"
ts-rs = { version = "7.1", features = [
"chrono-impl",
"no-serde-warnings",
"indexmap-impl",
] }
url = "2.4.1"
wasmer = "2.3.0"
wasmer-middlewares = "2.3.0"
Expand Down
3 changes: 3 additions & 0 deletions applications/tari_dan_wallet_daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ ignored = [
# Want to enable some log4rs features
"log4rs",
]

[features]
ts = [] # this is just for the build script to skip the build
8 changes: 7 additions & 1 deletion applications/tari_dan_wallet_daemon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::process::Command;
use std::{env, process::Command};

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=../tari_dan_wallet_web_ui/src");
println!("cargo:rerun-if-changed=../tari_dan_wallet_web_ui/public");

if env::var_os("CARGO_FEATURE_TS").is_some() {
println!("cargo:warning=The web ui is not being compiled when we are generating typescript types/interfaces.");
return Ok(());
}

let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };

if let Err(error) = Command::new(npm)
Expand Down
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions applications/tari_indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ ignored = [
# Want to enable some log4rs features
"log4rs",
]

[features]
ts = [] # this is just for the build script to skip the build
8 changes: 7 additions & 1 deletion applications/tari_indexer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::process::Command;
use std::{env, process::Command};

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=../tari_indexer_web_ui/src");
println!("cargo:rerun-if-changed=../tari_indexer_web_ui/public");

if env::var_os("CARGO_FEATURE_TS").is_some() {
println!("cargo:warning=The web ui is not being compiled when we are generating typescript types/interfaces.");
return Ok(());
}

let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };

if let Err(error) = Command::new(npm)
Expand Down
3 changes: 2 additions & 1 deletion applications/tari_indexer_web_ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
/coverage

# production
/build
build/*
!build/.gitkeep

# misc
.DS_Store
Expand Down
Empty file.
Empty file.
7 changes: 6 additions & 1 deletion applications/tari_validator_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ minotari_app_utilities = { workspace = true }
minotari_wallet_grpc_client = { workspace = true }
tari_common = { workspace = true }
tari_common_types = { workspace = true }
tari_core = { workspace = true, default-features = false, features = ["transactions"] }
tari_core = { workspace = true, default-features = false, features = [
"transactions",
] }
tari_crypto = { workspace = true }
tari_validator_node_rpc = { workspace = true }
tari_dan_app_utilities = { workspace = true }
Expand Down Expand Up @@ -86,3 +88,6 @@ ignored = [
# Want to enable some log4rs features
"log4rs",
]

[features]
ts = [] # this is just for the build script to skip the build
8 changes: 7 additions & 1 deletion applications/tari_validator_node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::process::Command;
use std::{env, process::Command};

fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=../tari_validator_node_web_ui/src");
println!("cargo:rerun-if-changed=../tari_validator_node_web_ui/public");

if env::var_os("CARGO_FEATURE_TS").is_some() {
println!("cargo:warning=The web ui is not being compiled when we are generating typescript types/interfaces.");
return Ok(());
}

let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };

if let Err(error) = Command::new(npm)
Expand Down
Empty file.
Empty file.
31 changes: 31 additions & 0 deletions bindings/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cargo test --workspace --exclude integration_tests export_bindings --features ts
shx mv ../dan_layer/bindings/src/types/* ./src/types/
shx rm -rf ../dan_layer/bindings/
DIRECTORY_PATH="./src/types" # replace with your directory path
HELPERS_PATH="./src/helpers" # replace with your directory path
INDEX_FILE="./index.ts"

# Remove the index file if it exists
if [ -f "$INDEX_FILE" ]; then
rm "$INDEX_FILE"
fi

# Generate the index file
for file in $(find $DIRECTORY_PATH -name "*.ts"); do
FILE_NAME=$(basename $file)
if [ "$FILE_NAME" != "index.ts" ]; then
MODULE_NAME="${FILE_NAME%.*}"
echo "export * from '$DIRECTORY_PATH/$MODULE_NAME';" >> $INDEX_FILE
fi
done

# Add helpers
for file in $(find $HELPERS_PATH -name "*.ts"); do
FILE_NAME=$(basename $file)
if [ "$FILE_NAME" != "index.ts" ]; then
MODULE_NAME="${FILE_NAME%.*}"
echo "export * from '$HELPERS_PATH/$MODULE_NAME';" >> $INDEX_FILE
fi
done

npx prettier --write "./**/*.{ts,tsx,css,json}" --log-level=warn
Loading

0 comments on commit 002cac7

Please sign in to comment.