Skip to content

Commit 19a684c

Browse files
committed
update doc
1 parent 92653b9 commit 19a684c

File tree

4 files changed

+120
-45
lines changed

4 files changed

+120
-45
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ doc-deps: ## Build the documentation for the local package and all dependencies.
102102
cargo doc --workspace
103103

104104
.PHONY: gen-rpc-doc
105-
gen-rpc-doc: submodule-init ## Generate rpc documentation
105+
gen-rpc-doc: submodule-init ## Generate rpc documentation
106106
cd devtools/doc/rpc-gen && cargo build
107-
cd docs/ckb_rpc_openrpc/ && git stash
107+
cd docs/ckb_rpc_openrpc/ && git reset --hard && git clean -fd
108108
./target/debug/ckb-rpc-gen rpc/README.md
109109
./target/debug/ckb-rpc-gen --json
110110

devtools/doc/rpc-gen/src/main.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod gen;
33
use crate::gen::RpcDocGenerator;
44
use ckb_rpc::module::*;
55
use serde_json::json;
6-
use std::fs;
6+
use std::{fs, path::PathBuf};
77

88
const OPENRPC_DIR: &str = "./docs/ckb_rpc_openrpc/";
99

@@ -21,35 +21,41 @@ fn run_command(prog: &str, args: &[&str], dir: Option<&str>) -> Option<String> {
2121
})
2222
}
2323

24-
fn get_tag() -> String {
25-
run_command("git", &["describe", "--tags", "--abbrev=0"], None).unwrap_or("main".to_owned())
24+
fn get_version() -> String {
25+
let version = run_command("cargo", &["pkgid"], None)
26+
.unwrap()
27+
.split('#')
28+
.nth(1)
29+
.unwrap_or("0.0.0")
30+
.to_owned();
31+
eprintln!("version: {:?}", version);
32+
return version;
2633
}
2734

2835
/// Get git tag from command line
2936
fn get_commit_sha() -> String {
3037
run_command("git", &["rev-parse", "HEAD"], Some(OPENRPC_DIR)).unwrap_or("main".to_string())
3138
}
3239

33-
fn checkout_tag_branch(tag: &str) {
40+
fn checkout_tag_branch(version: &str) {
3441
let dir = Some(OPENRPC_DIR);
35-
let res = run_command("git", &["checkout", tag], dir);
42+
let res = run_command("git", &["checkout", version], dir);
3643
if res.is_none() {
37-
run_command("git", &["checkout", "-b", tag], dir);
44+
run_command("git", &["checkout", "-b", version], dir);
3845
}
3946
}
4047

4148
fn dump_openrpc_json() -> Result<(), Box<dyn std::error::Error>> {
42-
let dir = "./docs/ckb_rpc_openrpc/json/";
43-
let tag = get_tag();
44-
checkout_tag_branch(&tag);
45-
46-
fs::create_dir_all(dir)?;
49+
let json_dir = PathBuf::from(OPENRPC_DIR).join("json");
50+
let version: String = get_version();
51+
checkout_tag_branch(&version);
52+
fs::create_dir_all(&json_dir)?;
4753
let dump =
4854
|name: &str, doc: &mut serde_json::Value| -> Result<(), Box<dyn std::error::Error>> {
49-
doc["info"]["version"] = serde_json::Value::String(tag.clone());
55+
doc["info"]["version"] = serde_json::Value::String(version.clone());
5056
let obj = json!(doc);
5157
let res = serde_json::to_string_pretty(&obj)?;
52-
fs::write(dir.to_owned() + name, res)?;
58+
fs::write(json_dir.join(name), res)?;
5359
Ok(())
5460
};
5561
dump("alert_rpc_doc.json", &mut alert_rpc_doc())?;
@@ -68,7 +74,7 @@ fn dump_openrpc_json() -> Result<(), Box<dyn std::error::Error>> {
6874
dump("experiment_rpc_doc.json", &mut experiment_rpc_doc())?;
6975
eprintln!(
7076
"finished dump openrpc json for tag: {:?} at dir: {:?}",
71-
tag, dir
77+
version, json_dir
7278
);
7379
Ok(())
7480
}
@@ -89,8 +95,8 @@ pub fn gen_rpc_readme(readme_path: &str) -> Result<(), Box<dyn std::error::Error
8995
experiment_rpc_doc(),
9096
];
9197

92-
let tag = get_commit_sha();
93-
let generator = RpcDocGenerator::new(&all_rpc, readme_path.to_owned(), tag);
98+
let commit_sha = get_commit_sha();
99+
let generator = RpcDocGenerator::new(&all_rpc, readme_path.to_owned(), commit_sha);
94100
fs::write(readme_path, generator.gen_markdown())?;
95101

96102
Ok(())

0 commit comments

Comments
 (0)