From c0feced7e564f3a651e851cb3f4241b37ed705e2 Mon Sep 17 00:00:00 2001 From: nshiab Date: Tue, 12 May 2026 15:11:25 -0400 Subject: [PATCH] Adding @observablehq/plot when relevant --- src/helpers/installPackagesAndFetchDocs.ts | 79 ++++++++++++++-------- test/installPackagesAndFetchDocs.test.ts | 8 +++ 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/helpers/installPackagesAndFetchDocs.ts b/src/helpers/installPackagesAndFetchDocs.ts index d6c7dda..909e054 100644 --- a/src/helpers/installPackagesAndFetchDocs.ts +++ b/src/helpers/installPackagesAndFetchDocs.ts @@ -22,58 +22,83 @@ export async function installPackagesAndFetchDocs( let lastDoc = ""; for (const pkg of selectedPackages) { const s = spinner(); - const installCmd = runtime === "deno" - ? `deno add jsr:${pkg}` - : runtime === "bun" - ? `bun add ${pkg}` - : `npm install ${pkg}`; - if (!options.silent) { - s.start(`Installing ${pkg} via ${runtime}...`); + const pkgsToInstall = [pkg]; + if ( + pkg === "@nshiab/simple-data-analysis" || + pkg === "@nshiab/journalism-dataviz" + ) { + pkgsToInstall.push("@observablehq/plot"); } - try { - await new Promise((resolve, reject) => { - commandRunner.exec(installCmd, (error) => { - if (error) { - reject(error); - } else { - resolve(void 0); - } - }); - }); + for (const p of pkgsToInstall) { + const isObservablePlot = p === "@observablehq/plot"; + const installCmd = runtime === "deno" + ? (isObservablePlot ? "deno add npm:" + p : "deno add jsr:" + p) + : runtime === "bun" + ? "bun add " + p + : "npm install " + p; + if (!options.silent) { - s.stop(`✅ ${pkg} installed!`); + s.start("Installing " + p + " via " + runtime + "..."); + } + + try { + await new Promise((resolve, reject) => { + commandRunner.exec(installCmd, (error) => { + if (error) { + reject(error); + } else { + resolve(void 0); + } + }); + }); + if (!options.silent) { + s.stop("✅ " + p + " installed!"); + } + } catch (error) { + if (!options.silent) { + s.stop("❌ Failed to install " + p + "."); + } + throw error; } + } - const sFetch = spinner(); + // Documentation logic + if (pkg === "@observablehq/plot") { + continue; + } + + const sFetch = spinner(); + try { if (!options.silent) { - sFetch.start(`Fetching documentation for ${pkg}...`); + sFetch.start("Fetching documentation for " + pkg + "..."); } const repoName = pkg.split("/")[1]; - const url = - `https://raw.githubusercontent.com/nshiab/${repoName}/refs/heads/main/llm.md`; + const url = "https://raw.githubusercontent.com/nshiab/" + repoName + + "/refs/heads/main/llm.md"; const response = await fetch(url); if (response.ok) { const docContent = await response.text(); - writeFileSync(join("docs", `${repoName}.md`), docContent); + writeFileSync(join("docs", repoName + ".md"), docContent); if (!options.silent) { - sFetch.stop(`✅ Documentation for ${pkg} saved!`); + sFetch.stop("✅ Documentation for " + pkg + " saved!"); } lastDoc = docContent; } else { if (!options.silent) { sFetch.stop( - `⚠️ No documentation (llm.md) found for ${pkg}. Skipping doc fetch.`, + "⚠️ No documentation (llm.md) found for " + pkg + + ". Skipping doc fetch.", ); } } } catch (error) { if (!options.silent) { - s.stop(`❌ Failed to install ${pkg}.`); + sFetch.stop("❌ Failed to fetch documentation for " + pkg + "."); } - throw error; + console.error(error); } } return lastDoc; diff --git a/test/installPackagesAndFetchDocs.test.ts b/test/installPackagesAndFetchDocs.test.ts index d2bf16e..3810ea6 100644 --- a/test/installPackagesAndFetchDocs.test.ts +++ b/test/installPackagesAndFetchDocs.test.ts @@ -54,6 +54,10 @@ Deno.test("installPackagesAndFetchDocs - should try to install packages and fetc execStub.calls[0].args[0], "deno add jsr:@nshiab/simple-data-analysis", ); + assertEquals( + execStub.calls[1].args[0], + "deno add npm:@observablehq/plot", + ); } finally { execStub.restore(); globalThis.fetch = originalFetch; @@ -95,6 +99,10 @@ Deno.test("installPackagesAndFetchDocs - should use npm install for node runtime execStub.calls[0].args[0], "npm install @nshiab/simple-data-analysis", ); + assertEquals( + execStub.calls[1].args[0], + "npm install @observablehq/plot", + ); } finally { runtimeStub.restore(); execStub.restore();