2022-07-12 07:02:38 +00:00
|
|
|
//! client client
|
|
|
|
//! NATS(c2se) NATS(c2se)
|
|
|
|
//! <---> <--->
|
|
|
|
//! client broker
|
|
|
|
//! <---> <--->
|
|
|
|
//! NATS(se2c) NATS(se2c)
|
|
|
|
//! server edge server edge
|
|
|
|
//! NATS(se) NATS(se)
|
|
|
|
//! <---> <--->
|
|
|
|
//! server service server broker server service
|
|
|
|
//! NATS(ss) <---> <---> NATS(ss)
|
|
|
|
//!
|
|
|
|
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use std::{collections::HashMap, fs, path::Path, process::Command};
|
|
|
|
|
|
|
|
static PROTO_PATHS: Lazy<Vec<&str>> =
|
|
|
|
Lazy::new(|| vec!["/usr/local/include/protobuf/", "./proto/"]);
|
|
|
|
|
|
|
|
static TARGETS: Lazy<HashMap<&str, Vec<&str>>> = Lazy::new(|| {
|
|
|
|
println!("initializing");
|
|
|
|
let mut m = HashMap::new();
|
|
|
|
|
|
|
|
m.insert(
|
|
|
|
"protobuf",
|
|
|
|
vec![
|
|
|
|
"./proto/protobuf/rpc/error.proto",
|
|
|
|
"./proto/protobuf/pagination/pagination.proto",
|
|
|
|
"./proto/protobuf/pagination/search.proto",
|
|
|
|
"./proto/protobuf/pagination/sort.proto",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
m.insert(
|
|
|
|
"models",
|
|
|
|
vec![
|
2022-07-15 06:14:09 +00:00
|
|
|
"./proto/models/core/network.proto",
|
2022-08-08 01:46:20 +00:00
|
|
|
"./proto/models/domain/site.proto",
|
|
|
|
"./proto/models/rbac/resource.proto",
|
|
|
|
"./proto/models/rbac/resource_action.proto",
|
|
|
|
"./proto/models/rbac/role.proto",
|
2022-07-12 07:02:38 +00:00
|
|
|
"./proto/models/member/member_class.proto",
|
|
|
|
"./proto/models/member/member_level.proto",
|
|
|
|
"./proto/models/member/member.proto",
|
2022-07-27 06:45:53 +00:00
|
|
|
"./proto/models/member/member_session.proto",
|
2022-07-12 07:02:38 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
m.insert(
|
|
|
|
"c2se",
|
|
|
|
vec![
|
2022-07-27 06:45:53 +00:00
|
|
|
"./proto/c2se/core/network.proto",
|
|
|
|
"./proto/c2se/common/identity.proto",
|
2022-07-12 07:02:38 +00:00
|
|
|
"./proto/c2se/backend/identity.proto",
|
|
|
|
"./proto/c2se/backend/member.proto",
|
|
|
|
"./proto/c2se/frontend/identity.proto",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2022-07-15 06:14:09 +00:00
|
|
|
m.insert("ss", vec!["./proto/ss/member/identity.proto"]);
|
|
|
|
|
2022-07-12 07:02:38 +00:00
|
|
|
m
|
|
|
|
});
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let build_path = "./build";
|
|
|
|
if Path::new(build_path).exists() {
|
|
|
|
fs::remove_dir_all(build_path).expect("clean for library directory is failed");
|
|
|
|
}
|
|
|
|
fs::create_dir_all(build_path).expect("creating for library directory is failed");
|
|
|
|
|
|
|
|
let build_path_rust = format!("{}/rust", build_path);
|
|
|
|
if Path::new(&build_path_rust).exists() {
|
|
|
|
fs::remove_dir_all(&build_path_rust).expect("clean for rust library directory is failed");
|
|
|
|
}
|
|
|
|
fs::create_dir_all(&build_path_rust).expect("creating for rust library directory is failed");
|
|
|
|
|
|
|
|
let build_path_javascript = format!("{}/javascript", build_path);
|
|
|
|
if Path::new(&build_path_javascript).exists() {
|
|
|
|
fs::remove_dir_all(&build_path_javascript)
|
|
|
|
.expect("clean for javascript library directory is failed");
|
|
|
|
}
|
|
|
|
fs::create_dir_all(&build_path_javascript)
|
|
|
|
.expect("creating for javascript library directory is failed");
|
|
|
|
|
|
|
|
let proto_paths: Vec<_> = PROTO_PATHS
|
|
|
|
.iter()
|
|
|
|
.map(|v| format!("--proto_path={}", *v))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
eprintln!("proto_paths: {:?}", proto_paths);
|
|
|
|
|
|
|
|
for (key, protos) in TARGETS.iter() {
|
|
|
|
let build_path_rust_sub = format!("{}/{}", &build_path_rust, key);
|
|
|
|
fs::create_dir_all(&build_path_rust_sub)
|
|
|
|
.expect("creating for rust library sub directory is failed");
|
|
|
|
|
|
|
|
let mut prost_build = prost_build::Config::new();
|
|
|
|
prost_build.out_dir(build_path_rust_sub);
|
|
|
|
prost_build
|
|
|
|
.compile_protos(protos.as_slice(), PROTO_PATHS.as_slice())
|
|
|
|
.expect("generating library for rust is failed");
|
|
|
|
|
|
|
|
let output = Command::new("protoc")
|
|
|
|
.args(proto_paths.as_slice())
|
|
|
|
.args(["--experimental_allow_proto3_optional"])
|
|
|
|
.args(&[
|
|
|
|
&format!(
|
|
|
|
"--js_out=import_style=commonjs,binary:{}",
|
|
|
|
&build_path_javascript
|
|
|
|
),
|
|
|
|
&format!("--ts_out={}", &build_path_javascript),
|
|
|
|
])
|
|
|
|
.args(protos.as_slice())
|
|
|
|
.output()
|
|
|
|
.expect("generating library for javascript is failed");
|
|
|
|
eprintln!(
|
|
|
|
"generating library for javascript status: {}",
|
|
|
|
output.status.success()
|
|
|
|
);
|
|
|
|
|
|
|
|
eprintln!(
|
|
|
|
"generating library for typescript stdout: {}",
|
|
|
|
String::from_utf8_lossy(&output.stdout)
|
|
|
|
);
|
|
|
|
eprintln!(
|
|
|
|
"generating library for typescript stderr: {}",
|
|
|
|
String::from_utf8_lossy(&output.stderr)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|