Skip to content

Commit 8c3b6f9

Browse files
committed
update doc
1 parent 92653b9 commit 8c3b6f9

File tree

4 files changed

+112
-37
lines changed

4 files changed

+112
-37
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ 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:
106106
cd devtools/doc/rpc-gen && cargo build
107107
cd docs/ckb_rpc_openrpc/ && git stash
108108
./target/debug/ckb-rpc-gen rpc/README.md

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ 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
@@ -40,13 +47,12 @@ fn checkout_tag_branch(tag: &str) {
4047

4148
fn dump_openrpc_json() -> Result<(), Box<dyn std::error::Error>> {
4249
let dir = "./docs/ckb_rpc_openrpc/json/";
43-
let tag = get_tag();
44-
checkout_tag_branch(&tag);
45-
50+
let version: String = get_version();
51+
checkout_tag_branch(&version);
4652
fs::create_dir_all(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)?;
5258
fs::write(dir.to_owned() + name, res)?;
@@ -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, 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)