Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 28eca30

Browse files
committed
feat: test build.rs
Signed-off-by: Jawad Tariq <[email protected]>
1 parent b469dfe commit 28eca30

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

build.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::process::Command;
2+
3+
const CONTRACTS_PATH: &str = "./contracts";
4+
5+
fn main() {
6+
compile_contracts();
7+
}
8+
9+
fn compile_contracts() {
10+
if !CONTRACTS_PATH.is_empty() {
11+
if let Err(err) = std::env::set_current_dir(CONTRACTS_PATH) {
12+
eprintln!("Error changing to subdirectory: {}", err);
13+
return;
14+
}
15+
}
16+
17+
let install_result = Command::new("npm").arg("ci").status();
18+
19+
match install_result {
20+
Ok(status) => {
21+
if status.success() {
22+
println!(
23+
"npm dependencies installed successfully in {}!",
24+
CONTRACTS_PATH
25+
);
26+
} else {
27+
eprintln!(
28+
"Error installing npm dependencies in {}: {:?}",
29+
CONTRACTS_PATH, status
30+
);
31+
}
32+
}
33+
Err(err) => {
34+
eprintln!("Error executing npm ci: {}", err);
35+
}
36+
}
37+
38+
let compile_result = Command::new("npm").arg("run").arg("build").status();
39+
40+
match compile_result {
41+
Ok(status) => {
42+
if status.success() {
43+
println!("Artifacts compiled successfully in {}!", CONTRACTS_PATH);
44+
} else {
45+
eprintln!(
46+
"Error compiling artifacts in {}: {:?}",
47+
CONTRACTS_PATH, status
48+
);
49+
}
50+
}
51+
Err(err) => {
52+
eprintln!("Error executing npm run build: {}", err);
53+
}
54+
}
55+
56+
if let Err(err) = std::env::set_current_dir("..") {
57+
eprintln!("Error changing back to the original directory: {}", err);
58+
}
59+
60+
// println!("cargo:rerun-if-changed={}", CONTRACTS_PATH);
61+
}

0 commit comments

Comments
 (0)