← Commit history

2.47.11: export-viewers renders from --sym/--fp or a signed wiki read (#40); GH c665edc

Colby Knox ·b1b13c47b4 · ·parent 2e6db2a
9 files changed +87−15
CHANGELOG.md+3
@@ -1,5 +1,8 @@ # Changelog +## 2.47.11 (2026-11-13)+- `export-viewers` can render a page before it is public. `--sym <file.kicad_sym> --fp <file.kicad_mod>` renders from local files instead of the wiki, with the same output. Reads from the wiki now carry your token (`ADOM_WIKI_TOKEN`, else the adom-wiki CLI's stored token, else the container key), so `--slug` works on a private page you can see. A page it cannot read now says so, instead of reporting no KiCad files. (#40)+ ## 2.47.10 (2026-11-10) - `generate` keeps a prime in a pin name. `QH'` used to lose its prime, collide with `QH`, and come out as `QH@2`, which EAGLE and Fusion read as a second pad of `QH`, so the 74HC595's serial output was labelled QH. A prime that ends a name or a word (`'`, `ʼ`, `′`, `’`) now becomes `_P`: `QH'` is `QH_P`, `1ʼ` is `1_P`. An apostrophe inside a word, as in `X'tal`, is unchanged. When two different pin names still end up as one EAGLE name, `generate` prints `WARN: [pin-name-collision]`. (#38) - The symbol viewer draws KiCad overbars: `~{1R}` shows as 1R with a bar over it instead of the markup. The viewer and Manager tooltips do the same. `data-name` keeps the raw name. (#39)
Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-lbr"-version = "2.47.10"+version = "2.47.11" dependencies = [  "altium-codec",  "anyhow",
Cargo.toml+1−1
@@ -1,6 +1,6 @@ [package] name = "adom-lbr"-version = "2.47.10"+version = "2.47.11" edition = "2021" description = "adom-lbr generator / EDA translator: the canonical adom-lbr JSON is the hub, with native converters to Altium (.SchLib/.PcbLib/.IntLib), EAGLE/Fusion (.lbr), and KiCad. Altium output is written natively — no Altium needed at conversion time." 
VERSION+1−1
@@ -1 +1 @@-2.47.10+2.47.11
bin/adom-lbr
⋯ 1 unchanged line ⋯
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.10",+  "version": "2.47.11",   "type": "app",   "description": "adom-lbr \u2014 the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad \u21c4 Altium \u21c4 EAGLE/Fusion) through one canonical adom-lbr JSON \u2014 symbol + footprint + 3D + pin\u2194pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},
page.json+2−2
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.10",+  "version": "2.47.11",   "type": "app",   "description": "adom-lbr — the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad ⇄ Altium ⇄ EAGLE/Fusion) through one canonical adom-lbr JSON — symbol + footprint + 3D + pin↔pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},@@ -89,4 +89,4 @@       "label": "Browse parts"     }   ]-}\ No newline at end of file+}
src/main.rs+10−2
@@ -205,6 +205,13 @@ enum Commands {         /// own pin table, e.g. a rich readme datasheet table, to avoid duplication)         #[arg(long)]         no_pin_table: bool,+        /// Render from this local .kicad_sym instead of the wiki page (with --fp), so a+        /// page's viewers can be built before it goes public+        #[arg(long, requires = "fp")]+        sym: Option<PathBuf>,+        /// The local .kicad_mod that goes with --sym+        #[arg(long, requires = "sym")]+        fp: Option<PathBuf>,     },     /// Export ONE configurable, cross-linked viewer combining symbol + footprint +     /// 3D + pin-map in a declared layout (columns | quad | single). Which panes and@@ -3984,9 +3991,10 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or             }         } -        Commands::ExportViewers { slug, dir, out, no_pin_table } => {+        Commands::ExportViewers { slug, dir, out, no_pin_table, sym, fp } => {             let out_dir = out.unwrap_or_else(|| PathBuf::from("viewers"));-            if let Err(e) = manage::export_viewers(&slug, &dir, &out_dir, no_pin_table) {+            let local = sym.as_deref().zip(fp.as_deref());+            if let Err(e) = manage::export_viewers(&slug, &dir, &out_dir, no_pin_table, local) {                 eprintln!("ERROR: {e}"); std::process::exit(1);             }         }
src/manage.rs+68−7
@@ -314,12 +314,45 @@ fn curl(url: &str) -> Option<Vec<u8>> {     } } +/// The caller's wiki token, from the same places the adom-wiki CLI reads it:+/// ADOM_WIKI_TOKEN, the CLI's stored token, then the container key.+fn wiki_token() -> Option<String> {+    let from_file = |p: std::path::PathBuf| std::fs::read_to_string(p).ok();+    std::env::var("ADOM_WIKI_TOKEN").ok()+        .or_else(|| std::env::var("HOME").ok().and_then(|h| from_file(std::path::Path::new(&h).join(".config/adom-wiki/token"))))+        .or_else(|| from_file("/var/run/adom/api-key".into()))+        .map(|t| t.trim().to_string())+        .filter(|t| !t.is_empty() && !t.contains(['\r', '\n']))+}++/// A signed read of one wiki URL, so a private page the caller can see renders+/// like a public one. The token goes to curl on stdin (`-H @-`), never on the+/// command line where `ps` would show it. `-f` turns a 403/404 into None rather+/// than handing the error body back as if it were the file.+fn wiki_get(url: &str) -> Option<Vec<u8>> {+    use std::io::Write;+    let token = wiki_token();+    let mut cmd = Command::new("curl");+    cmd.args(["-s", "-f", "-L", "--max-time", "20"]);+    if token.is_some() { cmd.args(["-H", "@-"]); }+    let mut child = cmd.arg(url)+        .stdin(std::process::Stdio::piped())+        .stdout(std::process::Stdio::piped())+        .stderr(std::process::Stdio::null())+        .spawn().ok()?;+    if let (Some(t), Some(mut stdin)) = (token, child.stdin.take()) {+        let _ = writeln!(stdin, "Authorization: Bearer {t}");+    }+    let out = child.wait_with_output().ok()?;+    (out.status.success() && !out.stdout.is_empty()).then_some(out.stdout)+}+ fn wiki_text(slug: &str, file: &str) -> Option<String> {     let url = format!("{WIKI}/api/v1/pages/{slug}/files/{file}");-    curl(&url).map(|b| String::from_utf8_lossy(&b).to_string())+    wiki_get(&url).map(|b| String::from_utf8_lossy(&b).to_string()) } fn wiki_bytes(slug: &str, file: &str) -> Option<Vec<u8>> {-    curl(&format!("{WIKI}/api/v1/pages/{slug}/files/{file}"))+    wiki_get(&format!("{WIKI}/api/v1/pages/{slug}/files/{file}")) }  /// Uppercase-MPN filename stem for a slug (files are named `<MPN>.ext`).@@ -452,7 +485,7 @@ fn board_deps(slug: &str) -> Value { /// List the file names on a page (robust to any MPN→filename convention — the /// slug can't be uppercased to the filename when the MPN has `/`, `.`, etc.). fn list_page_files(slug: &str) -> Vec<String> {-    let body = match curl(&format!("{WIKI}/api/v1/pages/{slug}/files")) {+    let body = match wiki_get(&format!("{WIKI}/api/v1/pages/{slug}/files")) {         Some(b) => b,         None => return vec![],     };@@ -493,6 +526,7 @@ fn load_part(slug: &str, _mpn: &str) -> Result<(AdomLbrPart, &'static str), Stri         (Some(s), Some(m)) => altium_codec::import_kicad(&s, &m, &up(slug))             .map(|p| (p, "kicad (generated)"))             .map_err(|e| e.to_string()),+        _ if files.is_empty() => Err(format!("could not read {slug} from the wiki: it does not exist, or it is private and no token reached it (set ADOM_WIKI_TOKEN, or render from local files with --sym and --fp)")),         _ => Err(format!("no adom-lbr JSON or KiCad files on {slug}")),     } }@@ -1464,12 +1498,21 @@ fn viewer_bundle_offline() -> Result<String, String> {     }) } -pub fn export_viewers(slug: &str, dir: &std::path::Path, out_dir: &std::path::Path, no_pin_table: bool) -> Result<(), String> {+pub fn export_viewers(slug: &str, dir: &std::path::Path, out_dir: &std::path::Path, no_pin_table: bool,+                      local: Option<(&std::path::Path, &std::path::Path)>) -> Result<(), String> {     let mpn = up(slug);-    // Prefer the canonical local hub (<MPN>.adom-lbr.json in --dir); fall back to-    // fetching + importing the wiki page's CAD by slug.+    // Where the CAD comes from, first match wins: local KiCad files (--sym/--fp), so+    // a page can be rendered before it is public; the canonical local hub+    // (<MPN>.adom-lbr.json in --dir); else the wiki page, read with the caller's token.     let hub = dir.join(format!("{mpn}.adom-lbr.json"));-    let part = if hub.exists() { crate::load_part(&hub) } else { load_part(slug, &mpn)?.0 };+    let part = if let Some((sym, fp)) = local {+        let read = |p: &std::path::Path| std::fs::read_to_string(p).map_err(|e| format!("read {}: {e}", p.display()));+        altium_codec::import_kicad(&read(sym)?, &read(fp)?, &mpn).map_err(|e| e.to_string())?+    } else if hub.exists() {+        crate::load_part(&hub)+    } else {+        load_part(slug, &mpn)?.0+    };     let sym_svg = symbol_svg(&part.symbol);     let fp_svg = footprint_svg(&part.footprint, &pin_names(&part.symbol)); @@ -1685,3 +1728,21 @@ mod overbar_tests {         assert_eq!(overbar_svg("A<B"), "A&lt;B");     } }++#[cfg(test)]+mod export_viewers_local_tests {+    #[test]+    fn local_kicad_files_render_both_viewers_without_the_wiki() {+        let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/pin-semantics");+        let out = std::env::temp_dir().join(format!("lbr-viewers-local-{}", std::process::id()));+        let empty = out.join("empty");+        std::fs::create_dir_all(&empty).unwrap();+        // A slug that does not exist proves nothing is fetched: the local files win.+        super::export_viewers("adom/no-such-page-for-test", &empty, &out, false,+            Some((&root.join("repro4-outline.kicad_sym"), &root.join("repro4.kicad_mod")))).unwrap();+        let sym = std::fs::read_to_string(out.join("symbol.html")).unwrap();+        assert!(sym.contains("data-name='NC'") && sym.contains("data-name='A'"), "symbol pins rendered");+        assert!(out.join("footprint.html").exists());+        let _ = std::fs::remove_dir_all(&out);+    }+}