docs: add initial package & modify build script

This commit is contained in:
hosted-fornet 2024-08-09 17:03:18 -07:00
parent 2b2b1ecc03
commit 118c12e985
12 changed files with 3470 additions and 11 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ kinode/packages/app_store/pkg/ui/*
kinode/packages/homepage/pkg/ui/* kinode/packages/homepage/pkg/ui/*
kinode/src/register-ui/build/ kinode/src/register-ui/build/
kinode/src/register-ui/dist/ kinode/src/register-ui/dist/
kinode/packages/docs/pkg/ui

73
Cargo.lock generated
View File

@ -2239,6 +2239,18 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
[[package]]
name = "filetime"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf401df4a4e3872c4fe8151134cf483738e74b67fc934d6532c882b3d24a4550"
dependencies = [
"cfg-if",
"libc",
"libredox",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "fixed-hash" name = "fixed-hash"
version = "0.8.0" version = "0.8.0"
@ -3240,13 +3252,14 @@ dependencies = [
"clap", "clap",
"crossterm", "crossterm",
"dashmap", "dashmap",
"flate2",
"futures", "futures",
"generic-array", "generic-array",
"hex", "hex",
"hmac", "hmac",
"http 1.1.0", "http 1.1.0",
"jwt", "jwt",
"kit", "kit 0.6.10",
"lazy_static", "lazy_static",
"lib", "lib",
"nohash-hasher", "nohash-hasher",
@ -3266,6 +3279,7 @@ dependencies = [
"snow", "snow",
"socket2 0.5.7", "socket2 0.5.7",
"static_dir", "static_dir",
"tar",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-tungstenite 0.21.0", "tokio-tungstenite 0.21.0",
@ -3362,6 +3376,38 @@ dependencies = [
"zip 0.6.6", "zip 0.6.6",
] ]
[[package]]
name = "kit"
version = "0.6.10"
source = "git+https://github.com/kinode-dao/kit?tag=v0.6.10#9e9f87b399109b824d99475584dd249eda2c1906"
dependencies = [
"anyhow",
"base64 0.21.7",
"clap",
"color-eyre",
"dirs 5.0.1",
"fs-err",
"git2",
"hex",
"kinode_process_lib 0.8.0",
"nix",
"regex",
"reqwest 0.11.27",
"semver 1.0.23",
"serde",
"serde_json",
"sha2",
"tokio",
"toml",
"tracing",
"tracing-appender",
"tracing-error",
"tracing-subscriber",
"walkdir",
"wit-bindgen",
"zip 0.6.6",
]
[[package]] [[package]]
name = "kns_indexer" name = "kns_indexer"
version = "0.2.0" version = "0.2.0"
@ -3401,7 +3447,7 @@ name = "lib"
version = "0.9.0" version = "0.9.0"
dependencies = [ dependencies = [
"alloy", "alloy",
"kit", "kit 0.6.8",
"lazy_static", "lazy_static",
"rand 0.8.5", "rand 0.8.5",
"ring", "ring",
@ -3457,6 +3503,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"libc", "libc",
"redox_syscall",
] ]
[[package]] [[package]]
@ -5460,6 +5507,17 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "tar"
version = "0.4.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb797dad5fb5b76fcf519e702f4a589483b5ef06567f160c392832c1f5e44909"
dependencies = [
"filetime",
"libc",
"xattr",
]
[[package]] [[package]]
name = "target-lexicon" name = "target-lexicon"
version = "0.12.16" version = "0.12.16"
@ -7207,6 +7265,17 @@ dependencies = [
"tap", "tap",
] ]
[[package]]
name = "xattr"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f"
dependencies = [
"libc",
"linux-raw-sys",
"rustix",
]
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.7.35" version = "0.7.35"

View File

@ -14,7 +14,9 @@ path = "src/main.rs"
[build-dependencies] [build-dependencies]
anyhow = "1.0.71" anyhow = "1.0.71"
kit = { git = "https://github.com/kinode-dao/kit", tag = "v0.6.8" } flate2 = "1.0"
kit = { git = "https://github.com/kinode-dao/kit", tag = "v0.6.10" }
tar = "0.4"
tokio = "1.28" tokio = "1.28"
walkdir = "2.4" walkdir = "2.4"
zip = "0.6" zip = "0.6"

View File

@ -1,9 +1,12 @@
use std::{ use std::{
collections::HashSet, collections::HashSet,
fs::{self, File}, fs::{self, File},
io::{Cursor, Read, Write}, io::{BufReader, Cursor, Read, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use flate2::read::GzDecoder;
use tar::Archive;
use zip::write::FileOptions; use zip::write::FileOptions;
fn get_features() -> String { fn get_features() -> String {
@ -44,6 +47,53 @@ fn output_reruns(dir: &Path, rerun_files: &HashSet<String>) {
} }
} }
fn untar_gz_file(path: &Path, dest: &Path) -> std::io::Result<()> {
// Open the .tar.gz file
let tar_gz = File::open(path)?;
let tar_gz_reader = BufReader::new(tar_gz);
// Decode the gzip layer
let tar = GzDecoder::new(tar_gz_reader);
// Create a new archive from the tar file
let mut archive = Archive::new(tar);
// Unpack the archive into the specified destination directory
archive.unpack(dest)?;
Ok(())
}
fn get_kinode_book(packages_dir: &Path) -> anyhow::Result<()> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let releases = kit::boot_fake_node::fetch_releases("kinode-dao", "kinode-book")
.await
.map_err(|e| anyhow::anyhow!("{e:?}"))?;
if releases.is_empty() {
return Err(anyhow::anyhow!("couldn't retrieve kinode-book releases"));
}
let release = &releases[0];
if release.assets.is_empty() {
return Err(anyhow::anyhow!("most recent kinode-book release has no assets"));
}
let release_url = format!(
"https://github.com/kinode-dao/kinode-book/releases/download/{}/{}",
release.tag_name,
release.assets[0].name,
);
let book_dir = packages_dir.join("docs").join("pkg").join("ui");
fs::create_dir_all(&book_dir)?;
let book_tar_path = book_dir.join("book.tar.gz");
kit::build::download_file(&release_url, &book_tar_path)
.await
.map_err(|e| anyhow::anyhow!("{e:?}"))?;
untar_gz_file(&book_tar_path, &book_dir)?;
fs::remove_file(book_tar_path)?;
Ok(())
})
}
fn build_and_zip_package( fn build_and_zip_package(
entry_path: PathBuf, entry_path: PathBuf,
parent_pkg_path: &str, parent_pkg_path: &str,
@ -60,7 +110,11 @@ fn build_and_zip_package(
None, None,
None, None,
None, None,
true, vec![],
vec![],
false,
false,
false,
) )
.await .await
.map_err(|e| anyhow::anyhow!("{:?}", e))?; .map_err(|e| anyhow::anyhow!("{:?}", e))?;
@ -129,9 +183,7 @@ fn main() -> anyhow::Result<()> {
} }
} }
let entries: Vec<_> = fs::read_dir(packages_dir)? get_kinode_book(&packages_dir)?;
.map(|entry| entry.unwrap().path())
.collect();
let rerun_files: HashSet<String> = HashSet::from([ let rerun_files: HashSet<String> = HashSet::from([
"Cargo.lock".to_string(), "Cargo.lock".to_string(),
@ -142,9 +194,12 @@ fn main() -> anyhow::Result<()> {
let features = get_features(); let features = get_features();
let results: Vec<anyhow::Result<(String, String, Vec<u8>)>> = entries let results: Vec<anyhow::Result<(String, String, Vec<u8>)>> = fs::read_dir(&packages_dir)?
.iter() .filter_map(|entry| {
.filter_map(|entry_path| { let entry_path = match entry {
Ok(e) => e.path(),
Err(_) => return None,
};
let parent_pkg_path = entry_path.join("pkg"); let parent_pkg_path = entry_path.join("pkg");
if !parent_pkg_path.exists() { if !parent_pkg_path.exists() {
// don't run on, e.g., `.DS_Store` // don't run on, e.g., `.DS_Store`

8
kinode/packages/docs/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
*/target/
/target
pkg/*.wasm
*.swp
*.swo
*/wasi_snapshot_preview1.wasm
*/wit/
*/process_env

3227
kinode/packages/docs/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
[workspace]
resolver = "2"
members = [
"docs",
]
[profile.release]
panic = "abort"
opt-level = "s"
lto = true

View File

@ -0,0 +1,18 @@
[package]
name = "docs"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "db4a6c1" }
process_macros = { git = "https://github.com/kinode-dao/process_macros", rev = "626e501" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.24.0"
[lib]
crate-type = ["cdylib"]
[package.metadata.component]
package = "kinode:process"

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,32 @@
use kinode_process_lib::{
await_message, call_init,
homepage::add_to_homepage,
http::server::{HttpBindingConfig, HttpServer},
println, Address,
};
wit_bindgen::generate!({
path: "target/wit",
world: "process-v0",
});
const ICON: &str = include_str!("icon");
call_init!(init);
fn init(our: Address) {
println!("begin");
let mut server = HttpServer::new(5);
server
.serve_ui(&our, "ui", vec!["/"], HttpBindingConfig::default())
.unwrap();
add_to_homepage("Docs", Some(ICON), Some("index.html"), None);
loop {
match await_message() {
Err(send_error) => println!("got SendError: {send_error}"),
Ok(ref _message) => println!("got message"),
}
}
}

View File

@ -0,0 +1,18 @@
{
"name": "docs",
"description": "",
"image": "",
"properties": {
"package_name": "docs",
"current_version": "0.1.0",
"publisher": "sys",
"mirrors": [],
"code_hashes": {
"0.1.0": ""
},
"wit_version": 0,
"dependencies": []
},
"external_url": "",
"animation_url": ""
}

View File

@ -0,0 +1,18 @@
[
{
"process_name": "docs",
"process_wasm_path": "/docs.wasm",
"on_exit": "Restart",
"request_networking": false,
"request_capabilities": [
"homepage:homepage:sys",
"http_server:distro:sys",
"vfs:distro:sys"
],
"grant_capabilities": [
"http_server:distro:sys",
"vfs:distro:sys"
],
"public": false
}
]