Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import type { StorageBackend } from "@typbase/storage";import type { PluginManifest } from "@typbase/typing";
import { pluginManifestText, type PluginBundleFile } from "@typbase/plugin-sdk";
import { pluginSlug } from "./manifest";
const encoder = new TextEncoder();
async function removeTree(backend: StorageBackend, path: string): Promise<void> { let entries: string[] = []; try { entries = await backend.list(path); } catch { return; }
for (const name of entries) { const child = `${path}/${name}`; const stat = await backend.stat(child).catch(() => null); if (stat?.kind === "directory") { await removeTree(backend, child); continue; }
// Some backends expose only files, so a nested folder shows up as its // first path segment with no directory stat. Ask for its children instead // of deleting a path that is really a parent. const nested = await backend.list(child).catch(() => []); if (nested.length) await removeTree(backend, child); else await backend.delete(child); }}
/** * Replaces the local source folder for one plugin. The bundle parser has * already checked paths. This only makes the folder match the release. */export async function installPluginBundle( backend: StorageBackend, manifest: PluginManifest, files: PluginBundleFile[],): Promise<string> { const root = `plugins/${pluginSlug(manifest.id)}`; await removeTree(backend, root); await backend.write(`${root}/plugin.json`, encoder.encode(pluginManifestText(manifest))); for (const file of files) { await backend.write(`${root}/${file.path}`, encoder.encode(file.text)); }
return root;}