Files
obsidian_ollama/install.sh
T
fegger 97cc4ed5fe fix: bundle chromadb and fix fetch invocation in Electron
- Bundle chromadb into main.js via esbuild instead of externalizing it.
  Obsidian's renderer cannot resolve bare require('chromadb') against a
  plugin-local node_modules. By bundling, the client library is inlined and
  works out of the box with just manifest.json + main.js.

- Remove eager cache initialization from OllamaClient constructor to avoid
  unhandled promise rejections when chromadb/ChromaDB is unavailable.

- Fix 'Failed to execute fetch on Window: Illegal invocation' by wrapping
  the default fetch fallback in an arrow function:
    this.fetchFn = fetchFn ?? ((url, init) => fetch(url, init));
  This preserves the window binding when fetch is called later.

- Update install.sh and README to remove the obsolete node_modules/chromadb
  copy step.

- Update ollama-client-cache tests to reflect that cache initialization is
  no longer eager.
2026-05-19 20:38:50 +02:00

130 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# install.sh — Install the Ollama Plugin into an Obsidian vault
#
# Usage:
# ./install.sh /path/to/your/vault
#
# The script will:
# 1. Install npm dependencies (excluding Ollama itself — you need that separately)
# 2. Compile the TypeScript plugin
# 3. Copy the built plugin into <vault>/.obsidian/plugins/ollama-plugin/
#
# Prerequisites:
# - Node.js and npm
# - Ollama installed and running (https://ollama.ai)
#
set -euo pipefail
# ── Helpers ──────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
info() { printf "${GREEN}${NC} %s\n" "$1"; }
warn() { printf "${YELLOW}${NC} %s\n" "$1"; }
error() { printf "${RED}${NC} %s\n" "$1"; }
step() { printf "\n${BOLD}══ %s ══${NC}\n" "$1"; }
# ── Argument validation ──────────────────────────────────────────────────────
VAULT_PATH="${1:-}"
if [ -z "$VAULT_PATH" ]; then
echo "Usage: ./install.sh /path/to/your/vault"
echo ""
echo " Provide the path to your Obsidian vault directory."
echo " The plugin will be installed into <vault>/.obsidian/plugins/ollama-plugin/"
exit 1
fi
if [ ! -d "$VAULT_PATH" ]; then
error "Vault directory does not exist: $VAULT_PATH"
exit 1
fi
if [ ! -d "$VAULT_PATH/.obsidian" ]; then
warn "No .obsidian folder found in $VAULT_PATH — this may not be a valid Obsidian vault."
warn "Continuing anyway, but the plugin may not load."
fi
PLUGIN_DIR="$VAULT_PATH/.obsidian/plugins/ollama-plugin"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# ── Check prerequisites ──────────────────────────────────────────────────────
step "Checking prerequisites"
if ! command -v node &> /dev/null; then
error "Node.js is required but not found. Install it from https://nodejs.org"
exit 1
fi
info "Node.js $(node --version)"
if ! command -v npm &> /dev/null; then
error "npm is required but not found."
exit 1
fi
info "npm $(npm --version)"
# ── Install dependencies ─────────────────────────────────────────────────────
step "Installing npm dependencies"
cd "$SCRIPT_DIR"
npm install
info "Dependencies installed"
# ── Build ────────────────────────────────────────────────────────────────────
step "Building the plugin"
npm run build
info "Build complete"
# ── Install into vault ───────────────────────────────────────────────────────
step "Installing into vault"
mkdir -p "$PLUGIN_DIR"
# Remove old dist/ directory from previous installations (no longer needed with bundling)
rm -rf "$PLUGIN_DIR/dist"
# Copy manifest and bundled entry point
cp "$SCRIPT_DIR/manifest.json" "$PLUGIN_DIR/"
cp "$SCRIPT_DIR/main.js" "$PLUGIN_DIR/"
# All dependencies are now bundled into main.js; no runtime node_modules needed.
info "Plugin installed to $PLUGIN_DIR"
# ── Verify ────────────────────────────────────────────────────────────────────
step "Verifying installation"
if [ -f "$PLUGIN_DIR/manifest.json" ] && [ -f "$PLUGIN_DIR/main.js" ]; then
info "manifest.json ✓"
info "main.js ✓"
else
error "Installation verification failed — missing files in $PLUGIN_DIR"
exit 1
fi
echo ""
echo " ${GREEN}${BOLD}Done!${NC} The plugin has been installed."
echo ""
echo " Next steps:"
echo " 1. Restart Obsidian (or reload plugins: Ctrl+Shift+P → 'Reload app without saving')"
echo " 2. Go to Settings → Community plugins → enable 'Ollama Plugin'"
echo " 3. Configure the plugin: Settings → Ollama Settings"
echo ""
echo " Make sure Ollama is running:"
echo " ollama serve"
echo " ollama pull llama3 (or your preferred model)"
echo ""